Balloon all components of an assembly view

Balloon all components of an assembly view

william
Advocate Advocate
140 Views
2 Replies
Message 1 of 3

Balloon all components of an assembly view

william
Advocate
Advocate

Hello All
My objective is to balloon all components in an assembly view. I have a rule that I believe it should work, but I keep getting an argument error when I go to add the balloons using the object collection. 
This has got me stumped for now, any advice is appreciated. 

' Add a balloon for each referenced component
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oView As DrawingView
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

' Get the target view
For Each v As DrawingView In oSheet.DrawingViews
    If v.Name = "TOP" Then
        oView = v
        Exit For
    End If
Next

Dim oAssemblyDoc  As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oOccs As Inventor.ComponentOccurrences = oAssemblyDoc.ComponentDefinition.Occurrences
Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oOcc As ComponentOccurrence In oOccs
    Try
        ' Try each edge until you find a drawable curve
        For Each oEdge As Edge In oOcc.SurfaceBodies.Item(1).Edges
            Dim oEdgeProxy As EdgeProxy
            oOcc.CreateGeometryProxy(oEdge, oEdgeProxy)

            Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oEdgeProxy)
            If oCurves.Count > 0 Then
                Dim oCurve As DrawingCurve = oCurves.Item(1)
                Dim midPt As Point2d = oCurve.MidPoint
                oLeaderPoints.Add(oTG.CreatePoint2d(midPt.X, midPt.Y))
                Dim intent As GeometryIntent = oSheet.CreateGeometryIntent(oCurve, 0.5)
                oLeaderPoints.Add(intent)
				Logger.Info("Point added for: " & oOcc.Name)
                Exit For
            End If
        Next
    Catch ex As Exception
        Logger.Error("Curve not found for " & oOcc.Name & ": " & ex.Message)
    End Try
Next

If oLeaderPoints.Count > 0 Then
	oSheet.Balloons.Add(oLeaderPoints)
Else
    Logger.Error("No valid curves found for balloon placement.")
End If


The error is: 
"System.ArgumentException: The parameter is incorrect. (0x80070057 (E_INVALIDARG))
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Object[] aArgs, Boolean[] aArgsIsByRef, Int32[] aArgsWrapperTypes, Type[] aArgsTypes, Type retType)
at Inventor.Balloons.Add(ObjectCollection LeaderPoints, Object VirtualComponent, Object Level, Object NumberingScheme, Object BalloonStyle, Object Layer)
at ThisRule.Main() in rule: Balloon, in document IMP-0600_ASSY CONFIG.idw:line 43
at Autodesk.iLogic.Exec.AppDomExec.ExecCodeHere()
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

0 Likes
Accepted solutions (1)
141 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @william .

I adjusted the logic of your code a little, now it works fine. I can't say why it didn't work properly before, because it's more likely related to the requirements for Balloons' build points.
I recommend that you familiarize yourself with the codes in this post.

' Add a balloon for each referenced component
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDrawDoc As DrawingDocument = oInvApp.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oView As DrawingView
Dim oTG As TransientGeometry = oInvApp.TransientGeometry
Dim oTO As TransientObjects = oInvApp.TransientObjects

' Get the target view
For Each v As DrawingView In oSheet.DrawingViews
    If v.Name = "TOP" Then
        oView = v
        Exit For
    End If
Next
If oView Is Nothing Then Exit Sub

Dim oAssemblyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oOccs As Inventor.ComponentOccurrences = oAssemblyDoc.ComponentDefinition.Occurrences

For Each oOcc As ComponentOccurrence In oOccs
	Dim oLeaderPoints As ObjectCollection = oTO.CreateObjectCollection
    Try
        ' Try each edge until you find a drawable curve
        For Each oEdge As Edge In oOcc.SurfaceBodies.Item(1).Edges
            Dim oEdgeProxy As EdgeProxy
            oOcc.CreateGeometryProxy(oEdge, oEdgeProxy)

            Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oEdgeProxy)
            If oCurves.Count > 0 Then
                Dim oCurve As DrawingCurve = oCurves.Item(1)
                Dim midPt As Point2d = oCurve.MidPoint
                oLeaderPoints.Add(oTG.CreatePoint2d(midPt.X, midPt.Y))
                Dim intent As GeometryIntent = oSheet.CreateGeometryIntent(oCurve, 0.5)
                oLeaderPoints.Add(intent)
				oSheet.Balloons.Add(oLeaderPoints)
				Logger.Info("Point added for: " & oOcc.Name)
                Exit For
            End If
        Next
    Catch ex As Exception
        Logger.Error("Curve not found for " & oOcc.Name & ": " & ex.Message)
    End Try
Next

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 3

william
Advocate
Advocate

Thanks Andrii
I was close then!
I will be going through the post you mentioned to learn more about this topic. 

0 Likes