You need to be logged in to view this content. Please login or become a member.
Description
This presentation was given at SolidWorks World 2012 in a hands-on session called “Taking Macros to the People: Hands-On For Beginners”. The advertised description: “Forget abstract talks about object-oriented programming. This hands-on class will get the total beginner on track to unleash the SolidWorks API for greater productivity, using quick and dirty tactics involving the macro recorder, API help, and free cheat sheets.”
Notes
Common VBA variable data types used with the SolidWorks API:
Files
Notes (handout)
Create extruded base with user form
I’m working thru this video and immediately after recording my macro…
I get this when I try to run it:
“Run Time Error ’91’:” and “Object variable or With block variable not set”
I’m at 5:54 into the video (for reference).
I have tried debugging this, but I obviously don’t know enough VBA yet.
I’m running:
Windows 7
SolidWorks 2012 SP4.0
Microsoft VBA 7.1
Please and Thank You…
Hi,
This error usually occurs when you try to use a function on an object that is Nothing or when you forget to use the Set keyword when setting an object variable’s reference. Of course, in your case, you are using the macro recorder so it is the macro recorder that messed up, not you.
Since this is a very common error, I address it at the end of this blog post: Debugging Tips for VBA Programmers
Keith
Hi,
Is that possible to make a link between file property of a solidworks document(where we enter the description, part number and other detail related to part or assembly or drawing) with the excel file.
basically, we have a register (excel) from where we raised the part number for the part. what i am trying to do is, if i fill the part detail in solidworks file property then it automatic write the description in register. so we dont need to type same detail in register.
can you please guide me to do this. if you not understand what i am trying to expain please let me know.
thanks
singh
Hi Singh,
I have a blog post on how to connect the SolidWorks and Excel APIs that will allow you to do this. Please see that here. The interface you need to work with SolidWorks custom properties is ICustomPropertyManager. There are lots of examples in the API Help.
Hi,
i’d like to make some Macrobuttons to open SW-Assemblies juste by one click, the same way then => File =>Open => (usually browse the Filepath ) => OK (Open).
Which is the code that i use ? Is there an example ?
thanks
tg
You could record a macro that does this. Did you watch the video? This is a very basic macro so it would be a good challenge for a beginner like yourself.
Hi Keith,
thanks for your answer.
Sorry, I havent watched the video 3.1 when I posted the question. I did it today, there i got the answer.
have a nice day!
tg
Even if I declared…
Dim swApp as SldWorks.sldworks
when I type swApp. the drop-down list with the members of the object does not appear. Does anybody knows why.? It’s a option somewhere in the IDE?
If you go to Tools–>References, is the SolidWorks 20XX type library checked?
Yes, it was checked. Actually two, 2005 and 2008 is checked.
But now is functioning… Thank you and I’m sorry I bothered you.