4 Replies Latest reply on Jan 8, 2014 10:41 AM by John Carlson

    API:  In an assembly drawing, determining what component is attached to a BOM balloon

    John Carlson

      I'm trying to programmatically determine which component a BOM balloon is attached to in an assembly drawing.

       

      So far, in VBA, I'm using iAnnotation.GetAttachedEntities3 and then iEntity.GetComponent.  This works well unless the note is attached to a silhouette edge in which case I get a "Type Mismatch" when I attempt to set the result from iAnnotation.GetAttachedEntities3 to an variable defined as a SldWorks.Entity type.

       

      With SolidWorks 2013, I actually could use iAnnotation.GetAttachedEntities2 and it would work with silhouette edges.  However, now in SolidWorks 2014 that "trick" doesn't work.

       

      So my question is if there is a different (better??) approach that I should be using.

        • Re: API:  In an assembly drawing, determining what component is attached to a BOM balloon
          Jim Sculley

          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.

           

          Jim S.

            • Re: API:  In an assembly drawing, determining what component is attached to a BOM balloon
              John Carlson

              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.

                • Re: API:  In an assembly drawing, determining what component is attached to a BOM balloon
                  Jim Sculley

                  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:

                   

                  exception.png

                   

                  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.

                   

                  Jim S.