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

标题: solidworks利用切割清单信息提取钣金展开尺寸到属性栏 宏 [打印本页]

作者: 1351375275    时间: 2019-8-24 08:24
标题: solidworks利用切割清单信息提取钣金展开尺寸到属性栏 宏
这个宏可以用在2014版以上,之前我发了个贴,那个宏只能用于2018版以上。
作者: yezhi1973    时间: 2019-8-24 11:39
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 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 bjkcd As Double
Dim bjkkd As Double
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set thisFeat = Part.FirstFeature
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
propNames = custPropMgr.GetNames '获取切割清单属性的数据全部名称并放入数组
If Not IsEmpty(propNames) Then
For Each vName In propNames
propName = vName
custPropMgr.Get2 propName, Value, resolvedValue '获取全部属性名称 ,数值和评估的值
If propName = "边界框长度" Then bjkcd = resolvedValue '判断是否是自己所需要的数据,如果是就获取
If propName = "边界框宽度" Then bjkkd = resolvedValue
Next vName
End If
End If
End If
End If
Set thisSubFeat = thisSubFeat.GetNextSubFeature
Loop
Set thisFeat = thisFeat.GetNextFeature
Loop
blnretval = Part.DeleteCustomInfo2("", "边界框长度") '删除属性栏上摘要信息的数据
blnretval = Part.DeleteCustomInfo2("", "边界框宽度")
blnretval = Part.AddCustomInfo3("", "边界框长度", swCustomInfoText, bjkcd) '添加数据到摘要信息
blnretval = Part.AddCustomInfo3("", "边界框宽度", swCustomInfoText, bjkkd)
End Sub
作者: azio1999    时间: 2019-8-24 18:11
[attach]955110[/attach]
作者: 秀才有力    时间: 2019-8-24 18:25
[attach]955111[/attach]
在属性栏输出的直接是数据,而不是表达式了
作者: chujun1982    时间: 2019-8-24 20:34
之前的帖子
http://tieba.baidu.com/p/6225758788
作者: hugaoqun    时间: 2019-8-24 22:18
好东西谢谢楼主
作者: wjyzjq    时间: 2019-8-24 23:25
非常棒!我在你的基础上加入了钣金厚度。
[attach]955112[/attach]
作者: oewhnb    时间: 2019-8-25 03:19
每改完1次都有运行一次宏吗?
作者: Jason0410    时间: 2019-8-25 03:21
大锅,你能不能从 “宏命令”的最基础讲起啊?这玩意儿99%的人都不会哎............
作者: huaxiaofeng    时间: 2019-8-25 04:55
[attach]955113[/attach]
在自定义属性中本来有自带的两栏,但是不带表达式,也不知道表达式怎么写,百度了很久也是没有头绪,望不吝赐教,




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