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

<<  Prev   |   Index   |   Next  >>


Ever wanted to create macros with SolidWorks-native user interfaces? This lesson will show you how to do just that via PropertyManager pages (PMP). At the end of the lesson we also show you how to create previews using temporary bodies.


Run-time errors in VBA classes are a little quirky. When an object doesn’t get set, you might not get an error at all. Instead, the macro just stops. Or you might get an error on the line of your standard module that calls a procedure within the class, even though the error actually occurred on a line in the class.

If a PMP is open and you need to select one of the following objects, do not use the Select method found within the interface of that object. Instead use IModelDocExtension::SelectByID2, which handles selection correctly regardless of whether the PMP is open.

  • IAnnotation
  • IComponent2
  • IFeature
  • IFeatureManager
  • ISketchHatch
  • ISketchPoint
  • ISketchSegment
  • ISketchSpline

Advanced: It is possible to contain the PMP layout and handling code in the same class. The advantage of this is that you do not need to create Public variables for the resource ID’s in a standard module. For handler argument in ISldWorks::CreatePropertyManagerPage, use “Me” since you are referencing that module.

Lesson Files

Lesson 7.4 code – start
Lesson 7.4 code
Lesson 7.4 – create spike
Code snippets


  1. CryoDesigner

    Hi Keith,

    IPropertyManagerPageSelectionbox::ItemText gets me the text inside the Selection Box but how can I Set the text inside the Selection Box. I have my Section Box to filter dimensions but sometimes I get the generic “Dimension” and other times I get the dimension name such as “D6@Sketch3”. I prefer the latter so I thought I would just programmatically get the name of the dimension but I have to be able to write to the Selection Box. Thanks

    • I don’t think you can set that text value, unfortunately. It would have to be via either a member of IPropertyManagerPageSelectionbox or IPropertyManagerPageControl (which the former inherits from) and neither of those classes contain members that let you do that.

  2. Harvard

    If I am using a PMP to change dimensions on a specific sketch were some values of would not be allowed, and if a user enters a value that is too small so the macro automatically sets it to the smallest allowable value, how would you updated the PMP with that value instead of continuing to display the value that was entered?

    • It sounds like you want to modify the value of a PMP control. You need to locate the property that lets you set the text for that control. For example, if you’re using a text box control (IPropertyManagerPageTextbox) then you would use IPropertyManagerPageTextbox::Text to change the value of the control. There are corresponding properties for the other controls as well.

  3. cbalde04

    The macro code message says “Select any number of faces and select a color.”, but only seems to allow the selection of one face.

    If you set pmSelection.SingleEntityOnly = False, how do you access the multiple selected entities within the selection box and get their entity values? via an array?

    • cbalde04

      I think I found a workaround.
      The selections within the SelectionBox are also passed to the SelectionManager (if it’s called out in the declarations), so you can use the selection manager to grab those objects selected in the SelectionBox and utilize their properties using the SelectionManager methods.

Questions and Comments

You must be logged in to post a comment.