How can I highlight a ballooned Assembly item in the drawing view, via coding?
Like highlight the balloon selected in on the sheet.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
This sample is not ideal, but it can be a good starting point for your research.
Sub Main()
Dim drawing As DrawingDocument = ThisDoc.Document
Dim hSet As HighlightSet = drawing.CreateHighlightSet()
Do
Dim balloon As Balloon = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kDrawingBalloonFilter,
"Select balloon")
hSet.Clear()
If balloon Is Nothing Then Exit Do
Dim drawingView As DrawingView = balloon.ParentView
Dim refAsm As AssemblyDocument = drawingView.ReferencedDocumentDescriptor.ReferencedDocument
For Each balloonValueSet As BalloonValueSet In balloon.BalloonValueSets
For Each compDef As ComponentDefinition In balloonValueSet.ReferencedRow.BOMRow.ComponentDefinitions
Dim occurrencesByComponentDefinition As ComponentOccurrencesEnumerator =
refAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(compDef)
For Each occurrence As ComponentOccurrence In occurrencesByComponentDefinition
Dim occurrenceCurves As DrawingCurvesEnumerator = drawingView.DrawingCurves(occurrence)
For Each drawingCurve As DrawingCurve In occurrenceCurves
For Each drawingCurveSegment As DrawingCurveSegment In drawingCurve.Segments
hSet.AddItem(drawingCurveSegment)
Next
Next
Next
Next
Next
Loop
End Sub
Hi @bradeneuropeArthur. I agree that there is likely no really good, clean, error proof way to do this task. I was about to tell you about the two different ways to approach this, but Michael beat me to an example the one way. The other way is through the Leader, LeaderNodes, LeaderNode.AttachedEntity, and so on. However, in a quick test on a couple test drawings of assemblies, I am not getting good results with that route either. It has to do with the GeometryIntent and its type. If it is a Geometry type, then we can usually dig deeper to get the model, but if it is a Point type or parameter type, no luck. Plus, this route can be a long rabbit hole, unfortunately.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oBalloons As Inventor.Balloons = oSheet.Balloons
If oBalloons.Count = 0 Then Return
Dim oHLS As HighlightSet = oDDoc.CreateHighlightSet
oHLS.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0) 'green
For Each oBalloon As Inventor.Balloon In oBalloons
oHLS.Clear
If oBalloon.Attached = False Then Continue For
Dim oView As DrawingView = oBalloon.ParentView
Dim oLeader As Inventor.Leader = oBalloon.Leader
If oLeader.HasRootNode = False Then Continue For
Dim oNodes As LeaderNodesEnumerator = oLeader.AllNodes
For Each oNode As LeaderNode In oNodes
Dim oGI As GeometryIntent = Nothing
Try : oGI = oNode.AttachedEntity : Catch : End Try
If oGI Is Nothing Then Continue For
Logger.Info("GeometryIntent.IntentType.ToString = " & oGI.IntentType.ToString)
Logger.Info("GeometryIntent.Intent Type = " & TypeName(oGI.Intent))
If oGI.IntentType = IntentTypeEnum.kGeometryIntent Then
Dim oDGeom As Object = oGI.Geometry
Logger.Info("GeometryIntent.Geometry Type = " & TypeName(oDGeom))
If TypeOf oDGeom Is DrawingCurve Then
Dim oDC As DrawingCurve = oDGeom
Dim oMGeom As Object = Nothing
Try : oMGeom = oDC.ModelGeometry : Catch : End Try
If oMGeom Is Nothing Then Continue For
If TypeOf oMGeom Is Edge Then
Dim oEdge As Edge = oMGeom
Dim oBody As SurfaceBody = oEdge.Parent
Dim oOcc As ComponentOccurrence = Nothing
If TypeOf oBody.Parent Is ComponentOccurrence Then
oOcc = oBody.Parent
Dim oDCs As DrawingCurvesEnumerator = Nothing
Try : oDCs = oView.DrawingCurves(oOcc) : Catch : End Try
If oDCs Is Nothing OrElse oDCs.Count = 0 Then Continue For
For Each oDCurve As DrawingCurve In oDCs
For Each oDCSeg As DrawingCurveSegment In oDCurve.Segments
oHLS.AddItem(oDCSeg)
Next
Next
End If
End If
End If
End If
Next 'oNode
MsgBox("Review currently highlighted geometry for Ballooned Item # " & oBalloon.BalloonValueSets.Item(1).ItemNumber, , "iLogic")
Next 'oBalloon
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.