Report Dimensions with Manual Text

The following journal will inspect the current work part for any drafting dimensions that have had their value overridden by a manual text entry. Any such dimensions will be highlighted and the sheet name, view name, and dimension text will be output to the listing window.

The journal was written on and tested with NX 7.5

 

[vbnet]
'NXJournaling.com
'tested with NX 7.5
'May 31, 2012
'When run, the journal will highlight all dimensions in the part that have manually entered text.
'The listing window will report the dimension text, view, and sheet for each dimension
'with manually entered text.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Report_Dimensions_manual_text

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mpi(99) As Integer
Dim mpr(69) As Double
Dim radius_value As String
Dim diameter_value As String
Dim manualTextCount As Integer = 0
Dim dictionary As New Collections.Generic.Dictionary(Of String, String)
Dim viewList() As View
Dim text1() As String
Dim text2() As String

lw.Open()

For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets
viewList = sheet.GetDraftingViews
For Each myView As View In viewList
dictionary.Add(myView.Name, sheet.Name)
Next
Next

Dim partDimensions() As Annotations.Dimension
partDimensions = workPart.Dimensions.ToArray
If partDimensions.Length > 0 Then
For Each partDimension As Annotations.Dimension In partDimensions
ufs.Drf.AskObjectPreferences(partDimension.Tag, mpi, mpr, radius_value, diameter_value)

If mpi(7) = 3 OrElse mpi(7) = 4 Then
'dimension has manual text
partDimension.Highlight()
lw.WriteLine("Sheet: " & dictionary(partDimension.GetAssociativity(1).ObjectView.Name))
lw.WriteLine("View: " & partDimension.GetAssociativity(1).ObjectView.Name)
partDimension.GetDimensionText(text1, text2)
Dim j As Integer
lw.WriteLine("Dimension Text: ")
For j = text1.GetLowerBound(0) To text1.GetUpperBound(0)
lw.WriteLine(" " & text1(j))
Next
manualTextCount += 1
lw.WriteLine("")
End If
Next
If manualTextCount > 0 Then
MsgBox(manualTextCount & " dimensions have manual text and have been highlighted")
Else
MsgBox("There are no dimensions with manual text in the part")
End If
Else
MsgBox("There are no dimensions in the work part")
End If

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module
[/vbnet]

Comments

Hi nxjournaling,
looking in the details on this function I have the problem this is on scope of the entire drawing part.
I cannot set the scope on the sheet for example if I have more than one sheet in my part. To cut it short
How can I find only the manual dimensions of the given drawingsheet ( or view )?
thanks in advance

I don't know of a way to limit the journal selection to dimensions on a given sheet. However, you can determine the sheet that a given dimension resides on. With this information, you can process only the dimensions that you are interested in.

The following code, by Amy Webster, is taken from GTAC document: nx_api4937.

' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet

Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUFSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUFSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

thank you nx journaling on reply,
It is not really clear what you try to explain.
Dim partDimensions() As Annotations.Dimension
partDimensions = workPart.Dimensions.ToArray
If partDimensions.Length > 0 Then
For Each partDimension As Annotations.Dimension In partDimensions

-> something like sheet dimensions to array but this will not work ->I'm looking for.
may you can give me some more advice
thanks in advance

Loop through the entire dimension collection, pass each dimension object to the function given above; it will return which drawing sheet the dimension resides on. When you find a dimension on the sheet you are interested in, perform whatever processing you need to do to that dimension object.

Alternately, you can create your own collection (array, list, stack, queue, etc) for each drawing sheet. Loop through the entire dimension collection (as above) and add them to the correct "sheet collection" that you have created based on which drawing sheet it resides on.

Hello
I tested it with NX 9.0.3. It works.
But, there is a Problem with highlighting. You can't de-highlighting dimension.
is there a possibility that mass colored differently? (without Highlight)
THX
BK

NX9

After running the journal, any leftover highlighting can be removed by running the part cleanup utility (use the 'remove extraneous highlighting' option). To remove the highlighting entirely from the journal either comment out or remove the following line:

partDimension.Highlight()

Thank you a lot.
But is there a function, how can I change the Dimensions with Manual Text automatically in other color (with this code)
in other words, instead of highlighting, recolor Dimensions with Manual Text.
THX
BK

NX9

The code below will change the color of the dimension with manual text rather than highlighting it. The code is currently set to use color 84 for dimensions with manual text; change this value as desired before running the journal.

'NXJournaling.com
'tested with NX 7.5
'May 31, 2012
'When run, the journal will highlight all dimensions in the part that have manually entered text.
'The listing window will report the dimension text, view, and sheet for each dimension
'with manually entered text.
'
'January 21, 2015
'Instead of using the .Highlight method, change the color of the dimension with manual text.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Report_Dimensions_manual_text_2

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main()

Dim lw As ListingWindow = theSession.ListingWindow
Dim mpi(99) As Integer
Dim mpr(69) As Double
Dim radius_value As String
Dim diameter_value As String
Dim manualTextCount As Integer = 0
Dim dictionary As New Collections.Generic.Dictionary(Of String, String)
Dim viewList() As View
Dim text1() As String
Dim text2() As String

lw.Open()

Const undoMarkName As String = "highlight manual dimensions"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets
viewList = sheet.GetDraftingViews
For Each myView As View In viewList
dictionary.Add(myView.Name, sheet.Name)
Next
Next

'******************************************************
'change this value to the color number of your choosing
Const manualDimColor As Integer = 84
'******************************************************

'find the color name of the chosen color above
Dim colorName As String = ""
Dim colorModel As Integer = UFConstants.UF_DISP_rgb_model
Dim colorValues(2) As Double
ufs.Disp.AskColor(manualDimColor, colorModel, colorName, colorValues)

Dim partDimensions() As Annotations.Dimension
partDimensions = workPart.Dimensions.ToArray
If partDimensions.Length > 0 Then
For Each partDimension As Annotations.Dimension In partDimensions
ufs.Drf.AskObjectPreferences(partDimension.Tag, mpi, mpr, radius_value, diameter_value)

If mpi(7) = 3 OrElse mpi(7) = 4 Then
'dimension has manual text
'partDimension.Highlight()
'color 84 = strong gold (in default CDF)
ColorDim(partDimension, manualDimColor)
lw.WriteLine("Sheet: " & dictionary(partDimension.GetAssociativity(1).ObjectView.Name))
lw.WriteLine("View: " & partDimension.GetAssociativity(1).ObjectView.Name)
partDimension.GetDimensionText(text1, text2)
Dim j As Integer
lw.WriteLine("Dimension Text: ")
For j = text1.GetLowerBound(0) To text1.GetUpperBound(0)
lw.WriteLine(" " & text1(j))
Next
manualTextCount += 1
lw.WriteLine("")
End If
Next
If manualTextCount > 0 Then
MsgBox(manualTextCount & " dimensions have manual text and have been changed to color: " & manualDimColor.ToString & " (" & colorName & ")")
Else
MsgBox("There are no dimensions with manual text in the part")
End If
Else
MsgBox("There are no dimensions in the work part")
End If

lw.Close()

End Sub

Sub ColorDim(ByRef theDim As Annotations.Dimension, ByVal theColor As Integer)

Dim objects1(0) As DisplayableObject
objects1(0) = theDim

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

With displayModification1
.ApplyToAllFaces = True
.ApplyToOwningParts = False
.NewColor = theColor
.Apply(objects1)
.Dispose()
End With

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

thank you very much
it's works very fine, I tested it on NX9.0.3 MP3 and NX10
thanks a lot

NX9