Adding Balloons to Drawing via iLogic

Adding Balloons to Drawing via iLogic

Anonymous
Not applicable
3,615 Views
9 Replies
Message 1 of 10

Adding Balloons to Drawing via iLogic

Anonymous
Not applicable

I'm having difficulty finding any useful information on how to automaticly add balloons via iLogic to the parts in my assembly drawing. There's little information on the subject or I'm just searching wrongly.

 

Hoping someone could help me a out! 🙂

0 Likes
3,616 Views
9 Replies
Replies (9)
Message 2 of 10

Paul1084
Advocate
Advocate

I will need to do this soon too, from what I can tell Balloons are accessed from the sheet:

Dim Doc As DrawingDocument
Doc = ThisDoc.Document 

Dim oSheet As Sheet
oSheet = Doc.Sheets.Item(1)

oSheet.Balloons.Add()

 tooltip.png

Message 3 of 10

Anonymous
Not applicable

It's been a while but I've found code (credits to Taking it to the next level: Drawing Automation) that made me able to add balloons. It's just not finding an object reference for the midPoint.

 

Sub Main()
        Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews.Item(1)
        Dim oAssemblyDoc As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

        Dim oOccs As Inventor.ComponentOccurrences = oAssemblyDoc.ComponentDefinition.Occurrences
        For Each oOcc As ComponentOccurrence In oOccs
               If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                       Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG, oOcc.SubOccurrences)
            Else
                Call CreateBalloon(oActiveSheet, oDrawingView, oTG, oOcc)
            End If
        Next
End Sub

Private Sub TraverseSubAssy(oActiveSheet As Sheet, oDrawingView As DrawingView, oTG As TransientGeometry, oOccs As ComponentOccurrences)
    For Each oOcc As ComponentOccurrence In oOccs
       If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
           Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG, oOcc.SubOccurrences)
       Else
           Call CreateBalloon(oActiveSheet, oDrawingView, oTG, oOcc)
       End If
    Next
End Sub

Public Sub CreateBalloon(oActiveSheet As Sheet, oDrawingView As DrawingView, oTG As TransientGeometry, oOcc As ComponentOccurrence)
    Dim oModelDoc As PartDocument = oOcc.Definition.Document    
    Dim oObjs As ObjectCollection = oModelDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "Balloon")
    If oObjs.Count = 0 Then              
            Exit Sub
    End If
    
    Dim oFace As Face
    oFace = oObjs.Item(1)
    
    Dim oFaceProxy As FaceProxy
    oOcc.CreateGeometryProxy(oFace, oFaceProxy)
    
    Dim oDrawCurves As DrawingCurvesEnumerator
    oDrawCurves = oDrawingView.DrawingCurves(oFaceProxy)
    
    Dim oDrawingCurve As DrawingCurve
    oDrawingCurve = oDrawCurves.Item(1)
    
    Dim midPoint As Point2d = Nothing
    midPoint = oDrawingCurve.MidPoint
    

    Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	
    	
		
       oLeaderPoints.Add(oTG.CreatePoint2d(midPoint.X, midPoint.Y ))
  
    
    Dim geoIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, .5)
    oLeaderPoints.Add(geoIntent)    

    Dim oBalloon As Balloon = Nothing
    oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints)        
End Sub

 

Message 4 of 10

blandb
Mentor
Mentor

Trying to run this is 2021, but nothing happens, no errors, nothing.

Autodesk Certified Professional
0 Likes
Message 5 of 10

JelteDeJong
Mentor
Mentor

this works for me in Inventor 2021.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim refDoc As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument
Dim occ As ComponentOccurrence = refDoc.ComponentDefinition.Occurrences.Item(1)

' change the face number if the face produce a drawing curve
Dim faceNumber As Integer = 1
Dim face As Face = occ.SurfaceBodies.Item(1).Faces.Item(faceNumber)
Dim curves = view.DrawingCurves(face)

If (curves.Count = 0) Then
    Throw New Exception("None DrawingCurve found.")
End If

Dim curve As DrawingCurve = curves.Item(1)
Dim geoIntent As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
Dim pointsColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

pointsColl.Add(ThisApplication.TransientGeometry.CreatePoint2d(0, 0))
pointsColl.Add(geoIntent)

sheet.Balloons.Add(pointsColl)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 10

JelteDeJong
Mentor
Mentor

the biggest problem here is getting the intent object. (That is the point that is connected to a curve on your drawing.) there is a other way of doing this. In my blog I wrote about it. With the function that I created there its possible to do this with much less code.

' the content of this file can be found in the blog post
AddVbFile "ManagedDrawingViewExtensions.iLogicVb"


Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Standard Goedhart:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim geoIntent As GeometryIntent = VIEW1.GetProxyIntent("<your face name here>")

Dim pointsColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

pointsColl.Add(ThisApplication.TransientGeometry.CreatePoint2d(0, 0))
pointsColl.Add(geoIntent)
Sheet_1.Sheet.Balloons.Add(pointsColl)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 10

blandb
Mentor
Mentor

Tried this, but I get the error:

 

Error in rule.........

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

More ingo tab:

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.SurfaceBodies.get_Item(Int32 Index)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Autodesk Certified Professional
0 Likes
Message 8 of 10

Daan_M
Collaborator
Collaborator

I'm trying to create balloons on a drawingview, but i'm getting an error:

 

'Public member 'GetIntent' on type 'DrawingView' not found'

 

Code;

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oDrawingView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oIntent As GeometryIntent = oDrawingView.GetIntent(PointIntentEnum.kAxisMidPointIntent)

Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 

oLeaderPoints.Add(oTG.CreatePoint2d(0, 0))
oLeaderPoints.Add(oIntent)
oSheet.Balloons.Add(oLeaderPoints)

 

 

0 Likes
Message 9 of 10

Paul1084
Advocate
Advocate

Think you need to specify your model geometry... I am working on code like this currently for dimensioning... my geometry intent references the model:

 

SU1Point = VIEW1.GetIntent({Frame.Name, "SU1"}, "Center Point")

Frame is a component occurrence 

0 Likes
Message 10 of 10

WCrihfield
Mentor
Mentor

Hi @Daan_M.  That 'GetIntent' method you are trying to use is not a method of the regular DrawingView API object, it is a method of the IManagedDrawingView iLogic Interface object (Link, Link).  The equivalent method in the regular Inventor API can be found in either of these two places:  AssemblyComponentDefinition.CreateGeometryIntent(), or PartComponentDefinition.CreateGeometryIntent(), and they require different types of input.  If your target geometry is down a couple layers deep within an assembly, then you usually have to get the proxy of the original geometry from its parent ComponentOccurrence.CreateGeometryProxy() method, then possibly again at the next step up, with that proxy object as the input for that method, to get the top level object, before you can then use that top level object as your reference for getting the GeometryIntent, and placing the balloon.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)