×
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

Attaching .vbproj macro to design binder

Attaching .vbproj macro to design binder

Attaching .vbproj macro to design binder

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

RE: Attaching .vbproj macro to design binder

Keith Rice (http://www.cadsharp.com/about/) has done considerable research into this.

-handleman, CSWP (The new, easy test)

RE: Attaching .vbproj macro to design binder

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

RE: Attaching .vbproj macro to design binder

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 https://solidworks.jiveon.com/thread/64905

-handleman, CSWP (The new, easy test)

RE: Attaching .vbproj macro to design binder

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

RE: Attaching .vbproj macro to design binder

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

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