Advertisement
makos

id clear

Jul 1st, 2024
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 clrNo As Integer
  10. Dim swFeat As Feature
  11.  
  12. Sub main()
  13.     Set swApp = Application.SldWorks
  14.     Set swModel = swApp.ActiveDoc
  15.     Set featMgr = swModel.FeatureManager
  16.    
  17.     If swModel.GetType <> swDocASSEMBLY Then
  18.         MsgBox "Please open an assembly!", vbCritical, "Error"
  19.         Exit Sub
  20.     End If
  21.  
  22.     vComponents = swModel.GetComponents(False)
  23.    
  24.     clrNo = 0
  25.     Dim i As Integer
  26.     For i = 0 To UBound(vComponents)
  27.         Set curMod = vComponents(i).GetModelDoc2()
  28.         Set swFeat = curMod.FirstFeature
  29.    
  30.         Do While Not swFeat Is Nothing
  31.             If swFeat.GetTypeName2 = "SolidBodyFolder" Then
  32.                 Set swBodyFolder = swFeat.GetSpecificFeature2
  33.                 swBodyFolder.UpdateCutList
  34.             ElseIf swFeat.GetTypeName2 = "CutListFolder" Then
  35.                 Dim vProperties As Long
  36.                 Dim vPropnames As Variant
  37.                 Dim vProptypes As Variant
  38.                 Dim vPropvalues As Variant
  39.                 Dim vResolved As Variant
  40.                
  41.                 vProperties = swFeat.CustomPropertyManager.GetAll2(vPropnames, vProptypes, vPropvalues, vResolved)
  42.                 If vProperties <> 0 Then
  43.                     Dim j As Integer
  44.                     For j = 0 To vProperties - 1
  45.                         If vPropnames(j) = "id" And vPropvalues(j) <> "" Then
  46.                             swFeat.CustomPropertyManager.Set2 vPropnames(j), ""
  47.                             clrNo = clrNo + 1
  48.                         End If
  49.                     Next j
  50.                 End If
  51.             End If
  52.            
  53.             Set swFeat = swFeat.GetNextFeature
  54.         Loop
  55.     Next i
  56.     MsgBox "Cleared " & clrNo & " values", vbOKOnly, "ID macro"
  57. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement