Advertisement
Guest User

Solidworks VBA for Balloon Locations

a guest
May 22nd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. Dim swApp As Object
  2. Sub main()
  3. Dim swApp As SldWorks.SldWorks
  4. Dim swModel As SldWorks.ModelDoc2
  5. Dim swDrw As DrawingDoc
  6. Dim swSheet As SldWorks.Sheet
  7. Dim swView As View
  8. Dim swoNote As Note
  9. Dim swAnn As Annotation
  10. Dim swAnns As Variant
  11. Dim sSheetName() As String
  12. Dim swEnt As SldWorks.Entity
  13. Dim swComp As SldWorks.Component
  14. Dim i, j, ix As Long
  15. Dim BalloonArray() As Variant
  16.  
  17. Set swApp = Application.SldWorks
  18. Set swModel = swApp.ActiveDoc
  19. If swModel.GetType = swDocDRAWING Then
  20. Set swDrw = swModel
  21. Else
  22. MsgBox "Open a drawing doc, please", vbOKOnly + vbInformation
  23. Exit Sub
  24. End If
  25.  
  26. sSheetName = swDrw.GetSheetNames
  27. ix = 0
  28. For i = 0 To UBound(sSheetName)
  29. swDrw.ActivateSheet sSheetName(i)
  30. Set swSheet = swDrw.GetCurrentSheet
  31. ' Debug.Print sSheetName(i)
  32. Set swView = swDrw.GetFirstView
  33. Do
  34. swAnns = swView.GetAnnotations
  35. If Not IsEmpty(swAnns) Then
  36. For j = 0 To UBound(swAnns)
  37. Set swAnn = swAnns(j)
  38. If swAnn.GetType = swNote Then
  39. Set swoNote = swAnn.GetSpecificAnnotation
  40. If swoNote.IsBomBalloon Then
  41. ReDim Preserve BalloonArray(ix)
  42. BalloonArray(ix) = Array(swoNote.GetText, i + 1, swSheet.GetDrawingZone(swoNote.GetBalloonInfo(0), swoNote.GetBalloonInfo(1)))
  43. ix = ix + 1
  44. Debug.Print (swoNote.GetText & ": " & i + 1 & ", " & swSheet.GetDrawingZone(swoNote.GetBalloonInfo(0), swoNote.GetBalloonInfo(1)))
  45. End If
  46. End If
  47. Next j
  48. End If
  49. Set swView = swView.GetNextView
  50. Loop While Not (swView Is Nothing)
  51. Next i
  52. ''Added BOM Intigration
  53. Dim swDraw As SldWorks.DrawingDoc
  54. Dim swFeat As SldWorks.Feature
  55. Dim BOMName As String
  56. Dim swFileName As String
  57. Dim swBomFeat As SldWorks.BomFeature
  58. Dim vBomTableAnn As Variant
  59. Dim swBomTableAnn As SldWorks.BomTableAnnotation
  60. Dim swTableAnn As SldWorks.TableAnnotation
  61. Dim iRow As Integer
  62. Dim iCol As Integer
  63.  
  64. Set swApp = Application.SldWorks
  65. Set swModel = swApp.ActiveDoc
  66. Set swDrawingsDoc = swApp.ActiveDoc
  67. Set swFeat = swModel.FirstFeature
  68.  
  69. While Not swFeat Is Nothing
  70. BOMName = swFeat.Name
  71. If "BomFeat" = swFeat.GetTypeName Then
  72. 'swFeat.Select True
  73. Set swBomFeat = swFeat.GetSpecificFeature2
  74. vBomTableAnn = swBomFeat.GetTableAnnotations
  75. Set swBomTableAnn = vBomTableAnn(0)
  76. Set swTableAnn = swBomTableAnn
  77. ' For iRow = 0 To swTableAnn.TotalRowCount - 1
  78. ' For iCol = 0 To swTableAnn.TotalColumnCount - 1
  79. ' Debug.Print swTableAnn.Text(iRow, iCol)
  80. ' Next
  81. ' Next
  82. If swTableAnn.DisplayedText(0, swTableAnn.ColumnCount - 1) <> "ZONE" Then
  83. swTableAnn.InsertColumn2 swTableItemInsertPosition_Last, 0, "ZONE", swInsertColumn_DefaultWidth
  84. swTableAnn.SetColumnType swTableAnn.ColumnCount - 1, 0
  85. Else
  86. Debug.Print ("already has zone")
  87. End If
  88. For iRow = 0 To swTableAnn.TotalRowCount - 1
  89. For ix = 0 To UBound(BalloonArray)
  90. If BalloonArray(ix)(0) = swTableAnn.Text(iRow, 0) Then
  91. 'Debug.Print BalloonArray(ix)(0) & ": " & BalloonArray(ix)(1) & ", " & BalloonArray(ix)(2) & "::: " & swTableAnn.Text(iRow, 0)
  92. swTableAnn.Text(iRow, swTableAnn.ColumnCount - 1) = swTableAnn.Text(iRow, swTableAnn.ColumnCount - 1) & "(" & BalloonArray(ix)(1) & "/" & BalloonArray(ix)(2) & ")" & vbLf
  93. End If
  94. Next
  95.  
  96. 'Debug.Print swTableAnn.Text(iRow, 0)
  97. Next
  98. End If
  99. Set swFeat = swFeat.GetNextFeature
  100. Wend
  101. ''Added BOM Intigration
  102. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement