Open Dwg and run a script - Excel to Draftsight
Open Dwg and run a script - Excel to Draftsight
(OP)
Hi,
I need to open a dwg file, run a script (.scr) and close Draftsight. I'm started with open the document.I found this code from jrice174 and I've tried to edit for Draftsight:
Return me a error: method or data member not found to
If I comment the line Draftsight start but without opening the test.dwg
Thanks for the help..
I need to open a dwg file, run a script (.scr) and close Draftsight. I'm started with open the document.I found this code from jrice174 and I've tried to edit for Draftsight:
CODE --> Vba
Sub openDraftsight() Dim dsApp As Object Dim NewFile As Object Dim dsAppPath As String Dim bReadOnly As Boolean On Error Resume Next Set dsApp = GetObject(, "DraftSight.Application") If (Err <> 0) Then Err.Clear Set dsApp = CreateObject("DraftSight.Application") If (Err <> 0) Then MsgBox "Could Not Load DraftSight!", vbExclamation End End If End If 'If you want to see AutoCAD on screen dsApp.Visible = True MydsAppPath = "C:\test.dwg" bReadOnly = True 'Set NewFile = Draftsight.Documents.Open(MydsAppPath, bReadOnly) If (NewFile Is Nothing) Then ErrorMessage: If NewFile = "False" Then End MsgBox "Could not find the required spreadsheet that should be located at" & vbCr & MydsAppPath & vbCr & "Please rename or relocate the specified file as needed." End End If 'Close Draftsight Process 'dsApp.Quit Set dsApp = Nothing Set NewFile = Nothing End Sub
Return me a error: method or data member not found to
CODE --> Vba
Documents
If I comment the line
CODE --> Vba
Set NewFile = Draftsight.Documents.Open(MydsAppPath, bReadOnly)
Thanks for the help..
RE: Open Dwg and run a script - Excel to Draftsight
You created the Draftsight application object, dsApp.
Then you TOTALLY disregard that object!
CODE
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: Open Dwg and run a script - Excel to Draftsight
RE: Open Dwg and run a script - Excel to Draftsight
Thanks for the help, I'm not an expert of Vba! I changed as you suggested. Now Draftsight run without error but without opening the file "test.dwg"
I hope there is a secondary option! Meanwhile it's fine for me to open the file...
RE: Open Dwg and run a script - Excel to Draftsight
Another approach that will get you one step further would be to tell Windows to open the .dwg file using DraftSight. This would be accomplished with a shell command:
Shell """[whatever the path is to the DraftSight .exe]"" ""[whatever the path is to your .dwg]""", 1
You will still have to manually run the .scr file inside DraftSight, and manually save and close etc.
RE: Open Dwg and run a script - Excel to Draftsight
RE: Open Dwg and run a script - Excel to Draftsight
You have the line:
Set NewFile = Draftsight.Documents.Open(MydsAppPath, bReadOnly)
However, this is the syntax for either AutoCAD or Excel, which you've copied this macro from.
When you tell ACAD/XL (whichever it was) ".Documents.Open....", that's its language. It knows what to do with that.
I don't know what DraftSight's API calls are for opening a document. You need to look at DraftSight API documentation for that.
RE: Open Dwg and run a script - Excel to Draftsight