×
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

Macro Features

Macro Features

Macro Features

(OP)
Hi,

I need to find a way to suppress a feature (without using a design table) based on the value of an equation.  Seems like an inline macro feature is the only way to do this?

Documentation and examples of macrofeatures seem sparse?  I'm not positive how to pass the equation value into the macros if statement.  And I'm not sure how the macro feature actually ends up in the feature tree?

TIA

Zander

RE: Macro Features

Use IEquationMgr Interface to retrieve and parse the equations.

The macro feature is the separete SolidWorks feature that reacts on several events such as rebuild and edit definition.

You can put the code for reading the equation and the suppressing the feature in the Regen function.

Please let me know if you need more assistance.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Macro Features

(OP)
Hi Artem,

Thanks for the info.  I'm curious, how does the macro feature actually get inserted into the feature tree?  Does it happen the first time you run it?

Thanks,

RE: Macro Features

It inserts with the FeatureManager::InsertMacroFeature3 method and became a regular feature in the Feature manager Design Tree. You can assign different icons and functionality to it.

If you are using VBA macro feature you can embed it directly to model file so the link to initial macro file brokes.

Please refer the attached sample macro which creates a macro feature.

Please do not hesitate to contact me if you have any questions.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Macro Features

(OP)
Cool!

I've got it working in theory - but in the rebuild section I need to figure out how to pass the equation value into a macro variable.

Thanks,

RE: Macro Features

(OP)
Ok,  I found the .getequationmgr function so I will work that out, then I just need to work out how to suppress a feature by name.  

Thanks again.

RE: Macro Features

(OP)
Hi,

I've got everything working except for the actual suppresion.  Does the macrofeature need to occur before the feature to be suppressed in the tree?

It seems like the last line of the if statement block:

bRet = swModel.EditSuppress2

Doesnt' error but doesn't suppress the selected feature.

Here is the block:

equation3 = swEqnMgr.Value(3)
    If equation3 < 61 Then
        Set swEditPart = swEditModel
        Set swFeat = swPart.FeatureByName("MD1-left")
        bRet = swFeat.Select2(False, 1)
        bRet = swModel.EditSuppress2
    End If

Any ideas?


 

RE: Macro Features

Use the Feature::SetSuppression2 method instead of ModelDOc2::EditSuppress2:

...
swFeat.SetSuppression2(swFeatureSuppressionAction_e.swSuppressFeature, swInConfigurationOpts_e.swAllConfiguration, Empty)
...

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Macro Features

(OP)
Artem,  you've been incredibly helpful - thanks!

Everything is working, both suppress and unsupress depending on equation value.  I dragged the macrofeature to before the feature being suppressed, but I don't know if I should have.  

Also, when I changed the model and rebuild, the vba editor is invoked and the rebuild function is in 'step' mode.  I don't know why though?

 

RE: Macro Features

(OP)
Ok,  I've fixed the 'stepinto' problem.

Now I have one last question:  If I want to alter the code of my macrofeature is this possible by using editdefinition?  The canned stuff in the sample macro just creates a msgbox saying 'edit definition',  but it would be cool if it could invoke the vba editor.

Thanks,

RE: Macro Features

Actually the "Edit Definition" is just an event where you can place some code. It is similar to "Regen" notify but fires in another situation.

If you would like to change the code of the macro feature. You shouldn't embed it to the model file so the link to .swb-file remains. If so you can open this macro in VBA-editor and alter the code.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Macro Features

(OP)
Hi,

Thanks - I didn't embed my macro (don't actually know how, although I read it can be done).  Instead, I edit the source, delete the old feature and rerun.

What would trigger the edit definition section?

Zander

RE: Macro Features

(OP)
I see, so it's a way of running some code whenever you decide as opposed to the regen section which will execute on every rebuild.  Thanks!

RE: Macro Features

Correct. Actually in Add-in programming mostly the PMPage shows within the "Edit Feature" call.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

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