找回密码 注册 QQ登录
开思网工业级高精度在线3D打印服务

iCAx开思网

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

[教程] 宏:焊件切割清单中自动增加『单重』和『总重』的属性+3!(限額5位)

  [复制链接]
641
发表于 2019-5-14 10:52:05 | 只看该作者
学习了
642
发表于 2019-5-17 21:14:08 | 只看该作者
跟焊件死磕到底了。。
643
发表于 2019-5-18 13:45:45 | 只看该作者
如何在焊接件切割清单属性中添加一条名称
名称  钢板 "SW-3D-边界框长度@@@"X"SW-3D-边界框宽度@@@"X"SW-3D-边界框厚度@@@"
如此这样一条,以达到自动出钢板的规格


644
发表于 2019-5-18 13:49:06 | 只看该作者
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

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")
                End If
            End If
        End If
        Set thisSubFeat = thisSubFeat.GetNextSubFeature
    Loop
    Set thisFeat = thisFeat.GetNextFeature
Loop
End Sub


我想在这段代码中能让切割清单中增加一条属性
名称  钢板 "SW-3D-边界框长度@@@"X"SW-3D-边界框宽度@@@"X"SW-3D-边界框厚度@@@"
不明白如何加入进去,请知道可以告知,谢谢


645
发表于 2019-5-20 10:58:51 | 只看该作者
zyf0732 发表于 2014-11-22 11:35
响应鹿大号召,我就是在闷大基础上增加了几个适合我的属性
Option Explicit
Dim swApp As SldWorks.Sld ...

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

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")
                End If
            End If
        End If
        Set thisSubFeat = thisSubFeat.GetNextSubFeature
    Loop
    Set thisFeat = thisFeat.GetNextFeature
Loop
End Sub


我想在这段代码中能让切割清单中增加一条属性
名称  钢板 "SW-3D-边界框长度@@@"X"SW-3D-边界框宽度@@@"X"SW-3D-边界框厚度@@@"
不明白如何加入进去,是否可以告知,谢谢

646
发表于 2019-5-28 14:07:29 | 只看该作者
  1. Sub main()
  2. Set swApp = Application.SldWorks
  3. Set Parts = swApp.ActiveDoc
  4. Set thisFeat = Parts.FirstFeature
  5. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  6. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  7. Parts.ClearSelection2 True
  8. boolstatus = Parts.Extension.SelectByID2("实体", "BDYFOLDER", 0, 0, 0, False, 0, Nothing, 0)
  9. Parts.Extension.Create3DBoundingBox

  10. Do While Not thisFeat Is Nothing
  11.     If thisFeat.GetTypeName = "SolidBodyFolder" Then
  12.         thisFeat.GetSpecificFeature2.UpdateCutList
  13.     End If
  14.     Set thisSubFeat = thisFeat.GetFirstSubFeature
  15.     Do While Not thisSubFeat Is Nothing
  16.         If thisSubFeat.GetTypeName = "CutListFolder" Then
  17.             Set cutFolder = thisSubFeat.GetSpecificFeature2
  18.         End If
  19.         If Not cutFolder Is Nothing Then
  20.             BodyCount = cutFolder.GetBodyCount
  21.             If BodyCount > 0 Then
  22.                 Set custPrOPMgr = thisSubFeat.CustomPropertyManager
  23.                 If Not custPrOPMgr Is Nothing Then
  24.                     custPrOPMgr.Delete "Total Weight"
  25.                     custPrOPMgr.Delete "总重"
  26.                     custPrOPMgr.Delete "Weight"
  27.                     custPrOPMgr.Delete "材料"
  28.                     fn = thisSubFeat.Name
  29.                     pn = Parts.GetTitle
  30.                     custPrOPMgr.Add "单重", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
  31.                     custPrOPMgr.Add "重量", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
  32.                     custPrOPMgr.Add "材料", "文字", Chr(34) & "SW-Material@@@" & fn & "@" & pn & Chr(34)
  33.                     propNames = custPrOPMgr.GetNames
  34.                     If Not IsEmpty(propNames) Then
  35.                         For Each vName In propNames
  36.                             propName = vName
  37.                             custPrOPMgr.Get2 propName, Value, resolvedValue
  38.                             If propName = "重量" Then TotalW = resolvedValue
  39.                         Next vName
  40.                     End If
  41.                     custPrOPMgr.Add "总重", "文字", Format(BodyCount * TotalW, "0.00")
  42.                     custPrOPMgr.Add "名称", "文字", "钢板 ""SW-3D-边界框长度@@@""X""SW-3D-边界框宽度@@@""X""SW-3D-边界框厚度@@@"""
  43.                 End If
  44.             End If
  45.         End If
  46.         Set thisSubFeat = thisSubFeat.GetNextSubFeature
  47.     Loop
  48.     Set thisFeat = thisFeat.GetNextFeature
  49. Loop
  50. End Sub
复制代码
可自动创建焊件的单重总重重量以及3D边界框和焊件中的钢板的名称尺寸长宽厚的链接
但是如果焊件中只有一个实体出错,总重If propName = "重量" Then TotalW = resolvedValue这句执行不下去

647
发表于 2019-5-29 22:29:37 | 只看该作者
厉害了啊
648
发表于 2019-5-30 17:17:29 | 只看该作者
看看,什么情况
649
发表于 2019-7-2 22:12:23 | 只看该作者
看东西幺回复啊
650
发表于 2019-7-3 13:43:34 | 只看该作者
谢谢分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

GMT+8, 2024-12-22 15:20 , Processed in 0.025056 second(s), 12 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

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