×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journal to add appended before text to PMI dimensions

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:

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

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

RE: Journal to add appended before text to PMI dimensions

(OP)
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".

RE: Journal to add appended before text to PMI dimensions

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

RE: Journal to add appended before text to PMI dimensions

(OP)
Awesome! that works perfect. Thank you cowski

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources