Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call SolidWorks Macro from Visual Basic 6.0 2

Status
Not open for further replies.

Standing

Mechanical
Jan 14, 2002
1,578
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
 
Replies continue below

Recommended for you

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.

[bat]Honesty may be the best policy, but insanity is a better defense.[bat]
-SolidWorks API VB programming help
 
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
 
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.


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
 
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
 
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 [tt]drawing[/tt] is a [tt]SldWorks.DrawingDoc[/tt] 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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor