前段时间在在Autodesk Inventor论坛解答了一个问题,觉得对钣金操作的开发者有用,现总结于此。
钣金里折弯是很常用的特征。而折弯基于基准面方向,可能向上,也可能向下。而实际生产中,需要知道哪些折弯向上,哪些向下。API提供的相关方法FlatBendResult.IsDirectionUp 可以解决。以下VBA代码假定当前激活的是一个钣金文档,它将进行统计,并弹出消息。
Public Sub GetBendResults()
'获取当前文档
Dim oPartDoc As PartDocument
oPartDoc = _InvApplication.ActiveDocument
'判断是否是钣金文档
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
MsgBox("必须打开钣金文档!")
Exit Sub
End If
'获取钣金文档定义
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
oSheetMetalCompDef = oPartDoc.ComponentDefinition
'如果还没有展开,则调用Unfold创建展开
If (Not oSheetMetalCompDef.HasFlatPattern) Then
oSheetMetalCompDef.Unfold()
End If
‘获取展开
Dim oFlatPattern As FlatPattern
oFlatPattern = oSheetMetalCompDef.FlatPattern
’遍历展开折弯结果对象
Dim oBendResult As FlatBendResult
For Each oBendResult In oFlatPattern.FlatBendResults
‘ 折弯的内部名
Dim strResult As String
strResult = "Internal Name: " & oBendResult.InternalName & ", "
’折弯在底面还是顶面
If oBendResult.IsOnBottomFace Then
strResult = strResult & "On Bottom, "
Else
strResult = strResult & "On Top, "
End If
‘折弯角度,并考虑了用缺省角度单位制
strResult = strResult & "Angle: " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetS
tringFromValue(oBendResult.Angle, UnitsTypeEnum.kDefaultDisplayAngleUnits) & ", "
‘折弯半径,并考虑了用缺省长度单位制
strResult = strResult & "Inner Radius: " & _InvApplication.ActiveDocument.UnitsOfMeasure.GetS
tringFromValue(oBendResult.InnerRadius, UnitsTypeEnum.kDefaultDisplayLengthUnits) & ", "
’折弯方向,向上还是向下
If oBendResult.IsDirectionUp Then
strResult = strResult & "Bend Direction: " & "Bend Up"
Else
strResult = strResult & "Bend Direction: " & "Bend Down"
End If
‘在调试窗口打印出以上信息
Debug.Print(strResult)
Next
End Sub