本帖最后由 zyf0732 于 2014-11-22 11:44 编辑
响应鹿大号召,我就是在闷大基础上增加了几个适合我的属性
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
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
custPropMgr.Delete "Total Weight"
custPropMgr.Delete "Weight"
custPropMgr.Delete "h名称"
custPropMgr.Delete "h数量"
custPropMgr.Delete "图号"
fn = thisSubFeat.Name
pn = Part.GetTitle
custPropMgr.Add "Weight", "文字", Chr(34) & "SW-Mass@@@" & fn & "@" & pn & Chr(34)
custPropMgr.Add "h名称", "文字", fn
propNames = custPropMgr.GetNames
If Not IsEmpty(propNames) Then
For Each vName In propNames
propName = vName
custPropMgr.Get2 propName, Value, resolvedValue
If propName = "Weight" Then TotalW = resolvedValue
Next vName
End If
custPropMgr.Add "Total Weight", "文字", Format(BodyCount * TotalW, "0.00")
custPropMgr.Add "h数量", "文字", BodyCount
custPropMgr.Add "图号", "文字", Left(pn, InStrRev(pn, ".") - 1) & "-"
End If
End If
End If
Set thisSubFeat = thisSubFeat.GetNextSubFeature
Loop
Set thisFeat = thisFeat.GetNextFeature
Loop
End Sub
不过这段程序没明白什么意思
propNames = custPropMgr.GetNames
If Not IsEmpty(propNames) Then
For Each vName In propNames
propName = vName
custPropMgr.Get2 propName, Value, resolvedValue
If propName = "Weight" Then TotalW = resolvedValue
Next vName
End If
还有请问各位大侠 能否把各个宏变都成按钮图标,用哪个就点哪个,不用再选择?
|