×
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

Call SolidWorks Macro from Visual Basic 6.0
2

Call SolidWorks Macro from Visual Basic 6.0

Call SolidWorks Macro from Visual Basic 6.0

(OP)
Is it possible to call a SolidWorks Macro from a Visual Basic 6.0 program?

Bradley
SolidWorks Pro 2008 x64 SP3.0EV
PDMWorks Workgroup, Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 12577 MB, nVidia 3400
e-mail is Lotus Notes

RE: Call SolidWorks Macro from Visual Basic 6.0

Yes.

CODE

retval = SldWorks.RunMacro ( filePathName, moduleName, procedureName )

Running macros from this command can get flaky, especially if macro has forms, multiple modules, or programmer does a poor job of closing objects.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Call SolidWorks Macro from Visual Basic 6.0

(OP)
Thanks TheTick,
I am working on it.
A star for you.

Bradley
SolidWorks Pro 2008 x64 SP3.0EV
PDMWorks Workgroup, Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 12577 MB, nVidia 3400
e-mail is Lotus Notes

RE: Call SolidWorks Macro from Visual Basic 6.0

(OP)
Matt,
Yes, I got Eric’s macro (PropertySync.swp) to run the way I like it. I tried to convert the macro, following TheTick’s directions on his web page, I could not get it to run. It is not a simple macro, it has several modules.
Here is a link to the macro that Eric wrote a while back for this purpose. Really well done.
http://home.comcast.net/~ewetemp/SolidWorks/PropertySync.swp

Bradley
SolidWorks Pro 2008 x64 SP3.0EV
PDMWorks Workgroup, Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 12577 MB, nVidia 3400
e-mail is Lotus Notes

RE: Call SolidWorks Macro from Visual Basic 6.0

Trying to convert to an addin?

RE: Call SolidWorks Macro from Visual Basic 6.0

(OP)
MyAppID = Shell("C:\DST_SolidWorks\Executables\RevBoxECIN.exe", 1)

This is the last line before exiting PropertySync.swp macro. What I have done is remove the operators touch from PropertySync.swp. The operator never sees the dialog box. The macro copies number and description from the part, (even if the part is not open) and copies number and description properties data into the drawing. Now the drawing always matches the part.

Bradley
SolidWorks Pro 2008 x64 SP3.0EV
PDMWorks Workgroup, Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 12577 MB, nVidia 3400
e-mail is Lotus Notes

RE: Call SolidWorks Macro from Visual Basic 6.0

Rather than triggering the macro from the exe, I would include the relevant code from the macro in the exe.  This will be aided by the fact that I worked to keep the user interface separate from the data model.  It will be hampered by the fact that I included no comments about what was happening where in the code.

You should be able to export the DrawingModel class module out of the macro and into your application.  Then you will need to get two instances of DrawingModel, one for the drawing and one for the model (part / assembly).  Then you can get the properties from the model one and set them in the drawing one.

Assuming that drawing is a SldWorks.DrawingDoc for the current drawing the following code will get the property model for the drawing.

CODE

Set drawingPropertyModel = New DrawingModel
drawingPropertyModel.setTo drawing, "", drawingPropertyModel

Getting the property model for the part / assembly is similar, but more complex.  The complexity comes from two sources: a drawing can have multiple views which reference different models, and the desired properties can be associated with either a model file or an individual configuration.  Assuming that you want to use the file properties from the current view of the current sheet of the drawing you would use the following code to get the DrawingModel object for the model.

CODE

Dim currentView As SldWorks.view
Set currentView = drawing.GetFirstView()
Set currentView = currentView.GetNextView

Set modelPropertyModel = New DrawingModel
modelPropertyModel.setTo currentView.ReferencedDocument, "", modelPropertyModel
            
If you want the configuration properties the last line would become:

CODE

modelPropertyModel.setTo currentView.ReferencedDocument, currentView.ReferencedConfiguration, modelPropertyModel

Then it is a simple matter of:

CODE

Dim number As String
Dim description As String

modelPropertyModel.getModelProperties(number, description, False)
drawingPropertyModel.setModelProperties(number, description, False)

I hope this is enough information so that you can work out the integration.

Eric

RE: Call SolidWorks Macro from Visual Basic 6.0

(OP)
Thanks you very much Eric,
Your original code is working for me now. However this new information will help in my old code to make it easier for someone else to take over after I leave.
Thank you. A star for you.

Bradley
SolidWorks Pro 2008 x64 SP3.0EV
PDMWorks Workgroup, Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 12577 MB, nVidia 3400
e-mail is Lotus Notes

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!


Resources