Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc2
- Dim featMgr As SldWorks.FeatureManager
- Dim curMod As SldWorks.ModelDoc2 'currently traversed Model
- Dim swBodyFolder As BodyFolder 'bodyfolder = top-level cut-list folder
- Dim vComponents As Variant 'all components in the assy
- Dim id As Integer
- Dim swFeat As Feature
- Sub main()
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- Set curMod = swApp.ActiveDoc
- Set featMgr = swModel.FeatureManager
- If (swModel.GetType <> swDocPART) Then
- MsgBox "Please open a part file", vbCritical, "Error"
- Exit Sub
- End If
- id = CInt(InputBox("Start ID:", "ID Macro", "1"))
- 'id = 1
- If Not curMod Is Nothing Then
- Set swFeat = curMod.FirstFeature
- Do While Not swFeat Is Nothing
- If Not swFeat.IsSuppressed Then
- 'Debug.Print swFeat.Name
- If swFeat.GetTypeName2 = "SolidBodyFolder" Then
- Set swBodyFolder = swFeat.GetSpecificFeature2
- swBodyFolder.UpdateCutList
- ElseIf swFeat.GetTypeName2 = "CutListFolder" Then
- Dim vProperties As Long
- Dim vPropnames As Variant
- Dim vProptypes As Variant
- Dim vPropvalues As Variant
- Dim vResolved As Variant
- vProperties = swFeat.CustomPropertyManager.GetAll2(vPropnames, vProptypes, vPropvalues, vResolved)
- If vProperties <> 0 Then
- 'Debug.Print "Number props: " & vProperties
- Dim j As Integer
- For j = 0 To vProperties - 1
- Debug.Print "Name: " & vPropnames(j)
- Debug.Print "Value: " & vPropvalues(j)
- If vPropnames(j) = "id" Then
- If vPropvalues(j) >= id Then
- Debug.Print "Found id value: " & vPropvalues(j)
- ' Debug.Print "Found id, assigning " & id
- swFeat.CustomPropertyManager.LinkProperty "id", False
- swFeat.CustomPropertyManager.Set2 vPropnames(j), CStr(id)
- id = id + 1
- End If
- End If
- Next j
- End If
- End If
- End If
- Set swFeat = swFeat.GetNextFeature
- Loop
- End If
- 'Debug.Print "Last ID assigned: " & id - 1
- MsgBox "Last ID: " & id - 1, vbOKOnly, "ID macro"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement