找回密码 注册 QQ登录
一站式解决方案

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 3647|回复: 19
打印 上一主题 下一主题

[求助] 有关在solidworks2018中使用3D边界框链接焊接钢板的外廊尺寸问题

[复制链接]
跳转到指定楼层
1
发表于 2019-11-25 13:29:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 linkral 于 2019-11-27 14:02 编辑


如上图所示,试过了很多遍
钢板 "SW-3D-边界框长度@@@"X"SW-3D-边界框宽度@@@"X"SW-3D-边界框厚度@@@"

这段在SOLIDWORKS2016中是可以使用的,但是在solidworks2018里就无法出来结果。
求知道的朋友告知一下这里如何适应2018的。



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!1
2
发表于 2019-11-25 16:26:15 | 只看该作者
没有人遇到过吗?
3
发表于 2019-11-25 17:00:16 | 只看该作者
在solidworks2018中使用下面这段才能生效
钢板 "SW-3D-边界框长度@@""X"SW-3D-边界框宽度@@""X"SW-3D-边界框厚度@@""
4
发表于 2019-11-25 17:01:39 | 只看该作者
custPrOPMgr.Add "名称", "文字", "钢板""SW-3D-边界框长度@@@""X""SW-3D-边界框宽度@@@""X""SW-3D-边界框厚度@@@"""

但是这段代码不知道如何修正才能自动添加上面那段属性
5
发表于 2019-11-25 20:18:39 | 只看该作者
本帖最后由 三维专家 于 2019-11-25 20:23 编辑

如果用宏程序,可用下面一句:
注意: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
6
发表于 2019-11-26 09:19:24 | 只看该作者
来学习学习
7
发表于 2019-11-26 09:45:20 | 只看该作者
三维专家 发表于 2019-11-25 20:18
如果用宏程序,可用下面一句:
注意:swFeat.name:为特征名;
         FileName:文件名[/ ...
  1. Option Explicit
  2. Dim swApp As SldWorks.SldWorks
  3. Dim Part As SldWorks.ModelDoc2
  4. Dim thisFeat As SldWorks.Feature
  5. Dim thisSubFeat As SldWorks.Feature
  6. Dim cutFolder As Object
  7. Dim BodyCount As Integer
  8. Dim fn As String
  9. Dim pn As String
  10. Dim custPrOPMgr As SldWorks.CustomPropertyManager
  11. Dim propNames As Variant
  12. Dim vName As Variant
  13. Dim propName As String
  14. Dim Value As String
  15. Dim resolvedValue As String
  16. Dim TotalW As Double
  17. Dim Parts As Object
  18. Dim boolstatus As Boolean
  19. Dim longstatus As Long, longwarnings As Long
  20. Dim swFeat As Feature
  21. Dim FileName As String

  22. Sub main()
  23. Set swApp = Application.SldWorks
  24. Set Parts = swApp.ActiveDoc
  25. Set thisFeat = Parts.FirstFeature
  26. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  27. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  28. Parts.ClearSelection2 True
  29. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  30. Parts.Extension.Create3DBoundingBox

  31. Do While Not thisFeat Is Nothing
  32.     If thisFeat.GetTypeName = "SolidBodyFolder" Then
  33.         thisFeat.GetSpecificFeature2.UpdateCutList
  34.     End If
  35.     Set thisSubFeat = thisFeat.GetFirstSubFeature
  36.     Do While Not thisSubFeat Is Nothing
  37.         If thisSubFeat.GetTypeName = "CutListFolder" Then
  38.             Set cutFolder = thisSubFeat.GetSpecificFeature2
  39.         End If
  40.         If Not cutFolder Is Nothing Then
  41.             BodyCount = cutFolder.GetBodyCount
  42.             If BodyCount > 0 Then
  43.                 Set custPrOPMgr = thisSubFeat.CustomPropertyManager
  44.                 If Not custPrOPMgr Is Nothing Then
  45.                     custPrOPMgr.Delete "Total Weight"
  46.                     custPrOPMgr.Delete "总重"
  47.                     custPrOPMgr.Delete "Weight"
  48.                     custPrOPMgr.Delete "材料"
  49.                     fn = thisSubFeat.Name
  50.                     pn = Parts.GetTitle
  51.                     custPrOPMgr.Add "单重", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
  52.                     custPrOPMgr.Add "重量", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
  53.                     custPrOPMgr.Add "材料", "文字", Chr(34) & "SW-Material@@@" & fn & "@" & pn & Chr(34)
  54.                     propNames = custPrOPMgr.GetNames
  55.                     If Not IsEmpty(propNames) Then
  56.                         For Each vName In propNames
  57.                             propName = vName
  58.                             custPrOPMgr.Get2 propName, Value, resolvedValue
  59.                             If propName = "重量" Then TotalW = resolvedValue
  60.                         Next vName
  61.                     End If
  62.                     custPrOPMgr.Add "总重", "文字", Format(BodyCount * TotalW, "0.00")
  63.                     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
  64.                 End If
  65.             End If
  66.         End If
  67.         Set thisSubFeat = thisSubFeat.GetNextSubFeature
  68.     Loop
  69.     Set thisFeat = thisFeat.GetNextFeature
  70. Loop
  71. End Sub
复制代码
修改后,提示运行时13错误,调试了之后还是没有解决,请大神帮忙看看问题出在哪里?

8
发表于 2019-11-26 11:37:42 | 只看该作者
本帖最后由 三维专家 于 2019-11-26 11:39 编辑
  1. '?ú????????и??嵥??????д?Щ???????????????????????????????Щ?й???????
  2. '?硰????????и??嵥???????????????"????"???SW-Mass???????
  3. '?硰?????????QUANTITY???????"????"???SW-Mass???????
  4. '???????????????????????????????????????????ò?????д??????????????

  5. Option Explicit

  6. Dim swApp As SldWorks.SldWorks
  7. Dim swModel As SldWorks.ModelDoc2
  8. Dim swModelDocExt As SldWorks.ModelDocExtension
  9. Dim swFeat As SldWorks.Feature

  10. Dim swCustPropMgr As SldWorks.CustomPropertyManager
  11. Dim names As Variant '???????????????
  12. Dim bRet As Boolean
  13. Dim evalval As String
  14. Dim featureName As String
  15. Dim boolstatus As Boolean
  16. Dim opt As Long

  17. Sub main()
  18.     Set swApp = Application.SldWorks
  19.     Set swModel = swApp.ActiveDoc
  20.     Set swModelDocExt = swModel.Extension
  21.    
  22.     ' ????????????
  23.     Set swFeat = swModel.FirstFeature
  24.    
  25.     Dim FileName As String
  26.     Dim name As String      '????????
  27.     Dim textexp As String
  28.     Dim evalval As String
  29.    
  30.     FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
  31.    
  32.    
  33.     Do While Not swFeat Is Nothing
  34.         If swFeat Is Nothing Then
  35.             Exit Do
  36.         End If
  37.         featureName = swFeat.name
  38.         If swFeat.GetTypeName2 = "CutListFolder" Then
  39.             boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  40.             Set swCustPropMgr = swFeat.CustomPropertyManager
  41.             names = swCustPropMgr.GetNames
  42.             name = Join(names, " ") '???????????????????????
  43.             
  44.             
  45.             swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  46.                 """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  47.             
  48.             
  49.             swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  50.             swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  51.                 """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  52.             
  53.             swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  54.             swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  55.                 textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  56.             swCustPropMgr.Add3 "????????", swCustomInfoType_e.swCustomInfoText, _
  57.                 "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  58.             
  59.             If InStr(1, name, "????") <= 0 Then '?ж????????
  60.                
  61.                 swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  62.                     """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  63.                 swModelDocExt.Create3DBoundingBox '????????
  64.                
  65.                 swCustPropMgr.Add3 "???", swCustomInfoType_e.swCustomInfoText, _
  66.                     """SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  67.                     & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  68.                     & "x""" & "SW-3D-??????@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  69.                     swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  70.                
  71.             Else
  72.                 swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '???????????DESCRIPTION?????
  73.                 swCustPropMgr.Add3 "????", swCustomInfoType_e.swCustomInfoText, _
  74.                     textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '???????DESCRIPTION???????д???????????????
  75.                
  76.             End If
  77.         End If
  78.         '        Debug.Print swFeat.GetTypeName2
  79.         Set swFeat = swFeat.GetNextFeature
  80.         
  81.     Loop
  82.     bRet = swModel.ForceRebuild3(False)
  83.     MsgBox "???"
  84. End Sub
复制代码

这是我编写的一个给焊件填写属性的宏程序,你可参考一下:
9
发表于 2019-11-26 11:40:23 | 只看该作者
三维专家 发表于 2019-11-26 11:37
这是我编写的一个给焊件填写属性的宏程序,你可参考一下:

好好的文件,怎么成了乱码?
10
发表于 2019-11-26 11:46:16 | 只看该作者
本帖最后由 三维专家 于 2019-11-26 11:47 编辑
  1. '该宏可为焊件切割清单属性填写一些通过其它方式获取的属性(也就是和其它一些有关联),
  2. '如“名称”和切割清单某个项目名称相同;"单重"和“SW-Mass”相同;
  3. '如“数量”和“QUANTITY”相同;
  4. '对于板材件,增加一项“备注”,并获取平板的边界框参数,将该参数填写进“备注”项目中

  5. Option Explicit

  6. Dim swApp As SldWorks.SldWorks
  7. Dim swModel As SldWorks.ModelDoc2
  8. Dim swModelDocExt As SldWorks.ModelDocExtension
  9. Dim swFeat As SldWorks.Feature

  10. Dim swCustPropMgr As SldWorks.CustomPropertyManager
  11. Dim names As Variant '属性名称数组变体
  12. Dim bRet As Boolean
  13. Dim evalval As String
  14. Dim featureName As String
  15. Dim boolstatus As Boolean
  16. Dim opt As Long

  17. Sub main()
  18.     Set swApp = Application.SldWorks
  19.     Set swModel = swApp.ActiveDoc
  20.     Set swModelDocExt = swModel.Extension
  21.    
  22.     ' 获取第一个特征
  23.     Set swFeat = swModel.FirstFeature
  24.    
  25.     Dim FileName As String
  26.     Dim name As String      '属性名称
  27.     Dim textexp As String
  28.     Dim evalval As String
  29.    
  30.     FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1)
  31.    
  32.    
  33.     Do While Not swFeat Is Nothing
  34.         If swFeat Is Nothing Then
  35.             Exit Do
  36.         End If
  37.         featureName = swFeat.name
  38.         If swFeat.GetTypeName2 = "CutListFolder" Then
  39.             boolstatus = swModelDocExt.SelectByID2(featureName, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  40.             Set swCustPropMgr = swFeat.CustomPropertyManager
  41.             names = swCustPropMgr.GetNames
  42.             name = Join(names, " ") '将数组转变为用空格隔开的字符串
  43.             
  44.             
  45.             swCustPropMgr.Add3 "名称", swCustomInfoType_e.swCustomInfoText, _
  46.                 """SW-CutListItemName@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  47.             
  48.             
  49.             swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval
  50.             swCustPropMgr.Add3 "单重", swCustomInfoType_e.swCustomInfoText, _
  51.                 """SW-Mass@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  52.             
  53.             swCustPropMgr.Get2 "QUANTITY", textexp, evalval
  54.             swCustPropMgr.Add3 "数量", swCustomInfoType_e.swCustomInfoText, _
  55.                 textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  56.             swCustPropMgr.Add3 "所属装配号", swCustomInfoType_e.swCustomInfoText, _
  57.                 "$PRP:""SW-File Name""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  58.             
  59.             If InStr(1, name, "长度") <= 0 Then '判断是否为板材
  60.                
  61.                 swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  62.                     """SW-Material@@@" & swFeat.name & "@" & FileName & """", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  63.                 swModelDocExt.Create3DBoundingBox '创建边界框
  64.                
  65.                 swCustPropMgr.Add3 "备注", swCustomInfoType_e.swCustomInfoText, _
  66.                     """SW-3D-边界框长度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  67.                     & "x""" & "SW-3D-边界框宽度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""" _
  68.                     & "x""" & "SW-3D-边界框厚度@@@" & swFeat.name & "@" & FileName & ".SLDPRT""", _
  69.                     swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd
  70.                
  71.             Else
  72.                 swCustPropMgr.Get2 "DESCRIPTION", textexp, evalval '如果为型材,获取DESCRIPTION属性值
  73.                 swCustPropMgr.Add3 "材料", swCustomInfoType_e.swCustomInfoText, _
  74.                     textexp, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd '将获取的DESCRIPTION属性值填写到“材料”属性中
  75.                
  76.             End If
  77.         End If
  78.         '        Debug.Print swFeat.GetTypeName2
  79.         Set swFeat = swFeat.GetNextFeature
  80.         
  81.     Loop
  82.     bRet = swModel.ForceRebuild3(False)
  83.     MsgBox "完成"
  84. End Sub
复制代码
转到记事本,重新复制一下,又好了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2025-2-21 18:20 , Processed in 0.026792 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2025 www.iCAx.org

快速回复 返回顶部 返回列表