I spent some time looking for a simple solution to this but I did not find a direct way to do it. The closest I came was The following:
1. Use GetAttachedEntities3 on the selected Annotation to get the SilhouetteEdge object
2. Use the Owner property of the Annotation to get the View
3. Use View::GetVisibleComponents to get a list of Component2 objects in the View
4. Loop through the Component2 objects:
i. Call View::GetVisibleEntities using the component and swViewEntityType_SilhouetteEdge as parameter values
ii. Loop through the returned array of SilhouetteEdges
a. Use GetStartPoint() and GetEndPoint() on each SilhouetteEdge and compare the x,y,z values (from the ArrayData property)
to those when calling GetStartPoint() and GetEndPoint() on the SilhouetteEdge from Step 1. If they match, then the current
Component2 being traversed is the Component2 where the balloon is attached.
This is a very clever approach. However, depending on which silhouette line is chosen, SolidWorks 2014 SP1 crashes on the iSilhouetteEdge.GetStartPoint. I had previously experimented with iSilhouetteEdge.GetFace and then getting the entity properties from the face, but had similar crash issues with SolidWorks on the GetFace.
I'm attaching a zip file with a drawing, assembly, component part, and a macro. On two computers I tested here, SolidWorks will crash consistently on the GetStartPoint. I'm not sure if I'm doing something wrong or if SolidWorks has some sort of issue.
Silhouette.zip 177.6 KB
Interestingly, the problem appears to be your test files. I see the same crash you describe on my SW2014 SP0 machine. If I use my own test files, your code completes without crashing. If I use my C# code on your test files, an Exception is thrown:
This is a very generic exception and doesn't really explain the crash. Were your test files created using SW2014 SP1? If you have a SW2014 SP0 machine available, you might want to recreate your test files there and see what happens. SW2014 SP1 is still in Early Visibility, so perhaps there is a bug that is causing the bad behavior.
I created the files in SW2014 SP0. I went to SP1 hoping that it fixed the problem. I'm rather confused if SP1 is EV or not too. It shows up in SolidWorks like a normal download but the SolidWorks News on the customer portal page make it sound like it's EV.
I originally saw the problem with some SW2013 geometry. Not the same part, but similar situation -- a straight silhouette edge from a cylinder shape causes a crash when trying to do much of anything with iSilhouette.