- Sub main()
- Set swApp = Application.SldWorks
- Set Parts = swApp.ActiveDoc
- Set thisFeat = Parts.FirstFeature
- boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
- boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
- Parts.ClearSelection2 True
- boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
- Parts.Extension.Create3DBoundingBox
- Do While Not thisFeat Is Nothing
- If thisFeat.GetTypeName = "SolidBodyFolder" Then
- thisFeat.GetSpecificFeature2.UpdateCutList
- End If
- Set thisSubFeat = thisFeat.GetFirstSubFeature
- Do While Not thisSubFeat Is Nothing
- If thisSubFeat.GetTypeName = "CutListFolder" Then
- Set cutFolder = thisSubFeat.GetSpecificFeature2
- End If
- If Not cutFolder Is Nothing Then
- BodyCount = cutFolder.GetBodyCount
- If BodyCount > 0 Then
- Set custPrOPMgr = thisSubFeat.CustomPropertyManager
- If Not custPrOPMgr Is Nothing Then
- custPrOPMgr.Delete "Total Weight"
- custPrOPMgr.Delete "总重"
- custPrOPMgr.Delete "Weight"
- custPrOPMgr.Delete "材料"
- fn = thisSubFeat.Name
- pn = Parts.GetTitle
- custPrOPMgr.Add "单重", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
- custPrOPMgr.Add "重量", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
- custPrOPMgr.Add "材料", "文字", Chr(34) & "SW-Material@@@" & fn & "@" & pn & Chr(34)
- propNames = custPrOPMgr.GetNames
- If Not IsEmpty(propNames) Then
- For Each vName In propNames
- propName = vName
- custPrOPMgr.Get2 propName, Value, resolvedValue
- If propName = "重量" Then TotalW = resolvedValue
- Next vName
- End If
- custPrOPMgr.Add "总重", "文字", Format(BodyCount * TotalW, "0.00")
- custPrOPMgr.Add "名称", "文字", "钢板 ""SW-3D-边界框长度@@@""X""SW-3D-边界框宽度@@@""X""SW-3D-边界框厚度@@@"""
- End If
- End If
- End If
- Set thisSubFeat = thisSubFeat.GetNextSubFeature
- Loop
- Set thisFeat = thisFeat.GetNextFeature
- Loop
- End Sub
复制代码 可自动创建焊件的单重总重重量以及3D边界框和焊件中的钢板的名称尺寸长宽厚的链接
但是如果焊件中只有一个实体出错,总重If propName = "重量" Then TotalW = resolvedValue这句执行不下去
|