Journal to remove leaders from all balloons but selected

I'm currently looking for a way to have a journal remove the leaders from all the balloons on a drafting sheet besides ones that I have selected. I create stacked balloons so only one leader is required per stack. The idea would be to run the journal, select the balloons with leaders to be exempted, and have the leaders on all of the remaining balloons be removed.

If you are working with callouts from an autoballoon operation, you may be able to make use of one of the "grouping" options. No journal code required in this case.

https://docs.plm.automation.siemens.com/tdoc/nx/10/nx_help/#uid:id919309

Unfortunately due to how the balloons are generated trying to use the grouping options results in an error either due to the balloons being from multiple views or there being "reference" balloons mixed in with "primary" balloons. This is why I wanted to explore the journaling approach.

Ok, I just wanted to make sure that you knew the options. Sometimes I see people coding up a solution that duplicates existing NX behavior simply because they did not know about it.

I'll work up some example code for removing leaders from ID symbols.

I managed to record this to remove the leader from a specific balloon. I'm just having a hard time broadening in out to what I'm looking for and removing the selection stickiness.

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim idSymbol1 As Annotations.IdSymbol = CType(workPart.FindObject("ENTITY 25 38 1"), Annotations.IdSymbol)

Dim idSymbolBuilder1 As Annotations.IdSymbolBuilder
idSymbolBuilder1 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(idSymbol1)

idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)

theSession.SetUndoMarkName(markId1, "Balloon Dialog")

idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim taggedObject1 As TaggedObject
taggedObject1 = idSymbolBuilder1.Leader.Leaders.FindItem(0)

Dim leaderData1 As Annotations.LeaderData = CType(taggedObject1, Annotations.LeaderData)

Dim leaderData2 As Annotations.LeaderData
leaderData2 = workPart.Annotations.CreateLeaderData()

leaderData2.StubSize = 5.0

leaderData2.Arrowhead = Annotations.LeaderData.ArrowheadType.FilledArrow

idSymbolBuilder1.Leader.Leaders.Append(leaderData2)

leaderData2.StubSide = Annotations.LeaderSide.Right

Dim dimensionlinearunits1 As Annotations.DimensionUnit
dimensionlinearunits1 = idSymbolBuilder1.Style.UnitsStyle.DimensionLinearUnits

Dim dimensionlinearunits2 As Annotations.DimensionUnit
dimensionlinearunits2 = idSymbolBuilder1.Style.UnitsStyle.DimensionLinearUnits

Dim dimensionlinearunits3 As Annotations.DimensionUnit
dimensionlinearunits3 = idSymbolBuilder1.Style.UnitsStyle.DimensionLinearUnits

idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)

idSymbolBuilder1.Origin.SetInferRelativeToGeometry(True)

' ----------------------------------------------
' Dialog Begin Balloon
' ----------------------------------------------

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Balloon")

idSymbolBuilder1.Leader.Leaders.Erase(0, ObjectList.DeleteOption.Delete)

theSession.SetUndoMarkName(markId3, "Balloon - LeaderBuilder")

theSession.SetUndoMarkVisibility(markId3, Nothing, Session.MarkVisibility.Visible)

theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Invisible)

Dim nXObject1 As NXObject
nXObject1 = idSymbolBuilder1.Commit()

theSession.SetUndoMarkName(markId1, "Balloon")

idSymbolBuilder1.Destroy()

theSession.SetUndoMarkVisibility(markId1, Nothing, Session.MarkVisibility.Visible)

theSession.DeleteUndoMark(markId3, Nothing)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Try the code below:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "remove ID symbol leaders")

lw.Open()

Dim selID As New List(Of Annotations.IdSymbol)
If SelectIdSymbols("select ID symbols with leaders to keep", selID) = Selection.Response.Cancel Then
Return
End If

For Each tempId As Annotations.IdSymbol In theSession.Parts.Work.Annotations.IdSymbols
If selID.Contains(tempId) Then
'user selected this symbol, we want to keep its leaders
Continue For
End If

Dim idSymbolBuilder1 As Annotations.IdSymbolBuilder
idSymbolBuilder1 = theSession.Parts.Work.Annotations.IdSymbols.CreateIdSymbolBuilder(tempId)

idSymbolBuilder1.Leader.Leaders.Clear(ObjectList.DeleteOption.Delete)

Dim nXObject1 As NXObject
nXObject1 = idSymbolBuilder1.Commit()

idSymbolBuilder1.Destroy()

Next

lw.Close()

End Sub

Function SelectIdSymbols(ByVal prompt As String, ByRef selIDSymbols As List(Of Annotations.IdSymbol)) As Selection.Response

Dim selObj() As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select an ID Symbol"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_drafting_entity_type
.Subtype = UFConstants.UF_draft_id_symbol_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
title, scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, selObj)
If resp = Selection.Response.Ok Then

For Each temp As Annotations.IdSymbol In selObj
selIDSymbols.Add(temp)
Next

Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Your code works brilliantly. Thank you very much for your help. On a side note, I dont suppose you know of a way to select multiple ID Symbols and have them stack (similar to the group option but allowing primary and reference symbols in the same stack)

You are welcome, glad that it worked for you.

As for stacking symbols, you should be able to move the symbols above, below, or next to each other as you see fit. When moving ID callout symbols around, I like to turn on the grid and snap options to easily and quickly align the callouts perfectly (set the snap spacing to be the same as the circular ID diameter). Also, the "alignment" options of the symbol will give you a way to position symbols relative to one another, with or without associativity.

Thanks, this helped me too.

BH