Submitted by dwang953 on Mon, 06/15/2015 - 10:15
Forums:
I'm trying to extract the type for each dimension in a drawing. For example, the types below are defined in DimensionCollection:
namespace Annotations
{
class ArcLengthDimension;
}
namespace Annotations
{
class Associativity;
}
namespace Annotations
{
class ChamferDimension;
}
namespace Annotations
{
class ConcentricCircleDimension;
}
How can I iterate through each of the dimensions in a part and print out the type (i.e. radius dimension, arc length dimension) in a nice format in Excel?
re: dimension type
The following code will write the type of each dimension in the work part to 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 dimension type"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
For Each tempDim As Annotations.Dimension In workPart.Dimensions
lw.WriteLine(tempDim.GetType.ToString)
Next
lw.Close()
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
Thank you! Can you let me
Thank you! Can you let me know where I can go to find classes like GetType? I was looking in NXOpen.DimensionCollection and NXOpen.Dimension but I did not see classes like that.
re: dimension classes
Go to the "Dimension" class documentation page and scroll to the bottom. You'll see an "inheritance hierarchy" that lists all of the dimension types derived from the "Dimension" class.
GetType
The GetType function is part of the .NET framework; it's not an NX/Open function. You can apply it to any object in a VB or C# program. An Annotations.Dimension object inherits this function from the top-level .NET "Object" type. It actually returns a System.Type object, and then ToString gives you the name of that Type (which is usually what you want).