Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Attaching .vbproj macro to design binder

Status
Not open for further replies.

mihalj

Mechanical
Apr 15, 2009
40
0
0
US
Hi,
did anyone succeeded attaching macro created with Visual Basic net to design binder and run it from equation? If it was done can you please share what was exactly line added inside equation line (I am guessing it should be line added inside global variable)?
I tried something with macro name and added after class name as well as sub name (in my case it was "Var1"=1::swApp.RunAttachedMacro "name.vbproj", "SolidWorksMacro", "main()").
As a matter of fact whenever I put this line inside equations, I do not get error, and after I close equation and open it again, equation is gone (it was not saved).
Thanks in advance for help.
 
Replies continue below

Recommended for you

Hi,
I did check their site (actually they triggered my interest to see how I can do that thru VB .Net as I am not quite familiar with VBA), but I do have difficulties to do the same under VB.Net. Also I did download some presentation done in 2011, and examples in it, but when I did it open in Solidworks 2014 there was no any attachments with a part (design binder). Wonder was it omitted due to changes between 2011 and 2014 version?
Anyway thanks for the help, however I need someone experienced with macros done in VB.Net environment.
 
I am pretty familiar with the 2011 presentation, if its the one I am thinking of. It doesn't use .NET, and it doesn't use the RunAttachedMacro method. It actually embeds the VBA code into custom properties.

I didn't notice before that you specified .NET. I'm about 99% sure that RunAttachedMacro only works with VBA macros. To run .NET macros in Solidworks, you have to run the compiled .dll unless you're running it from the IDE.

All that said, the user interface for SW2014 will not allow you to enter this kind of equation. It has a very strict syntax checker that rejects many equations that actually work just fine. To enter this type of equation. you need to use API to directly enter the equation, bypassing the user interface.

Luke Malpass has written a useful macro that can inject these equations. See
-handleman, CSWP (The new, easy test)
 
First of all thanks for the help. I think you nailed it with an idea to go thru direct API control of equation and try to run it thru code rather than standard equation editor (though might be more useful in this case to use MacroFeature within feature tree). There is specified function RunAttachedMacro inside SW VB Net (now does it work or not, that is another question). I am going to try to do something over weekend and let you know (of course if you are interested about results).
 
Hi,
at the moment I am stuck with very weird issue (unless I don't get this at all) in regards to passing dimension out of sketch:
Dim swPart as IPartDoc
Dim featureOfPart as IFeature = Nothing
Dim sketchWidth As IDimension = Nothing
Dim dblSketchWidth as Double = Nothing

swPart = swApp.ActiveDoc
featureOfPart = swPart.FeatureByName("Something")
sketchWidth = featureOfPart.IParameter("Width@SomethingSketch@SomethingPart.sldprt")

dblSketchWidth = sketchWidth.IGetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, 1, Nothing)
MsgBox (dblSketchWidth)

Getting an error: "Use the "new" keyword to create object instance.".
Tried other functions (dimension.value, IGetValue3) which returns double value from dimension but with same issue and message.
Does anyone gets this error? How to approach to physical value of sketch dimension? The goal is to get a value from sketch and compare it with another value, possibly set new value and then I can go to real beauty of this job to somehow create macro feature and embed it into the part.
Please can someone help only with getting double or string value from dimension?
Thanks.
 
Status
Not open for further replies.
Back
Top