Submitted by iamfallen on Fri, 06/07/2013 - 07:35
Forums:
I am trying to select and highlight all dimensions on the current sheet that are of the basic tolerance type. Where am I going wrong in my thought process?
Dim workPart As Part = theSession.Parts.Work
Dim cnt As Integer = 0
Dim basicDim As Annotations.Dimension
For Each basicDim In workPart.Dimensions
Try
Dim aDim As Annotations.Dimension
aDim.ToleranceType As Annotations.ToleranceType.Basic = basicDim
basicDim.Highlight()
cnt = cnt + 1
Catch ex As Exception
End Try
Next
re: basic dimensions
The following code will highlight the basic dimensions and report how many were found. Note: the dimensions will not be selected, only highlighted. To remove the highlighting, do a part cleanup with the option "remove extraneous highlighting" checked.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
dim lw as listingwindow = theSession.listingwindow
lw.open
dim count as integer = 0
for each basicDim as annotations.dimension in workpart.dimensions
if basicDim.ToleranceType = Annotations.ToleranceType.Basic then
basicDim.highlight
count += 1
end if
next
lw.writeline(count.tostring & " basic dimensions found")
lw.close
End Sub
End Module
where can i get descriptions
where can i get descriptions ?
like want to know about annotations ? etc.
re: object model
You will find documentation on the NX object model in the NX help files. The exact location will depend on your version of NX.
For NX 8, assuming the help files including the NXOpen API help files are installed, it can be found at: Programming tools -> NX Open -> Open for .NET -> NX Open for .net reference guide.
On this page you will have to click a link to download the compiled help file to your local harddrive (due to security restrictions in Windows). Find the newly downloaded file (.net_ref.chm) and double click it to open. Start browsing the contents or use the search tab to find an item of interest.
Making changes while highlighting
This is what I worked out for making changes to the basic dimensions while highlighting and counting. The section removing trailing zeros works fine when ran. The section to change the number of places displayed does not and I am not sure why.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim count as Integer = 0
For each basicDim As annotations.dimension in workpart.dimensions
If basicDim.ToleranceType = Annotations.ToleranceType.Basic Then
Dim basicTol As Annotations.LinearTolerance
basicTol = basicDim.GetTolerance()
basicTol.PrimaryDimensionDecimalPlaces = 3
basicDim.SetTolerance(basicTol)
'Remove Trailing Zeros
Dim basicDimPref As Annotations.DimensionPreferences
basicDimPref = basicDim.GetDimensionPreferences()
Dim basicFormat As Annotations.UnitsFormatPreferences
basicFormat = basicDimPref.GetUnitsFormatPreferences()
basicFormat.DisplayTrailingZeros = False
basicDimPref.SetUnitsFormatPreferences(basicFormat)
basicDim.SetDimensionPreferences(basicDimPref)
basicDim.highlight
count += 1
End If
Next
UI.GetUI().NXMessageBox.Show("Basic Dimensions", _
NXMessageBox.DialogType.Information, _
" These " & count.tostring & " dimensions are Basic and have been converted to 3 places with no trailing zeros")
Dim pc As PartCleanup = theSession.NewPartCleanup
pc.TurnOffHighlighting = True
pc.DoCleanup()
pc.Dispose()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
re: dimension decimal places
The variable basicDim is of type Annotations.Dimension which does not have the method .GetTolerance(). The child classes that derive from Annotations.Dimension, such as BaseHorizontalDimension, do have the method .GetTolerance(). You could try testing the dimension's type, casting it to the proper subtype, then access the .GetTolerance() method; this would require a select case block or several if blocks to test for each dimension subtype.
An alternative would be to use a UF function that would operate on any given dimension type. These functions are not usually consistent with the .NET object model, nor are they as user friendly or self-documenting, but you can still use them as needed. This is a case that might benefit from a UF function.
Option Strict Off
Imports System
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
Dim displayPart As Part = theSession.Parts.Display
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
theSession.ListingWindow.Close()
End Sub
Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim count As Integer = 0
For Each basicDim As annotations.dimension In workpart.dimensions
If basicDim.ToleranceType = Annotations.ToleranceType.Basic Then
'create variables to hold dimension information
Dim mpi(99) As Integer
Dim mpr(69) As Double
Dim radius_val As String
Dim diameter_val As String
'ask the dimension information of our selected dimension
theUfSession.Drf.AskObjectPreferences(basicDim.Tag, mpi, mpr, radius_val, diameter_val)
'change decimal places to 3
mpi(3) = 3
'update the dimension to our desired preferences
theUfSession.Drf.SetObjectPreferences(basicDim.Tag, mpi, mpr, radius_val, diameter_val)
'Remove Trailing Zeros
Dim basicDimPref As Annotations.DimensionPreferences
basicDimPref = basicDim.GetDimensionPreferences()
Dim basicFormat As Annotations.UnitsFormatPreferences
basicFormat = basicDimPref.GetUnitsFormatPreferences()
basicFormat.DisplayTrailingZeros = False
basicDimPref.SetUnitsFormatPreferences(basicFormat)
basicDim.SetDimensionPreferences(basicDimPref)
basicDim.highlight()
count += 1
End If
Next
UI.GetUI().NXMessageBox.Show("Basic Dimensions", _
NXMessageBox.DialogType.Information, _
" These " & count.tostring & " dimensions are Basic and have been converted to 3 places with no trailing zeros")
Dim pc As PartCleanup = theSession.NewPartCleanup
pc.TurnOffHighlighting = True
pc.DoCleanup()
pc.Dispose()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
Does anyone know how to
Does anyone know how to select surface roughness annotations and "drawing feature control frames"? They don't seem to be the same data type as Annotations.Dimension.
re: feature control frames
You can access all of the feature control frames by using the part's .Gdts collection.
Thank you... can you point me
Thank you... can you point me to how I can access and use that collection?
re: feature control frames
The code below will look through the current work part's .Gdts collection and display the FCF's primary datum reference and characteristic on the information window.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "report feature control frames"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
For Each temp As Annotations.Gdt In workPart.Gdts
'lw.WriteLine("type: " & temp.GetType.ToString)
If TypeOf (temp) Is Annotations.DraftingFcf Then
Dim fcfBuilder As Annotations.DraftingFeatureControlFrameBuilder
fcfBuilder = workPart.Annotations.CreateDraftingFeatureControlFrameBuilder(temp)
Dim featureControlFrameDataBuilder1 As Annotations.FeatureControlFrameDataBuilder = fcfBuilder.FeatureControlFrameDataList.FindItem(0)
lw.WriteLine("Primary datum reference: " & featureControlFrameDataBuilder1.PrimaryDatumReference.Letter)
lw.WriteLine(fcfBuilder.Characteristic.ToString)
fcfBuilder.Destroy()
lw.WriteLine("")
End If
Next
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
Thanks! Should I also be
Thanks! Should I also be using Gdts collection to extract the tolerance value and the tolerance zone shape?
re: tolerance value and zone shape
Building on the previous code, this journal will also report the tolerance value and zone shape of the drafting FCF's in the part file. Note this is only for the drafting FCF's, if you are using PMI annotations, you will need to query the PMI and/or FCF collections.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UF
Module Module2
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "report feature control frames"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
For Each temp As Gdt In workPart.Gdts
If Not TypeOf (temp) Is Annotations.DraftingFcf Then
lw.WriteLine("")
Continue For
End If
Dim fcfBuilder As Annotations.DraftingFeatureControlFrameBuilder
fcfBuilder = workPart.Annotations.CreateDraftingFeatureControlFrameBuilder(temp)
Dim featureControlFrameDataBuilder1 As Annotations.FeatureControlFrameDataBuilder = fcfBuilder.FeatureControlFrameDataList.FindItem(0)
lw.WriteLine("Primary datum reference: " & featureControlFrameDataBuilder1.PrimaryDatumReference.Letter)
lw.WriteLine(fcfBuilder.Characteristic.ToString)
lw.WriteLine("Zone shape: " & featureControlFrameDataBuilder1.ZoneShape.ToString)
lw.WriteLine("Tolerance value: " & featureControlFrameDataBuilder1.ToleranceValue)
fcfBuilder.Destroy()
lw.WriteLine("")
Next
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
I'm trying to also export
I'm trying to also export surface features, but I seem to have the wrong class for workPart. Does anyone know what class I should use and what value I should look to output?
'Export surface features
For Each mysurface As Annotations.DraftingSurfaceFinish in workPart.Markers 'DraftingViews
Dim finishBuilder As Annotations.DraftingSurfaceFinishBuilder
finishBuilder = workPart.Annotations.DraftingSurfaceFinishSymbols.CreateDraftingSurfaceFinishBuilder(mysurface)
objExcel.Cells(row, 1) = finishBuilder.A2
Next