Advertisement
makos

Untitled

Sep 19th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Dim swApp As SldWorks.SldWorks
  4. Dim swModel As SldWorks.ModelDoc2
  5. Dim featMgr As SldWorks.FeatureManager
  6. Dim curMod As SldWorks.ModelDoc2 'currently traversed Model
  7. Dim swBodyFolder As BodyFolder 'bodyfolder = top-level cut-list folder
  8. Dim vComponents As Variant 'all components in the assy
  9. Dim id As Integer
  10. Dim swFeat As Feature
  11.  
  12. Sub main()
  13. Set swApp = Application.SldWorks
  14. Set swModel = swApp.ActiveDoc
  15. Set curMod = swApp.ActiveDoc
  16. Set featMgr = swModel.FeatureManager
  17.  
  18. If (swModel.GetType <> swDocPART) Then
  19. MsgBox "Please open a part file", vbCritical, "Error"
  20. Exit Sub
  21. End If
  22.  
  23. id = CInt(InputBox("Start ID:", "ID Macro", "1"))
  24. 'id = 1
  25.  
  26. If Not curMod Is Nothing Then
  27. Set swFeat = curMod.FirstFeature
  28.  
  29. Do While Not swFeat Is Nothing
  30. If Not swFeat.IsSuppressed Then
  31. 'Debug.Print swFeat.Name
  32. If swFeat.GetTypeName2 = "SolidBodyFolder" Then
  33. Set swBodyFolder = swFeat.GetSpecificFeature2
  34. swBodyFolder.UpdateCutList
  35. ElseIf swFeat.GetTypeName2 = "CutListFolder" Then
  36. Dim vProperties As Long
  37. Dim vPropnames As Variant
  38. Dim vProptypes As Variant
  39. Dim vPropvalues As Variant
  40. Dim vResolved As Variant
  41.  
  42. vProperties = swFeat.CustomPropertyManager.GetAll2(vPropnames, vProptypes, vPropvalues, vResolved)
  43. If vProperties <> 0 Then
  44. 'Debug.Print "Number props: " & vProperties
  45. Dim j As Integer
  46. For j = 0 To vProperties - 1
  47. Debug.Print "Name: " & vPropnames(j)
  48. Debug.Print "Value: " & vPropvalues(j)
  49.  
  50. If vPropnames(j) = "id" Then
  51. If vPropvalues(j) >= id Then
  52. Debug.Print "Found id value: " & vPropvalues(j)
  53. ' Debug.Print "Found id, assigning " & id
  54. swFeat.CustomPropertyManager.LinkProperty "id", False
  55. swFeat.CustomPropertyManager.Set2 vPropnames(j), CStr(id)
  56. id = id + 1
  57. End If
  58. End If
  59. Next j
  60. End If
  61. End If
  62. End If
  63.  
  64. Set swFeat = swFeat.GetNextFeature
  65. Loop
  66. End If
  67. 'Debug.Print "Last ID assigned: " & id - 1
  68. MsgBox "Last ID: " & id - 1, vbOKOnly, "ID macro"
  69. End Sub
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement