Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Open Dwg and run a script - Excel to Draftsight

Open Dwg and run a script - Excel to Draftsight

Open Dwg and run a script - Excel to Draftsight


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
        Set dsApp = CreateObject("DraftSight.Application")
        If (Err <> 0) Then
            MsgBox "Could Not Load DraftSight!", vbExclamation
        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
        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 If
    'Close Draftsight Process
    Set dsApp = Nothing
    Set NewFile = Nothing

End Sub 

Return me a error: method or data member not found to

CODE --> Vba


If I comment the line

CODE --> Vba

Set NewFile = Draftsight.Documents.Open(MydsAppPath, bReadOnly) 
Draftsight start but without opening the test.dwg

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!


Set NewFile = Draftsight dsApp.Documents.Open(MydsAppPath, bReadOnly) 


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Open Dwg and run a script - Excel to Draftsight

Dude... I already told you (on a different forum) that you can't do this without DraftSight Professional. Yes, you can run scr files inside of DraftSight using the free version, but you can't use API calls from VBA to open files and run commands.

RE: Open Dwg and run a script - Excel to Draftsight


Quote (SkipVought)

You created the Draftsight application object, dsApp.

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"

Quote (handleman)

but you can't use API calls from VBA to open files and run commands

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

The only thing you're going to be able to do with this method is open DraftSight. You will not be able to open the file or execute the .scr through VBA.

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

Thanks for the suggestion bigsmile Now I'm using the professional ( in trail mode) and even in this case Draftsight starting without opening the specific file...I don't know where's my mistake..

RE: Open Dwg and run a script - Excel to Draftsight

You will have to "speak" Draftsight's "Language". Every program that you automate with VBA has certain functions and calls that are specific to that program.

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

You are using late binding, so IDE will not help enumerate methods and members. You may be able to use object explorer to find methods and members exposed from your created object.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


eBook - Rethink Your PLM
A lot has changed since the 90s. You don't surf the Web using dial-up anymore, so why are you still using a legacy PLM solution that's blocking your ability to innovate? To develop and launch products today, you need a flexible, cloud-based PLM, not a solution that's stuck in the past. Download Now
White Paper - Using Virtualization for IVI and AUTOSAR Consolidation on an ECU
Current approaches used to tackle the complexities of a vehicle’s electrical and electronics (E/E) architecture are both cost prohibitive and lacking in performance. Utilizing virtualization in automotive software architecture provides a better approach. This can be achieved by encapsulating different heterogeneous automotive platforms inside virtual machines running on the same hardware. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close