Guest User

Drawing No. Macro

a guest
Feb 22nd, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Dim swApp As SldWorks.SldWorks
  2.  
  3. Sub main()
  4.  
  5. Dim swModel As ModelDoc2
  6.  
  7. Dim vComps As Variant
  8.  
  9. Dim swComp As SldWorks.Component2
  10.  
  11. Dim swAssy As SldWorks.AssemblyDoc
  12.  
  13. Dim i As Integer
  14.  
  15. Set swApp = Application.SldWorks
  16.  
  17. Set swModel = swApp.ActiveDoc
  18.  
  19. updateProperty swModel
  20.  
  21. If swModel.GetType = swDocASSEMBLY Then
  22.  
  23. Set swAssy = swModel
  24.  
  25. vComps = swAssy.GetComponents(False)
  26.  
  27. For i = 0 To UBound(vComps)
  28.  
  29. Set swComp = vComps(i)
  30.  
  31. Set swModel = swComp.GetModelDoc2
  32.  
  33. updateProperty swModel
  34.  
  35. Next i
  36.  
  37. End If
  38.  
  39.  
  40.  
  41. End Sub
  42.  
  43.  
  44.  
  45.  
  46. Function updateProperty(swModel As SldWorks.ModelDoc2) As Boolean
  47.  
  48. Dim filename As String, ProjectName As String, DrawingNo As String
  49.  
  50. Dim cpm As CustomPropertyManager
  51.  
  52.  
  53.  
  54. Set cpm = swModel.Extension.CustomPropertyManager("")
  55.  
  56.  
  57.  
  58. 'get needed info from model file name
  59.  
  60. filename = swModel.GetTitle
  61.  
  62. filename = Replace(Replace(filename, ".sldprt", ""), ".sldasm", "")
  63.  
  64. ProjectName = val(filename)
  65.  
  66. If ProjectName = 0 Then
  67.  
  68.  
  69.  
  70. Else
  71.  
  72. 'Add Project Name to custom properties and add text
  73.  
  74. cpm.Add2 "ProjectNo", swCustomInfoText, " "
  75.  
  76. cpm.Set "ProjectNo", ProjectName
  77.  
  78. DrawingNo = Left(filename, 8)
  79.  
  80. End If
  81.  
  82.  
  83.  
  84. If ProjectName = 0 Then
  85.  
  86.  
  87.  
  88. Else
  89.  
  90. 'Add Number to custom properties and add text
  91.  
  92. cpm.Add2 "DrawingNo", swCustomInfoText, " "
  93.  
  94. cpm.Set "DrawingNo", DrawingNo
  95.  
  96. End If
  97.  
  98.  
  99.  
  100. End Function
  101.  
Advertisement
Add Comment
Please, Sign In to add comment