Fixing the inconsistent selections in the SOLIDWORKS macro

Edit ArticleEdit Article
See more issues and resolutions


SOLIDWORKS macro was recorded by Macro Recording Tool and requires some selections to be made (usually for feature creation or mating). When running the macro the selection may fail or different object is selected which is causing the macro misbehavior.


Usually macro recording is using the IModelDocExtension::SelectByID2 SOLIDWORKS API method to capture the selection. This method may use temporarily names (like sketch segment names) or coordinates for selection which might not be consistent across different models or view orientations.

Recorded macro line to select arc in the sketch by name
Recorded macro line to select arc in the sketch by name


Update the selection method. Refer the Selection article for detailed guide.


All articles and code at CodeStack are now open-source and hosted on GitHub. If you want to contribute by modifying existing articles and code snippets, submitting new ones, reporting errors and bugs etc. please follow this blog post for more information. We appreciate any contribution.

Product of Xarial Product of Xarial