×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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

Jobs

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

(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:

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) 
Draftsight start but without opening the test.dwg


Thanks for the help..



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

Hi,

You created the Draftsight application object, dsApp.

Then you TOTALLY disregard that object!

CODE

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

Skip,

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

(OP)

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

(OP)
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


Resources

White Paper – Choosing the Right Spring Loaded Connector
In today’s cost-sensitive world, designers are often driven to specify the lowest cost solution for every aspect of their designs to ensure that their solution is competitively priced and their company remains profitable. However, specifying a low-cost, low-quality connector solution can result in premature failure, considerable re-work costs and damage to reputations. Download Now
eBook – Own the Lifecycle: Sustainable Business Transformation
Increasingly, product and services companies are seeking more information and control in the operational lifecycle of their products, including service and use. Better information about the operational lifecycle, and the ability to use that information, requires more than just unstructured data flowing back from products in the field. 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