- Dim doc As PartDocument = ThisDoc.Document '零件PartDocument, 部件AssemblyDocument。
- oCompDef = doc.ComponentDefinition
- Dim oparams As Parameters = oCompDef.Parameters
- Dim oparam As Parameter
- Dim oPt1 As Point, oPt2 As Point
- oPt1 = oCompDef.RangeBox.MaxPoint
- oPt2 = oCompDef.RangeBox.MinPoint
- Dim X As Double, Y As Double, Z As Double
- X = Abs(oPt1.X - oPt2.X)
- Y = Abs(oPt1.Y - oPt2.Y)
- Z = Abs(oPt1.Z - oPt2.Z)
- For Each oparam In oparams
- If oparam.Name = "长" Then exists = True
- If oparam.Name = "宽" Then exists1 = True
- If oparam.Name = "高" Then exists2 = True
- Next oparam
- If exists Then
- oparams.Item("长").Value = Round(X,1) '参阅Round函数
- Else
- oparams.UserParameters.AddByValue("长",Round(X,1) , "mm")
- End If
- If exists1 Then
- oparams.Item("宽").Value = Round(Y,1)
- Else
- oparams.UserParameters.AddByValue("宽", Round(Y,1) , "mm")
- End If
- If exists2 Then
- oparams.Item("高").Value =Round(Z,1)
- Else
- oparams.UserParameters.AddByValue("高", Round(Z,1) , "mm") End If
复制代码 |