Lesson 7.5 – Macro Features

You need to be logged in to view this content. Please login or become a member.

<<  Prev   |   Index   |   Next  >>

Description

This is the only tutorial available that you will walk you through the creation of a macro feature for creating or modifying a body. You will also learn how to control the input body and extrude length with a PropertyManager page. A temporary body preview will be added as well. Finally, you will see the final iteration of the Spike Creator macro that we have been working on in the previous two lessons.

Watch a demo video of the spike creator and more at this blog post.

Notes

Macro features can be used for more than just creating or modifying bodies. For example, sometimes they are used simply to update custom properties after each rebuild. In this case, the macro feature options (the last argument in IFeatureManager::InsertMacroFeature3) will include the optino to keep the macro feature at the end of the feature tree, and the security options will be set so that the macro feature cannot be suppressed to deleted. Then the code that always updates the custom properties is contained in the rebuild function, so each time the model updates, the custom properties update. Notifications can also be used to accomplish this kind of thing, however, and can generally be implemented more easily since your users merely need to update their SolidWorks’ shortcuts so that SolidWorks opens with the notification macro running. In either case, however, the administrator can make modifications to the target macro if changes need to be made. This is because every time the macro feature rebuilds it looks to the code in the target macro file.

If you have an object that was always being set successfully but all of sudden starts giving you trouble, do NOT try to do a lot of surgery on your code to try to fix the problem right then. Macro features are fairly finicky, and sometimes during your coding you simply need to save everything, close down the VB Editor to clear out all variables, and then re-open the macro.

Normally you can use IMacroFeatureData::EditBodies to get the body that needs modifying. However if you need the component transform then use IMacroFeatureData::GetSelections3. See also the API Help article entitled “Macro Features and Component Transforms”.

Lesson Files

Lesson 7.5 code – Part A
Lesson 7.5 code – Part B
Lesson 7.5 code – Part C
Lesson 7.5 code – Part D
Lesson 7.5 code – Part E
Lesson 7.5 code – Part F
Lesson 7.5 code – Part G
Lesson 7.5 code – Part H
Lesson 7.5 code – Part I (spike creator)
Lesson 7.5 – Update custom properties with macro feature
Code snippets

2 Comments

  1. eranderson

    Keith,
    What is the best way to access the body selected in the PMP for the macro feature? If for example one wanted to use the position of the selected body to place the spike instead of it being placed at the origin, or use the size of the box to determine the size of the spike? Also, do the operations within the macro have to be part of Imodeler or can they be standard features like linearpattern4? would they need to be created as subfeatures?

    • 1. If the selected objects are listed in a selection box on the PMP, then you would use IPropertyManagerPageSelectionbox.GetSelectedItems to get the pointers of those objects.

      2. You cannot create “regular” SolidWorks features in the rebuild function of a macro feature because this would result in a rebuild within a rebuild, which would cause SolidWorks to crash or at least experience problems. You will need to use IModeler to create geometry.

Questions and Comments

You must be logged in to post a comment.