Adding balloons automatically API

Adding balloons automatically API

Anonymous
Not applicable
2,014 Views
12 Replies
Message 1 of 13

Adding balloons automatically API

Anonymous
Not applicable

Hello all,

 

I am trying to add balloons in an assembly with a code sample I got from an inventor atomation demo by Thomas Fitzgerald:  https://www.autodesk.com/autodesk-university/class/Taking-It-Next-Level-Drawing-Automation-Inventor-...

 

Sub Create_Balloon
		
 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
 Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews.oFrontview
Dim oAssemblyDoc As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
oDrawingView.ViewStyle = 32257

'*** Iterate through Assembly to find Parts

Dim oOccs As ComponentOccurrences = oAssemblyDoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType = 12291 Then
Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG,
oOcc.SubOccurrences)
Else
Call CreateBalloon(oActiveSheet, oDrawingView, oTG,
oOcc)
End If
 Next
oDrawingView.ViewStyle = 32258
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 = 12291 Then
Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG,
oOcc.SubOccurrences)
Else
Call CreateBalloon(oActiveSheet, oDrawingView, oTG,
oOcc)
End If
 Next
End Sub


Public Function CreateBalloon(oActiveSheet As Sheet, oDrawingView As DrawingView, oTG As TransientGeometry, oOcc As ComponentOccurrence)
Dim oModelDoc As Inventor.PartDocument
oModelDoc = oOcc.Definition.Document
'*** Find the tagged Faces
Dim oObjs As ObjectCollection = oModelDoc.AttributeManager.FindObjects("*", "*", "Balloon")
If oObjs.Count = 0 Then Exit Function

	
	Dim oFace As Inventor.Face
oFace = oObjs.Item(1)
Dim oFaceProxy As Inventor.FaceProxy
Call oOcc.CreateGeometryProxy(oFace, oFaceProxy)
Dim oDrawCurves As Inventor.DrawingCurvesEnumerator
oDrawCurves = oDrawingView.DrawingCurves(oFaceProxy)
Dim oDrawingCurve As Inventor.DrawingCurve
oDrawingCurve = oDrawCurves.Item(1)
Dim midPoint As Point2d = Nothing
midPoint = oDrawingCurve.MidPoint
Dim oLeaderPoints As ObjectCollection =
ThisApplication.TransientObjects.CreateObjectCollection

'*** Locate where the Balloon will be placed

If midPoint.X > oDrawingView.Position.X Then
oLeaderPoints.Add(oTG.CreatePoint2d(midPoint.X + 2, midPoint.Y- 1))
Else
oLeaderPoints.Add(oTG.CreatePoint2d(midPoint.X - 2, midPoint.Y- 1))
End If

'*** Must be the LAST point added to the array. This is the Balloon Leader attachment Point.

Dim geoIntent As Inventor.GeometryIntent =
oActiveSheet.CreateGeometryIntent(oDrawingCurve, .5)
oLeaderPoints.Add(geoIntent)

'*** Create the balloon

Dim oBalloon As Inventor.Balloon
oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints)

End Function

The problem is that the code seems to do nothing. No errors an no balloons show up either. 
I named the surfaces by right clicking them and using the assign name option.
Is this the wrong method or is there an error in the code?

 

thank you for your help in advance.

 

With kind regards,

Lennart

 

0 Likes
2,015 Views
12 Replies
Replies (12)
Message 2 of 13

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

This line should fail:

Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews.oFrontview

There's no property in DrawingView named "oFrontview".

 

If you change it to something like this (to run on the first view):

Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews(1)

 It should work, if you've named the faces "Balloon".

 

The iLogic rule then looks like this:

Sub Main
	Create_Balloon
End Sub

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

'*** Iterate through Assembly to find Parts

Dim oOccs As ComponentOccurrences = oAssemblyDoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.DefinitionDocumentType = 12291 Then
Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG,
oOcc.SubOccurrences)
Else
Call CreateBalloon(oActiveSheet, oDrawingView, oTG,
oOcc)
End If
 Next
oDrawingView.ViewStyle = 32258
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 = 12291 Then
Call TraverseSubAssy(oActiveSheet, oDrawingView, oTG,
oOcc.SubOccurrences)
Else
Call CreateBalloon(oActiveSheet, oDrawingView, oTG,
oOcc)
End If
 Next
End Sub


Public Function CreateBalloon(oActiveSheet As Sheet, oDrawingView As DrawingView, oTG As TransientGeometry, oOcc As ComponentOccurrence)
Dim oModelDoc As Inventor.PartDocument
oModelDoc = oOcc.Definition.Document
'*** Find the tagged Faces
Dim oObjs As ObjectCollection = oModelDoc.AttributeManager.FindObjects("*", "*", "Balloon")
If oObjs.Count = 0 Then Exit Function

	
	Dim oFace As Inventor.Face
oFace = oObjs.Item(1)
Dim oFaceProxy As Inventor.FaceProxy
Call oOcc.CreateGeometryProxy(oFace, oFaceProxy)
Dim oDrawCurves As Inventor.DrawingCurvesEnumerator
oDrawCurves = oDrawingView.DrawingCurves(oFaceProxy)
Dim oDrawingCurve As Inventor.DrawingCurve
oDrawingCurve = oDrawCurves.Item(1)
Dim midPoint As Point2d = Nothing
midPoint = oDrawingCurve.MidPoint
Dim oLeaderPoints As ObjectCollection =
ThisApplication.TransientObjects.CreateObjectCollection

'*** Locate where the Balloon will be placed

If midPoint.X > oDrawingView.Position.X Then
oLeaderPoints.Add(oTG.CreatePoint2d(midPoint.X + 2, midPoint.Y- 1))
Else
oLeaderPoints.Add(oTG.CreatePoint2d(midPoint.X - 2, midPoint.Y- 1))
End If

'*** Must be the LAST point added to the array. This is the Balloon Leader attachment Point.

Dim geoIntent As Inventor.GeometryIntent =
oActiveSheet.CreateGeometryIntent(oDrawingCurve, .5)
oLeaderPoints.Add(geoIntent)

'*** Create the balloon

Dim oBalloon As Inventor.Balloon
oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints)

End Function

 

 

0 Likes
Message 3 of 13

Anonymous
Not applicable

Hello @JhoelForshav,

 

The code works but it still does not detect the tagged faces. 
I diagnosed this by putting a messagebox after

If oObjs.Count = 0 Then Exit Function

The message box does not show up if I run the rule.

Could this happen because my model exists of multiple subassemblys?

 

 

0 Likes
Message 4 of 13

JhoelForshav
Mentor
Mentor

@Anonymous 

Is the view oriented in a way so that the named face is represented by a drawing curve?

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

So it looks like this.

lennart1423_0-1607504729021.pnglennart1423_1-1607505369227.png

I have not named all parts because im still testing.
As you kan see, the front face of square plate with the bolts trough it has been tagged.
On the drawing it is visible from its side.

0 Likes
Message 6 of 13

JhoelForshav
Mentor
Mentor

Looks right to me... It's difficult to say why it doesn't work. Could you attach a non-confidential dataset in which this code doesn't work so I can investigate? 🙂

0 Likes
Message 7 of 13

Anonymous
Not applicable

sure! what do you need exactly? 
something like an iLogic design copy?

 

0 Likes
Message 8 of 13

JhoelForshav
Mentor
Mentor

That should work 🙂 or if you have the assembly, parts and drawing in the same folder you can just zip that folder and attach it here

0 Likes
Message 9 of 13

Anonymous
Not applicable

okay,
I zipped it up.
The assembly is called "Testopstelling L support"

 

It may look a bit diffrent to what we discussed in the thread because the assembly is configurable.
Also, filenames and some notes in the rules are in dutch.

to get to the rule we are discussing:
in the map open the assembly "Testopstelling L Support"
The iLogic rule you are looking for is called: "drawing copy van kubus" (It is an odd name wich still has to be changed)

 

0 Likes
Message 10 of 13

Anonymous
Not applicable

Correction:

The assembly is called: "LSupportParametrisch" 

not: "Testopstelling L support


0 Likes
Message 11 of 13

JhoelForshav
Mentor
Mentor

Ok, So this was a bit more messy than I expected... I'm afraid I'll not have time to really dig in to it anytime soon😕

Hopefully you'll figure it out eventually or someone else here on the forum will help you.

Good luck!

0 Likes
Message 12 of 13

JhoelForshav
Mentor
Mentor

@Anonymous 

I didn't want to read through and debug your code so instead I wrote a new sub from the beginning for this.

I've tested it on your files and it works for me....

Sub Main
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick view")
PlaceBalloons(oView)
End Sub
Sub PlaceBalloons(oView As DrawingView)
Dim oAsm As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
	Try
		Dim oObjs As ObjectCollection = oOcc.Definition.Document.AttributeManager.FindObjects("*", "*", "Balloon")
		If oObjs.Count > 0 AndAlso TypeOf (oObjs(1)) Is Face
			Dim oProx As FaceProxy
			oOcc.CreateGeometryProxy(oObjs(1), oProx)
			Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oProx)
			If oCurves.Count > 0
				Dim oCurve As DrawingCurve = oCurves(1)
				Dim oMidPoint As Point2d = oCurve.MidPoint
				Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
				If oMidPoint.X > oView.Position.X Then
					oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 2, oMidPoint.Y - 1))
				Else
					oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X - 2, oMidPoint.Y - 1))
				End If
				Dim oIntent As GeometryIntent = oView.Parent.CreateGeometryIntent(oCurve, PointIntentEnum.kMidPointIntent)
				oLeaderPoints.Add(oIntent)
				oView.Parent.Balloons.Add(oLeaderPoints)
			End If
		End If
	Catch
	End Try
Next
End Sub	
Message 13 of 13

JMGunnar
Collaborator
Collaborator

You use suppress parts/assembly  in you assembly

 

it can not ask for "Balloon" surface in suppress parts 

 

Best Regards Johan G

 

0 Likes