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

Open dwg through AutoCAD 2009

1 REPLY 1
Reply
Message 1 of 2
Anonymous
230 Views, 1 Reply

Open dwg through AutoCAD 2009

Can someone please post the code of how to open a dwg and send a command to it from stand alone vb.net 2008. Basically I want to do what script pro used to do but I want it do it from a list of dwg path gathered from a SQL query. I know how to get the paths into an array and loop through them, I just need to be able to open the drawings and SendCommand a scr file to them and then track the time it takes to complete the process.

Thanks in advance...
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Below is code I have that you should be able to remove the unnecessary parts and modify the rest to suit.

Sub Main()
Dim objApp As Object
Dim objAcad As AcadApplication
Dim objAcadDoc As AcadDocument
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objSSet As AcadSelectionSet
Dim shtFType(0) As Short
Dim objFData(0) As Object
Dim objBlockRef As AcadBlockReference
Dim objAttribRefs() As Object
Dim objAttribRef As AcadAttributeReference
Dim intCount As Integer
objApp = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application")
objAcad = CType(objApp, AcadApplication)
objAcad.ActiveDocument.SetVariable("FILEDIA", 0)
objFSO = New Scripting.FileSystemObject
objFolder = objFSO.GetFolder("Z:\Products\AAAT\Experience Guide\Towns")
For Each objFile In objFolder.Files
If objFile.Name Like "*.dwt" = True Then
objAcadDoc = objAcad.Documents.Add(objFile.Path)
Do Until objAcad.GetAcadState.IsQuiescent = True
Loop
objAcadDoc.SendCommand("script " & Left(objFile.Path, Len(objFile.Path) - 4) & ".scr" & vbCr)
Do Until objAcad.GetAcadState.IsQuiescent = True
Loop
objSSet = objAcadDoc.SelectionSets.Add("SSET")
shtFType(0) = 8
objFData(0) = "*HOTEL,*ACCOM-LISTED,*ACCOM-DELISTED,*ACCOM-UNLISTED,TRIM-LINE,T??R-CITY*"
objSSet.Select(AcSelect.acSelectionSetAll, , , shtFType, objFData)
objSSet.Erase()
shtFType(0) = 2
objFData(0) = "COPYRIT"
objSSet.Select(AcSelect.acSelectionSetAll, , , shtFType, objFData)
For Each objBlockRef In objSSet
objAttribRefs = CType(objBlockRef.GetAttributes, [Object]())
For intCount = 0 To UBound(objAttribRefs)
objAttribRef = CType(objAttribRefs(intCount), AcadAttributeReference)
If objAttribRef.TagString = "DATE" Then objAttribRef.TextString = "0107"
Next intCount
Next objBlockRef
objSSet.Delete()
objAcadDoc.SaveAs(Left(objFile.Path, Len(objFile.Path) - 4) & ".dwg", AcSaveAsType.acNative)
objAcadDoc.Close()
End If
Next objFile
objAcad.ActiveDocument.SetVariable("FILEDIA", 1)
End Sub

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