Adding custom note (aftertext) to dimensions

Hello everybody, first of all, thanks for many useful macros, lessons i've got from here.

I created a journal that add a custom aftertext to selected dimension.
But i am still not so able to aply journal to multiple selection.
Or even better to search for dimensions with any kind of tolerance and then apply to all of them the custom after text.

This is my current situation. Any help?

' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
Imports System
Imports NXOpen

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

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()

Dim linearDimensionBuilder1 As NXOpen.Annotations.LinearDimensionBuilder = Nothing
linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(CType(theUI.SelectionManager.GetSelectedTaggedObject(0), Annotations.Dimension))

'for each aftertext as string in linearDimensionBuilder1.appendedtext.getafter(0)
Dim text(0) As String
text(0) = "<&70><+> <+><&90>"
linearDimensionBuilder1.AppendedText.SetAfter(text)
'next

Dim nXObject1 As NXOpen.NXObject = linearDimensionBuilder1.Commit()
linearDimensionBuilder1.Destroy()

End Sub
End Module

You can find some code in the link below that shows how to iterate through all the dimensions and check the tolerance type.

http://nxjournaling.com/comment/2747#comment-2747

I've got few commands from there, but now i got stucked with something else.
i need to edit dimensions with any kind of tolerance.
I think i did something wrong with dimension builders.
This is my current situation

' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
Imports System
Imports NXOpen
Imports NXOpenUI
Imports MiniSnap, MiniSnap.Create

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

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()
Dim myDimText() As String
Dim myDimDualText() As String
Dim myToleranceType As String

For Each myDimension As Annotations.Dimension In workPart.Dimensions
myToleranceType = myDimension.ToleranceType.ToString
If myToleranceType <> "None" Then
theUI.SelectionManager.AddToTaggedObjectsSelectionList(select, mydimension)
Dim linearDimensionBuilder1 As NXOpen.Annotations.LinearDimensionBuilder = Nothing
'linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(theUI.SelectionManager.AddToTaggedObjectsSelectionList(select, mydimension))
linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(mydimension)
Dim aftertext1(0) As String
aftertext1(0) = "<&70><+> <+><&90>"
linearDimensionBuilder1.AppendedText.SetAfter(aftertext1)

Else Return
End If
Next

End Sub
End Module

After setting the appended text, be sure to call the builder's .Commit and .Destroy methods.

I made it somehow, the only detail now is that it doesent work with radial dimensions :(

' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
' NX 11.0.2.7
' Journal created by dalibor.balic on Tue Dec 19 08:14:16 2017 ora solare Europa occidentale
'
Imports System
Imports NXOpen
Imports NXOpenUI
Imports MiniSnap, MiniSnap.Create

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

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()

For Each myDimension As Annotations.Dimension In workPart.Dimensions
dim myToleranceType = myDimension.ToleranceType.ToString

If myToleranceType <> "None" then

Dim linearDimensionBuilder1 As NXOpen.Annotations.linearDimensionBuilder = Nothing
linearDimensionBuilder1 = workPart.Dimensions.createlinearDimensionBuilder(ctype(myDimension, Annotations.Dimension))

Dim aftertext1(0) As String
aftertext1(0) = "<&70><+> <+><&90>"
linearDimensionBuilder1.AppendedText.SetAfter(aftertext1)

Dim nXObject1 As NXOpen.NXObject = linearDimensionBuilder1.Commit()
linearDimensionBuilder1.Destroy()

End If

Next

End Sub
End Module
<\code>

I wouldn't expect a linear dimension builder to work with radial dimensions or angular dimensions. If you need to process multiple types of dimensions, there are a couple of options:

  • check the dimension type and create the appropriate builder to edit the dimension
  • skip the dimension builder object and edit the dimension object directly

The code below illustrates the 2nd option; it is not a complete journal, you will need to incorporate it into your code. I'd suggest adding the undo mark before your for each loop, processing the appended text in the loop, and performing the update after the loop is done.

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

'dimension selection code omitted

Dim myAppendedText As Annotations.AppendedText = myDim.GetAppendedText

Dim newAfterText(0) As String
newAfterText(0) = "NEW APPENDED TEXT"
myAppendedText.SetAfterText(newAfterText)

myDim.SetAppendedText(myAppendedText)

'update dimension display
myAppendedText.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

Yes, that works perfectly.
Thank you very much!