NX批量导出图纸尺寸和公差至表格

	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"    '这里更改为你自己的表格路径
    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

    'open Excel file
    Dim objWorkbook = objExcel.Workbooks.Open(excelFileName)
    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) '写入尺寸名义值
		objExcel.Cells(row, column+1) = myDimension.UpperMetricToleranceValue ()'写入公差上偏差
		objExcel.Cells(row, column+1) = myDimText(0).LowerMetricToleranceValue ()'写入公差下偏差

    Next

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

    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

    '----Other unload options-------
    'Unloads the image immediately after execution within NX
    'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    'Unloads the image explicitly, via an unload dialog
    'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
    '-------------------------------

	End Function

	End Module
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值