cancel
Showing results for 
Search instead for 
Did you mean: 

2D Drawing dimension extract

Experimenter
Experimenter

Hi All,

Can anyone help me to find a way to extract the dimensions from the 2D drawing and plot it into xls sheet (basically looking for the code).

Thanks in advance,

 

2 REPLIES

Re: 2D Drawing dimension extract

Honored Contributor
Honored Contributor

Below is some code that will export the drawing dimensions out to an Excel file. The code could use some work, but it shows the basics.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUISession As UI = UI.GetUI
        Dim workPart As Part = theSession.Parts.Work

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")

        'change excelFileName to meet your needs
        Const excelFileName As String = "C:\Temp\part_dimensions.xlsm"
        Const xlUp As Integer = -4162
        Dim row As Long = 1
        Dim column As Long = 1

        'create Excel object
        Dim objExcel = CreateObject("Excel.Application")
        If objExcel Is Nothing Then
            theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
            theSession.UndoToMark(markId1, "journal")
            Exit Sub
        End If

        'add new worksheet to Excel
        Dim objWorkbook = objExcel.Workbooks.Add
        If objWorkbook Is Nothing Then
            theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & excelFileName & ControlChars.NewLine & "journal exiting.")
            theSession.UndoToMark(markId1, "journal")
            Exit Sub
        End If

        objExcel.visible = True

        objExcel.Cells(row, 1) = workPart.FullPath

        Dim myDimText() As String
        Dim myDimDualText() As String
        For Each myDimension As Annotations.Dimension In workPart.Dimensions
            row += 1
            myDimension.GetDimensionText(myDimText, myDimDualText)
            objExcel.Cells(row, column) = myDimText(0)
        Next

        'objExcel.Quit()
        objWorkbook = Nothing
        objExcel = Nothing

        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

Re: 2D Drawing dimension extract

Experimenter
Experimenter

Thank you Cowski :-)