Advertisement
candale

Untitled

Jul 12th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.87 KB | None | 0 0
  1. Dim swApp As SldWorks.SldWorks
  2. Dim swModel As SldWorks.ModelDoc2
  3. Dim swDraw As DrawingDoc
  4. Dim swRefModel As SldWorks.ModelDoc2
  5. Dim swView As SldWorks.View
  6. Dim lerr As Long
  7. Dim bstatus As Boolean
  8. Dim allSheetViewArrays As Variant
  9. Dim sheetViews As Variant
  10. Dim swNote As Note
  11. Dim swConfig As Configuration
  12. Dim BOM_PN As String
  13. Dim assembly As SldWorks.AssemblyDoc
  14. Dim swExtension As ModelDocExtension
  15. Dim cusPropMgr As SldWorks.CustomPropertyManager
  16.  
  17.  
  18.  
  19. Sub main()
  20.  
  21.     Set swApp = Application.SldWorks
  22.     Set swModel = swApp.ActiveDoc
  23.     MsgBox "Doing stuff"
  24.     If swModel.GetType <> swDocDRAWING Then
  25.         Msg = "Only Allowed on Drawings" ' Define message
  26.         Style = vbOKOnly ' OK Button only
  27.         Title = "Error" ' Define title
  28.         Call MsgBox(Msg, Style, Title) ' Display error message
  29.         Exit Sub ' Exit this program
  30.     End If
  31.      
  32.     Set swDraw = swModel
  33.     allSheetViewArrays = swDraw.GetViews
  34.     For i = 0 To UBound(allSheetViewArrays)
  35.         sheetViews = allSheetViewArrays(i)
  36.         For j = 0 To UBound(sheetViews)
  37.        
  38.             Set swView = sheetViews(j)
  39.             Set swRefModel = swView.ReferencedDocument
  40.            
  41.             Dim componentCunt As Integer
  42.             Dim components As Variant
  43.             Dim component As Component2
  44.             Dim swModelPart As SldWorks.ModelDoc2
  45.             Dim longstatus As Long
  46.             Dim boolstatus As Boolean
  47.             Dim swAnn As Annotation
  48.            
  49.             If Not swRefModel Is Nothing Then
  50.                 If swRefModel.GetType = swDocASSEMBLY Then
  51.                     componentCount = swRefModel.GetComponentCount(True)
  52.                     components = swRefModel.GetComponents(False)
  53.                     For k = LBound(components) To UBound(components)
  54.                         Set component = components(k)
  55.                         Set swModelPart = component.GetModelDoc2
  56.                        
  57.                         If swModelPart.GetType = swDocPART Then
  58.                             Set swConfig = swModelPart.GetActiveConfiguration
  59.                             Set cusPropMgr = swConfig.CustomPropertyManager
  60.                             Set swNote = swRefModel.InsertNote("note my friend")
  61.                            
  62.                             If Not swNote Is Nothing Then
  63.                                 swNote.LockPosition = False
  64.                                 swNote.Angle = 0
  65.                                 boolstatus = swNote.SetBalloon(9, 0)
  66.                                 Set swAnn = swNote.GetAnnotation()
  67.                             End If
  68.                            
  69.                         End If
  70.                     Next k
  71.                    
  72.                 End If
  73.             End If
  74.              
  75.             Set swView = swView.GetNextView
  76.         Next j
  77.          
  78.     Next i
  79.      
  80.      
  81. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement