如何统计钣金文档中向上和向下折弯的个数

前段时间在在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值