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.
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 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