Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to add appended before text to PMI dimensions 1

Status
Not open for further replies.

someonedflr

Automotive
Jan 14, 2014
40
0
0
US
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:

Code:
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!!
 
Replies continue below

Recommended for you

You want to loop through the existing dimensions and add/edit the appended text. The code you have loops through the dimensions then loops through the existing appended text on each dimension. I'm not sure the purpose of the inner loop, I think you can get rid of it.

www.nxjournaling.com
 
Ok, I got rid of the inner loop, but still I'm not sure how I could assign the text to the dimensions in the first loop... I tried with modifying the loop like this:

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
        Next

but 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".
 
I'd try this (beware that it will affect all dimensions in the part, not just the PMI dims).

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
 
Status
Not open for further replies.
Back
Top