AnsweredAssumed Answered

How to remember SketchSegments?

Question asked by Greg James on May 4, 2017
Latest reply on May 8, 2017 by Greg James

I'm developing an Addin to generate SketchSegments.  It generates a lot of new segments based on selected lines and curves.  This is working great, but I need a way to remember the segments I've generated, so I can have buttons to select groups of them or manipulate them all together later on.  These buttons and operations must work at any later point in time, especially after user edits, so something simple like putting the newly created segments into the selection set will not work.


What's the preferred way to track a bunch of SketchSegments?  It must be robust as the user mucks about with the sketch, possibly deleting the segments I've created.


I've tried these methods of SketchSegment, but each falls flat in some way:

* Store a list of values from GetID().  This fails when the sketch is edited.  The IDs change, and new segments end up getting the original IDs.  This is despite what the SW docs claim about segment IDs never changing.

* Store a list of strings from GetName().  Same problem as with the IDs.  Names get recycled. 

* Store a list of references to SketchSegments.  This is the best so far, but if someone deletes one of these SketchSegments in the UI, how can I get notification that my object reference is no longer valid?  If a segment gets deleted in the UI, I can still call its methods and they return valid data (ID = 2, 3,  GetName = "Line3"), but eventually I get the wonderful COM exception "The object invoked has disconnected from its clients"


One other thing - I haven't been able to find any docs about SolidWorks' architecture and best practices with the API.  There's every detail about classes and methods, and lots of examples of fetching things for immediate use, but I don't find anything about overall concepts, manipulating the scene graph, how the undo stack works, what to be aware of in moving from a Part doc to an Assembly, etc.  A Best Practices doc would be a big help.


Thanks for any help!