Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Check if a specific occurrence has been ballooned

mat_hijs
Collaborator

Check if a specific occurrence has been ballooned

mat_hijs
Collaborator
Collaborator

I'm trying to automate some drawings where I want to balloon a lot of components. I would like to add some kind of check to see if the occurrences I'm about to balloon already have a balloon because I don't want to add duplicates. Does anyone have any idea how to do this?

0 Likes
Reply
Accepted solutions (1)
406 Views
9 Replies
Replies (9)

SevInventor
Advocate
Advocate

Happy New Year,

 

try this:

 

	Dim oDoc As Document = ThisDoc.Document
    If oDoc.DocumentType <> kDrawingDocumentObject Then: MsgBox("drawings only!"): Exit Sub: End If
        
	Dim oSheet As Sheet = oDoc.ActiveSheet
    If oSheet Is Nothing Then: MsgBox("Only valid for drawings with sheets!"): Exit Sub: End If
	

	Dim oPL As PartsList = oSheet.PartsLists(1)
	
    If oPL.PartsListRows.Count < 1 Then: MsgBox("Only valid for partslists with rows"): Exit Sub: End If


 		For Each oRow In oPL.PartsListRows
	 		If oRow.Ballooned = False Then
				'do something
		Next

 

0 Likes

mat_hijs
Collaborator
Collaborator

Happy new year to you too, and thanks for the quick response. Correct me if I'm wrong since I have not tried the code yet, but doesn't this just check if at least one of each component has a balloon? I'll be having assemblies where the same component will have multiple occurrences and I need them all to be ballooned, not just one of each.

0 Likes

SevInventor
Advocate
Advocate

Yes you're right.

 

You can compare the count of the part list row to the number of occurrences in the assembly but i don't know if  you can get something like the  partlist.row.baloons.count

0 Likes

mat_hijs
Collaborator
Collaborator

I also thought about that, but I think that even when I have both counts I still won't know which occurrence is ballooned and which one isn't. For now I just delete all balloons and then add all the balloons I need, but this is not ideal when moving balloons from their "default" position for example.

0 Likes

SevInventor
Advocate
Advocate

with this code you can step through each Partlist row and have the Occurrences marked blue.

Maybe it helps you a bit.

Sub Main()

	Dim oDoc As Document = ThisDoc.Document
    If oDoc.DocumentType <> kDrawingDocumentObject Then: MsgBox("Run in drawings only!"): Exit Sub: End If
        
	Dim oSheet As Sheet = oDoc.ActiveSheet
    If oSheet Is Nothing Then: MsgBox("Only valid for dwg files with sheets!"): Exit Sub: End If
	
    If oSheet.PartsLists.Count <> 1 Then: MsgBox("Only valid for sheets with 1 PartsList"):Exit Sub: End If
	Dim oPL As PartsList = oSheet.PartsLists(1)
	
    If oPL.PartsListRows.Count < 1 Then: MsgBox("Only valid for partslists with actual rows"): Exit Sub: End If
	If oSheet.Balloons.Count < 1 Then : MsgBox("Rule only valid for sheets with balloons!") : Exit Sub : End If
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument.ReferencedDocuments.Item(1)	
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oview As DrawingView=oDoc.ActiveSheet.DrawingViews.item(2)	

	Dim oDoc1 As Document	
	Dim oSet As HighlightSet
	oSet = oDoc.CreateHighlightSet
   oview = ThisApplication.CommandManager _
        .Pick(kDrawingViewFilter, "Select a drawing view.")

	

	Dim Oocc As ComponentOccurrence
 		For Each oRow In oPL.PartsListRows
	 		

			oDoc1 = oRow.ReferencedFiles.Item(1).ReferencedDocument

					For Each Oocc In oAsmDef.Occurrences.AllReferencedOccurrences(oDoc1)
						Dim oCurveUnum As DrawingCurvesEnumerator
       					oCurveUnum = oview.DrawingCurves(Oocc)
        
        				Dim oCurve As DrawingCurve
        				Dim oSegment As DrawingCurveSegment
        
        					'add segments to collection to be moved to required layer
        				For Each oCurve In oCurveUnum
          					For Each oSegment In oCurve.Segments

						Try
							oSet.AddItem(oSegment)
							


Catch
	Continue For
End Try


					Next
					Next
					Next
		Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 255)

oSet.Color = oColor

MsgBox("ok?")

oSet.Clear()	
		Next




End Sub 

 

0 Likes

mat_hijs
Collaborator
Collaborator

Doesn't this still only look at if one or more occurrences of each component have been ballooned instead of if each occurrence has been ballooned?

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mat_hijs.  What you are asking for may simply not be possible.  And if it is possible, it will most likely require a lot of complicated code, and a lot of processing.  The there are only two associations between balloons and what they reference.  They have the BalloonValueSets, but each BalloonValueSet may only lead to a row of the BOM, not a specific component, when there is more than one component being represented by that row.  The other route is through what the balloon is actually physically attached to.  You can start down that path by first checking the Balloon.Attached property value, and if True, looking into the Balloon.Leader, then Leader.HasRootNode, then get the last node in the leader, and check its LeaderNode.AttachedEntity property, to get the GeometryIntent object.  Check its GeometryIntent.IntentType to see if it is the 'kGeometryIntent' variation of the IntentTypeEnum.  If it is, then get its GeometryIntent.Geometry to a variable (as an Object).  This can be multiple different types of objects, which is why its Type is just Object, instead of something more specific.  Because of this, a whole other block of code is needed that tests what Type it actually is, then reacts differently to the different Types.  In order for you to find out if one specific component has a balloon attached to it, you would have to loop through each sheet, because the balloons belong to the sheet.  Then you would have to test each view on each sheet, because we will need to use the DrawingView.DrawingCurves(oComponent) property as a means of getting the view geometry associated with that one component in that one view.  Then loop through each DrawingCurve in that DrawingCurvesEnumerator that you get from the DrawingCurves property (after checking if its Count = 0).  Check if the object you got from the GeometryIntent.Geometry property is that DrawingCurve from this loop.  If so, then you will know that component has a Balloon attached to it in at least one view, on at least one sheet.  Whew...:grinning_face_with_sweat:

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

mat_hijs
Collaborator
Collaborator

Well, that is pretty much exactly what I was trying to avoid. I was hoping I was missing a very simple link between the occurrence and the balloon but it seems that I'm not. I'll have to work around this then. Thanks anyway.

0 Likes