How to find a component occurrence from a balloon?

By Philippe Leefsma

Q:

Is there a way to get the component occurrence that a balloon is pointing to?

A:

The “LeaderNode.AttachedEntity” tells the geometry intent (attachment) for the node, from which we could know the model geometry. The code below supposes that the drawing view is created by an assembly and a balloon (one leader node) attached to one component of the assembly.

Another way is BalloonValueSet.ReferencedRow. A sample [GetComponentReferencedByBalloon] is available in the Inventor API help files.

    ‘ Assumess the drawing view is created from a assembly.

    ‘ Select a balloon manually before running this procedure

    Private Sub test(ByVal app As Inventor.Application)

 

        Dim doc As DrawingDocument = app.ActiveDocument

 

        Dim balloon As Balloon = doc.SelectSet(1)

 

        Dim leader As Leader = balloon.Leader

 

        ‘assuming the leader is a single line segment

        Dim leaderNode As LeaderNode = leader.AllNodes(2)

 

        Dim intent As GeometryIntent = leaderNode.AttachedEntity

 

        Dim curve As
DrawingCurve = intent.Geometry

 

        Dim edgePx As EdgeProxy = curve.ModelGeometry

 

        Dim occurrence As ComponentOccurrence = edgePx.ContainingOccurrence

 

        Debug.Print(vbCrLf + "Occurrence Name: " + occurrence.Name)

 

    End Sub

<

p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”> 


Comments

6 responses to “How to find a component occurrence from a balloon?”

  1. Hello,
    How can I make this work in Inventor.
    I am not a VBA expert say the least.
    Thanks
    Dan

  2. Philippe Leefsma Avatar
    Philippe Leefsma

    Hi Dan,
    That code is VB.Net, what programming language are you using? Once you get to know the objects that are involved it should be pretty straightforward to convert that in any other language.
    There are free tools on the web to convert between C# and VB.Net syntax also…

  3. What I meant was that in Inventor we have VBA editor. Usually I copy paste the code inside VBA in Inventor and then it builds the macro and I can run it. With this code is not working.
    I thought maybe something special is needed.
    Thanks
    Dan

  4. Philippe Avatar
    Philippe

    Well this code is VB.Net. We do not encourage people to write VBA code because the technology is kind of deprecated, we rather push developers to .Net, so you will find on this blog mostly .Net examples.
    Unfortunately we cannot spend time converting back all our samples to VBA, you would need to learn a bit what the differences are between VBA nd VB.Net in order to do the conversion yourself. That’s mainly the variables declaration that need to be separated from the affectation and the use of “Set” keyword.
    You should be able to find easily resources on the web for beginners in order to understand the syntax and differences between those two languages.

  5. If I have attach balloon? How Can I recognize Occurence?
    Thanks,
    Mario

  6. InventorDude Avatar
    InventorDude

    Please note that if you’re using sheet metal or are otherwise pointing at the tangent edges of a round feature (sheet metal bend radius, possibly fillets as well), you should assign
    curve.ModelGeometry to a FaceProxy instead of an EdgeProxy.
    Spent some time trying to figure this out. I used a try/catch block to handle both cases, though you might get away with finding curve.ModelGeometry.type and using a conditional to handle each case.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading