Journal to add appended before text to PMI dimensions
Journal to add appended before text to PMI dimensions
(OP)
Hello,
I'm by no means an expert developing journals, but the opposite, hehe... but I have been trying to made up a code that add appended before text to all the PMI dimensions in a model. My purpose is to list them as (1), (2), (3), etc... I have taken some parts of code from other threads here, and modified it a little bit. It lists the dimensions as pretended, but only the dimensions which already have a text assigned to the appended before text. If they have no text, they remain like that.
So my question is, how to list all the dimensions, regardless they whether or not have appended text?.
Here is my code so far:
Thanks in advance!!
I'm by no means an expert developing journals, but the opposite, hehe... but I have been trying to made up a code that add appended before text to all the PMI dimensions in a model. My purpose is to list them as (1), (2), (3), etc... I have taken some parts of code from other threads here, and modified it a little bit. It lists the dimensions as pretended, but only the dimensions which already have a text assigned to the appended before text. If they have no text, they remain like that.
So my question is, how to list all the dimensions, regardless they whether or not have appended text?.
Here is my code so far:
CODE --> .net
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Imports NXOpen.Annotations
Module ChangeDimText
Dim s As Session = Session.GetSession()
Dim dp As Part = s.Parts.Display
Dim n As Integer = 1
Sub Main()
Dim markId2 As Session.UndoMarkId
markId2 = s.SetUndoMark(Session.MarkVisibility.Visible, "Edit Dimension Text")
Dim dims() As Annotations.Dimension = dp.Dimensions.ToArray
For Each dim1 As Dimension In dims
Dim appendedtext1 As Annotations.AppendedText = dim1.GetAppendedText()
Dim beforetext() As String = appendedtext1.GetBeforeText()
For i As Integer = 0 To beforetext.Length - 1
beforetext(i) = "(" & n & ")"
appendedtext1.SetBeforeText(beforetext)
dim1.SetAppendedText(appendedtext1)
n = n + 1
Next
Next
Dim nErrs1 As Integer
nErrs1 = s.UpdateManager.DoUpdate(markId2)
End Sub
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 Thanks in advance!!





RE: Journal to add appended before text to PMI dimensions
www.nxjournaling.com
RE: Journal to add appended before text to PMI dimensions
CODE -->
Dim dims() As Annotations.Dimension = dp.Dimensions.ToArray For Each dim1 As Dimension In dims Dim appendedlist = "(" & n & ")" dim1.SetAppendedText(appendedlist) n = n + 1 Nextbut I got the error "System.InvalidCastException: Unable to cast object of type 'System.String' to type 'NXopen.Annotations.AppendedText'. at ChangeDimText.Main() in line 29".
RE: Journal to add appended before text to PMI dimensions
CODE
Dim n As Integer = 1 Dim newBeforeText(0) As String Dim appendedText As Annotations.AppendedText For Each tempDim As Annotations.Dimension In workPart.Dimensions lw.WriteLine(tempDim.GetType.ToString) newBeforeText(0) = "(" & n.ToString & ")" appendedText = tempDim.GetAppendedText appendedText.SetBeforeText(newBeforeText) tempDim.SetAppendedText(appendedText) n += 1 Next theSession.UpdateManager.DoUpdate(markId1)www.nxjournaling.com
RE: Journal to add appended before text to PMI dimensions