.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script pro to batch dwg to dxf

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
1760 Views, 2 Replies

Script pro to batch dwg to dxf

Hello
im setting scriptpro to batch export dxf files.
But im am having trouble with the code
this i how far i got
(initdia 0)(command "._dxfout" "c:\\filename.dxf")

What i really want i for the dwg file to change til dxf with the same name, but in a new folder.
Ex.
Z:\files\new\test.dwg
Z:\files\new\test1dwg
Z:\files\alfa.dwg
to
C:\folder\text.dxf
C:\folder\text1.dxf
C:\folder\alfa.dxf Edited by: jensv on Feb 12, 2010 12:06 PM
2 REPLIES 2
Message 2 of 3
arcticad
in reply to: Anonymous

jensv:

I'm not familiar with scriptpro however,
Here is some .net code to do what you ask.

{code}

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime

Public Class dxfout

Sub dxfOut()
Dim targetDirectory As String = "c:\myFiles\"
Dim OutputDirectory As String = "c:\myFiles\output\"

Dim fileEntries As String() = System.IO.Directory.GetFiles(targetDirectory)

If fileEntries.Count > 0 Then
If (Not System.IO.Directory.Exists(OutputDirectory)) Then
System.IO.Directory.CreateDirectory(OutputDirectory)
End If
For Each fileName In fileEntries
If Not isFileInUse(fileName) Then
If fileName.Substring(fileName.Length - 3).ToUpper = "DWG" Then
Using db As New Autodesk.AutoCAD.DatabaseServices.Database(False, True)
Using tr As Transaction = db.TransactionManager.StartTransaction()
If getDatabase(fileName, db) Then
Dim outNewDXF As String = OutputDirectory & System.IO.Path.GetFileNameWithoutExtension(fileName) & ".dxf"
Try
db.DxfOut(outNewDXF, 8, True)
Catch ex As System.Exception
MsgBox("error writing: " * outNewDXF)
End Try
End If
db.CloseInput(True)
End Using
End Using
End If
End If
Next
End If

End Sub

Function getDatabase(ByVal FileName As String, ByRef db As Autodesk.AutoCAD.DatabaseServices.Database) As Boolean
Try
' Read File
db.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")
Return True
Catch ex As System.Exception
Return False
End Try
End Function

Public Function isFileInUse(ByVal sFile As String) As Boolean
If System.IO.File.Exists(sFile) Then
Try
Dim F As Short = FreeFile()
FileOpen(F, sFile, Microsoft.VisualBasic.OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(F)
Catch
Return True
End Try
End If
End Function

End Class

{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 3
mfernandes
in reply to: arcticad

Hey arcticad

I am comming late into this thread, and although I have programmed in LISP and VBA I am completely new in dot net.

 

So if I understand your code.

It reads all the drawing files in the dir, opens eachfile and outputs a dxf file.....correct??

 

I want to do something similar, but I want to open DGN drawings and save as dwg,

so would I open a New drawing, import the DGN and save the DWG ?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost