QQ登录

只需一步,快速开始

快捷登录

登录 或者 注册 请先

UG爱好者

查看: 2428|回复: 2
打印 上一主题 下一主题

[求助] UG工程图所有尺寸导出excel

[复制链接]

二级士官

Rank: 2

2

主题

46

帖子

477

积分
跳转到指定楼层
楼主
发表于 2019-2-16 08:55:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想把UG工程图中所有已标注的尺寸(含公差),形位公差等所有内容导出到excel中,大神有方法做到吗?

有奖推广贴子: 

回复

使用道具 举报

头像被屏蔽

禁止访问

0

主题

32

帖子

95

积分
沙发
发表于 2019-2-16 09:42:27 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

二级士官

Rank: 2

2

主题

46

帖子

477

积分
板凳
 楼主| 发表于 2019-2-18 22:33:03 | 只看该作者
代码如下:

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)
        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


运行后弹出错误:System.Runtime.InteropService.COMException:
头大
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

 
 
QQ:1359218528
工作时间:
9:00-17:00
 
微信公众号
手机APP
机械社区
微信小程序

手机版|UG爱好者论坛 ( 京ICP备10217105号-2 )    论坛管理员QQ:1359218528

本站信息均由会员发表,不代表本网站立场,如侵犯了您的权利请联系管理员,邮箱:1359218528@qq.com  

Powered by UG爱好者 X3.2  © 2001-2014 Comsenz Inc. GMT+8, 2024-4-26 23:25

返回顶部