NX Tracking manual/user edited dimensions in NXOpen

2022-09-12T11:15:13Z
NX Open

Summary


Details

How to track manual/user edited dimensions in NXOpen?

Solution

The method to use is NXOpen.UF > UFDrf > AskObjectPreferences. This method returns some arrays of values containing information about the given annotation object. The variable "mpi(7)" will be the one with the dimensional modification information you are looking for:

MPI[7] Text Entry Mode

1 = Only Automatic Text

2 = Automatic Text, Appended

3 = Only Manual Text

4 = Manual Text, Appended

User needs to check for a value of 3 or 4 which indicates that the dimension text has been modified.

Sample code to highlight all dimensions with manual text and optionally delete or fix them:-

----------------------------------------------------------------------------------------------------------------------------------

Imports NXOpen

Imports NXOpen.UF

Module NXJournal

Dim theSession As Session = Session.GetSession()

Dim theUFSession As UFSession = UFSession.GetUFSession()

Dim workPart As Part = theSession.Parts.Work

Sub DoIt()

Dim manualDimensions As System.Collections.ArrayList =

New System.Collections.ArrayList

Dim mpi(99) As Integer

Dim mpr(69) As Double

Dim radius_value As String = Nothing

Dim diameter_value As String = Nothing

For Each thisDimension As Annotations.Dimension In workPart.Dimensions.ToArray()

theUFSession.Drf.AskObjectPreferences(thisDimension.Tag, mpi, mpr,

radius_value, diameter_value)

If mpi(7) > 2 Then manualDimensions.Add(thisDimension)

Next

If manualDimensions.Count = 0 Then

Echo("No manual text dimensions found")

Return

End If

For Each thisDisplayableObject As DisplayableObject In manualDimensions

thisDisplayableObject.Highlight()

Next

Dim options As String() = {"Delete", "Convert back to automatic text", "Ignore"}

Dim nowWhat As String = ChooseOneString(manualDimensions.Count &

" Manual Dimensions Highlighted", options)

For Each thisDisplayableObject As DisplayableObject In manualDimensions

thisDisplayableObject.Unhighlight()

Next

Select Case nowWhat

Case "Delete"

Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(

Session.MarkVisibility.Visible, "Delete all Manual Dimensions")

For Each thisNXObject As NXObject In manualDimensions

theSession.UpdateManager.AddToDeleteList(thisNXObject)

Next

theSession.UpdateManager.DoUpdate(markId1)

Case "Convert back to automatic text"

Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(

Session.MarkVisibility.Visible, "Fix all Manual Dimensions")

For Each thisNXObject As NXObject In manualDimensions

theUFSession.Drf.AskObjectPreferences(thisNXObject.Tag, mpi, mpr,

radius_value, diameter_value)

mpi(7) = mpi(7) - 2 ' 3-> 1, 4-> 2

theUFSession.Drf.SetObjectPreferences(thisNXObject.Tag, mpi, mpr,

radius_value, diameter_value)

Next

Case Else

End Select

End Sub

Function ChooseOneString(ByRef prompt As String, ByRef choices() As String) As String

If choices.Length = 0 Then Return Nothing

' comment out the next line if using a Do/Until Nothing loop!

If choices.Length = 1 Then Return choices(0)

Dim opts(13) As String

Dim a As Integer = 0

Dim ii, resp, z As Integer

Dim n_choices As Integer = choices.Length

Do

If (n_choices - a) < 14 Then

z = n_choices - a

Else

z = 14

End If

For ii = 0 To z - 1

opts(ii) = choices(a + ii)

Next

If ((z = 14) And ((a + z) < n_choices)) Then opts(13) = "More..."

theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

resp = theUFSession.Ui.DisplayMenu(prompt, 0, opts, z)

theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

Select Case resp

Case 1 ' Back

If (a = 0) Then Return Nothing

a = a - 13

Case 2 ' Cancel

Return Nothing

Case 18 ' More ...

If ((a + z) < n_choices) Then a = a + 13

Case Else ' Picked one

Return choices(a + resp - 5)

End Select

Loop While True

Return Nothing ' can't really get here

End Function

Public Sub Main(ByVal args As String())

If workPart IsNot Nothing Then

DoIt()

Else

Echo("This journal requires an open part")

End If

End Sub

Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()

theSession.ListingWindow.WriteLine(output)

theSession.LogFile.WriteLine(output)

End Sub

Public Function GetUnloadOption(ByVal arg As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

-------------------------------------------------------------------------------------------

Notes

KB Article ID# PL8664928

Contents

SummaryDetails

Associated Components

NX Open - All Languages