SolidWorks机械工程师网——最大的SolidWorks学习平台

标题: 有关在solidworks2018中使用3D边界框链接焊接钢板的外廊尺寸问题 [打印本页]

作者: madeyeye    时间: 2019-11-25 13:29
标题: 有关在solidworks2018中使用3D边界框链接焊接钢板的外廊尺寸问题



如上图所示,试过了很多遍
钢板 "SW-3D-边界框长度@@@"X"SW-3D-边界框宽度@@@"X"SW-3D-边界框厚度@@@"
这段在SOLIDWORKS2016中是可以使用的,但是在solidworks2018里就无法出来结果。
求知道的朋友告知一下这里如何适应2018的。
作者: azhen001    时间: 2019-11-25 16:26
没有人遇到过吗?
作者: nayven    时间: 2019-11-25 16:26
没有人遇到过吗?
作者: kawayijoe    时间: 2019-11-25 17:00
在solidworks2018中使用下面这段才能生效solidworks网,必须顶一下
钢板 "SW-3D-边界框长度@@""X"SW-3D-边界框宽度@@""X"SW-3D-边界框厚度@@""
作者: torance    时间: 2019-11-25 17:01
custPrOPMgr.Add "名称", "文字", "钢板""SW-3D-边界框长度@@@""X""SW-3D-边界框宽度@@@""X""SW-3D-边界框厚度@@@"""
但是这段代码不知道如何修正才能自动添加上面那段属性
作者: jwyjwy    时间: 2019-11-25 17:01
custPrOPMgr.Add "名称", "文字", "钢板""SW-3D-边界框长度@@@""X""SW-3D-边界框宽度@@@""X""SW-3D-边界框厚度@@@"""
但是这段代码不知道如何修正才能自动添加上面那段属性
作者: doudoule1981    时间: 2019-11-25 20:18
如果用宏程序,可用下面一句:
注意:swFeat.name:为特征名;
FileName:文件名
swCustPropMgr.Add3 "备注", swCustomInfoType_e.swCustomInfoText, _
  """SW-3D-边界框长度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框宽度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框厚度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
作者: zzz021    时间: 2019-11-26 09:19
来学习学习
作者: zzky760    时间: 2019-11-26 09:19
来学习学习
作者: moja1453    时间: 2019-11-26 09:45
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim thisFeat As SldWorks.Feature
Dim thisSubFeat As SldWorks.Feature
Dim cutFolder As Object
Dim BodyCount As Integer
Dim fn As String
Dim pn As String
Dim custPrOPMgr As SldWorks.CustomPropertyManager
Dim propNames As Variant
Dim vName As Variant
Dim propName As String
Dim Value As String
Dim resolvedValue As String
Dim TotalW As Double
Dim Parts As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swFeat As Feature
Dim FileName As String
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.Add3 "名称", "文字", "钢板""""SW-3D-边界框长度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""" & "x""" & "SW-3D-边界框宽度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""" & "x""" & "SW-3D-边界框厚度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  End If
  End If
End If
Set thisSubFeat = thisSubFeat.GetNextSubFeature
Loop
Set thisFeat = thisFeat.GetNextFeature
Loop
End Sub
复制代码
修改后,提示运行时13错误,调试了之后还是没有解决,请大神帮忙看看问题出在哪里?
作者: asdfg0914    时间: 2019-11-26 09:45
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim thisFeat As SldWorks.Feature
Dim thisSubFeat As SldWorks.Feature
Dim cutFolder As Object
Dim BodyCount As Integer
Dim fn As String
Dim pn As String
Dim custPrOPMgr As SldWorks.CustomPropertyManager
Dim propNames As Variant
Dim vName As Variant
Dim propName As String
Dim Value As String
Dim resolvedValue As String
Dim TotalW As Double
Dim Parts As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swFeat As Feature
Dim FileName As String
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.Add3 "名称", "文字", "钢板""""SW-3D-边界框长度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""" & "x""" & "SW-3D-边界框宽度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""" & "x""" & "SW-3D-边界框厚度@@@" & swFeat.Name & "@" & FileName & ".SLDPRT""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  End If
  End If
End If
Set thisSubFeat = thisSubFeat.GetNextSubFeature
Loop
Set thisFeat = thisFeat.GetNextFeature
Loop
End Sub
复制代码
修改后,提示运行时13错误,调试了之后还是没有解决,请大神帮忙看看问题出在哪里?
作者: yoyoo1978    时间: 2019-11-26 11:37
'?ú????????и??嵥??????д?Щ???????????????????????????????Щ?й???????
'?硰????????и??嵥???????????????"????"???SW-Mass???????
'?硰?????????QUANTITY???????"????"???SW-Mass???????
'???????????????????????????????????????????ò?????д??????????????
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim names As Variant '???????????????
Dim bRet As Boolean
Dim evalval As String
Dim featureName As String
Dim boolstatus As Boolean
Dim opt As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' ????????????
Set swFeat = swModel.FirstFeature
Dim FileName As String
Dim name As String'????????
Dim textexp As String
Dim evalval As String
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
Do While Not swFeat Is Nothing
If swFeat Is Nothing Then
  Exit Do
End If
featureName = swFeat.name
If swFeat.GetTypeName2 = "CutListFolder" Then
  boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  Set swCustPropMgr = swFeat.CustomPropertyManager
  names = swCustPropMgr.GetNames
  name = Join(names, " ") '???????????????????????
  
  
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swCustPropMgr.Add3 "????????", swCustomInfoType_e.swCustomInfoText, _
  "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  If InStr(1, name, "????") <= 0 Then '?ж????????
  
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swModelDocExt.Create3DBoundingBox '????????
  
  swCustPropMgr.Add3 "???", swCustomInfoType_e.swCustomInfoText, _
  """SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  Else
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '???????????DESCRIPTION?????
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '???????DESCRIPTION???????д???????????????
  
  End If
End If
'Debug.Print swFeat.GetTypeName2
Set swFeat = swFeat.GetNextFeature
Loop
bRet = swModel.ForceRebuild3(False)
MsgBox "???"
End Sub
复制代码
这是我编写的一个给焊件填写属性的宏程序,你可参考一下:
作者: mydym520    时间: 2019-11-26 11:37
'?ú????????и??嵥??????д?Щ???????????????????????????????Щ?й???????
'?硰????????и??嵥???????????????"????"???SW-Mass???????
'?硰?????????QUANTITY???????"????"???SW-Mass???????
'???????????????????????????????????????????ò?????д??????????????
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim names As Variant '???????????????
Dim bRet As Boolean
Dim evalval As String
Dim featureName As String
Dim boolstatus As Boolean
Dim opt As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' ????????????
Set swFeat = swModel.FirstFeature
Dim FileName As String
Dim name As String'????????
Dim textexp As String
Dim evalval As String
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
Do While Not swFeat Is Nothing
If swFeat Is Nothing Then
  Exit Do
End If
featureName = swFeat.name
If swFeat.GetTypeName2 = "CutListFolder" Then
  boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  Set swCustPropMgr = swFeat.CustomPropertyManager
  names = swCustPropMgr.GetNames
  name = Join(names, " ") '???????????????????????
  
  
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swCustPropMgr.Add3 "????????", swCustomInfoType_e.swCustomInfoText, _
  "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  If InStr(1, name, "????") <= 0 Then '?ж????????
  
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swModelDocExt.Create3DBoundingBox '????????
  
  swCustPropMgr.Add3 "???", swCustomInfoType_e.swCustomInfoText, _
  """SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  Else
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '???????????DESCRIPTION?????
  swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '???????DESCRIPTION???????д???????????????
  
  End If
End If
'Debug.Print swFeat.GetTypeName2
Set swFeat = swFeat.GetNextFeature
Loop
bRet = swModel.ForceRebuild3(False)
MsgBox "???"
End Sub
复制代码
这是我编写的一个给焊件填写属性的宏程序,你可参考一下:
作者: w2626146    时间: 2019-11-26 11:40
好好的文件,怎么成了乱码?
作者: yunfeiyang518    时间: 2019-11-26 11:40
好好的文件,怎么成了乱码?
作者: ringfinger    时间: 2019-11-26 11:46
'该宏可为焊件切割清单属性填写一些通过其它方式获取的属性(也就是和其它一些有关联),
'如“名称”和切割清单某个项目名称相同;"单重"和“SW-Mass”相同;
'如“数量”和“QUANTITY”相同;
'对于板材件,增加一项“备注”,并获取平板的边界框参数,将该参数填写进“备注”项目中
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim names As Variant '属性名称数组变体
Dim bRet As Boolean
Dim evalval As String
Dim featureName As String
Dim boolstatus As Boolean
Dim opt As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' 获取第一个特征
Set swFeat = swModel.FirstFeature
Dim FileName As String
Dim name As String'属性名称
Dim textexp As String
Dim evalval As String
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
Do While Not swFeat Is Nothing
If swFeat Is Nothing Then
  Exit Do
End If
featureName = swFeat.name
If swFeat.GetTypeName2 = "CutListFolder" Then
  boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  Set swCustPropMgr = swFeat.CustomPropertyManager
  names = swCustPropMgr.GetNames
  name = Join(names, " ") '将数组转变为用空格隔开的字符串
  
  
  swCustPropMgr.Add3 "名称", swCustomInfoType_e.swCustomInfoText, _
  """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  swCustPropMgr.Add3 "单重", swCustomInfoType_e.swCustomInfoText, _
  """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  swCustPropMgr.Add3 "数量", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swCustPropMgr.Add3 "所属装配号", swCustomInfoType_e.swCustomInfoText, _
  "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  If InStr(1, name, "长度") <= 0 Then '判断是否为板材
  
  swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swModelDocExt.Create3DBoundingBox '创建边界框
  
  swCustPropMgr.Add3 "备注", swCustomInfoType_e.swCustomInfoText, _
  """SW-3D-边界框长度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框宽度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框厚度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  Else
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '如果为型材,获取DESCRIPTION属性值
  swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '将获取的DESCRIPTION属性值填写到“材料”属性中
  
  End If
End If
'Debug.Print swFeat.GetTypeName2
Set swFeat = swFeat.GetNextFeature
Loop
bRet = swModel.ForceRebuild3(False)
MsgBox "完成"
End Sub
复制代码
转到记事本,重新复制一下,又好了!
作者: moon1189    时间: 2019-11-26 11:46
'该宏可为焊件切割清单属性填写一些通过其它方式获取的属性(也就是和其它一些有关联),
'如“名称”和切割清单某个项目名称相同;"单重"和“SW-Mass”相同;
'如“数量”和“QUANTITY”相同;
'对于板材件,增加一项“备注”,并获取平板的边界框参数,将该参数填写进“备注”项目中
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim names As Variant '属性名称数组变体
Dim bRet As Boolean
Dim evalval As String
Dim featureName As String
Dim boolstatus As Boolean
Dim opt As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' 获取第一个特征
Set swFeat = swModel.FirstFeature
Dim FileName As String
Dim name As String'属性名称
Dim textexp As String
Dim evalval As String
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
Do While Not swFeat Is Nothing
If swFeat Is Nothing Then
  Exit Do
End If
featureName = swFeat.name
If swFeat.GetTypeName2 = "CutListFolder" Then
  boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  Set swCustPropMgr = swFeat.CustomPropertyManager
  names = swCustPropMgr.GetNames
  name = Join(names, " ") '将数组转变为用空格隔开的字符串
  
  
  swCustPropMgr.Add3 "名称", swCustomInfoType_e.swCustomInfoText, _
  """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  swCustPropMgr.Add3 "单重", swCustomInfoType_e.swCustomInfoText, _
  """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  swCustPropMgr.Add3 "数量", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swCustPropMgr.Add3 "所属装配号", swCustomInfoType_e.swCustomInfoText, _
  "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  If InStr(1, name, "长度") <= 0 Then '判断是否为板材
  
  swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  swModelDocExt.Create3DBoundingBox '创建边界框
  
  swCustPropMgr.Add3 "备注", swCustomInfoType_e.swCustomInfoText, _
  """SW-3D-边界框长度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框宽度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  & "x""" & "SW-3D-边界框厚度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  
  Else
  swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '如果为型材,获取DESCRIPTION属性值
  swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '将获取的DESCRIPTION属性值填写到“材料”属性中
  
  End If
End If
'Debug.Print swFeat.GetTypeName2
Set swFeat = swFeat.GetNextFeature
Loop
bRet = swModel.ForceRebuild3(False)
MsgBox "完成"
End Sub
复制代码
转到记事本,重新复制一下,又好了!
作者: kingwuyi    时间: 2019-11-26 14:16



作者: daegun    时间: 2019-11-26 14:39
哦,明白了你使用的方式了,
可能是应用环境不同,我这个焊接材料清单是需要直接体现所用的材料给采购,
具体使用在哪里目前还没有这样的要求。
谢谢你的开阔了我的眼界。
作者: yhswolf    时间: 2019-11-26 15:23
程序在运行前,将原来所创建的边界框删除,否则程序会判断失误!
作者: aiwei96    时间: 2019-11-26 15:26
像你这样,将名称赋予材料规格,一般少见!一般是在材料栏,填写材料规格!
作者: qiaozi    时间: 2019-11-26 15:34



这是我做的焊件明细表
作者: tanddsn    时间: 2019-11-27 14:04
今天不知道怎么回事,怎么论坛上的图片都成了空白的,什么都看不到了,大家也是这样的情况吗?
作者: sunnyeric    时间: 2020-4-14 08:31
型材规格之后要标记不同材质的,我这种表格要方便些
作者: 懒懒的高贵    时间: 2022-8-4 16:03
很不错,顶一下!




欢迎光临 SolidWorks机械工程师网——最大的SolidWorks学习平台 (https://www.swbbsc.com/) Powered by Discuz! X3.2