Inventor中工作点导出到excel
来源:互联网 发布:java获取json对象的值 编辑:程序博客网 时间:2024/06/05 18:26
一位顾客在零件中创建了许多工作点,然后客户需要一个Excel文件,包含这些工作点的坐标。下面的一个VBA宏,将创建一个CSV文件,其中包含了零件中工作点的坐标。如果您在运行宏之前选择了一部分工作点,那么这个宏将出现一个选项,提示您只会输出已经选定的工作点或输出所有的工作点。如果没有选定的工作点,那么它会导出所有的工作点。
这个宏开始并没有考虑到单位问题,因为Inventor的默认单位是CM,而不是MM,所以输出的尺寸是不正确的,下面是更新。
更新:自从我第一次发布这篇文章,我收到了有关宏程序如何使用的文件的当前单位的问题。我已经修改了下面的代码。在此之前,它是使用内部厘米的长度单位。它现在使用的文件中指定的长度,但它忽略了文件中指定的小数点后数字的数量,总是写入多达8位小数。
程序如下:
Public Sub ExportWorkPoints()
' Get the active part document.
Dim partDocAs PartDocument
IfThisApplication.ActiveDocumentType = kPartDocumentObject Then
Set partDoc = ThisApplication.ActiveDocument
Else
MsgBox "A part must be active."
Exit Sub
End If
' Check to see if any work points areselected.
Dim points()As WorkPoint
DimpointCount As Long
pointCount =0
IfpartDoc.SelectSet.Count > 0 Then
' Dimension the array so it can contain the full
' list of selected items.
ReDim points(partDoc.SelectSet.Count - 1)
Dim selectedObj As Object
For Each selectedObj In partDoc.SelectSet
If TypeOf selectedObj Is WorkPoint Then
Set points(pointCount) = selectedObj
pointCount = pointCount + 1
End If
Next
ReDim Preserve points(pointCount - 1)
End If
' Ask to see if it should operate on the selected points
' or allpoints.
DimgetAllPoints As Boolean
getAllPoints= True
IfpointCount > 0 Then
Dim result As VbMsgBoxResult
result = MsgBox("Some work points are selected. "& _
"Do you want to export only the " & _
"selected work points? (Answering "& _
"""No"" will export all work points)", _
vbQuestion + vbYesNoCancel)
If result = vbCancel Then