AnsweredAssumed Answered

Drawing Macro

Question asked by Mathew Challinor on Dec 13, 2016
Latest reply on Dec 19, 2016 by Mathew Challinor



This is my first post so apologies if this has been covered.


I want to create a macro that will save my current assembly as an STL, load the assembly into my drawing template and create a view from the current assembly view and then create a bill of materials from my bill of material template and then auto balloon the view.


we will have approximately 1000 drawings to-do so need to get this running.


I have got so far and now I am having a few problems. The problems I have are as follows;


  • When I save the part as an stl this needs to be in the current assembly location and have the same name as the assembly.stl
  • When I load the "Current View" I want to bring in "import annotation" and "design annotations" as well.
  • When I try to load a bill of materials I get an error on Set swBOMTable


any help would be much appreciated.


Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _


' Save Part file as .stp and load drawing template


Set Part = swApp.ActiveDoc
longstatus = Part.SaveAs3("V:\Engineering\AMC Tool Library\Tool Assemblies\TA-1001\TA-1001.STEP", 0, 0)
Set Part = swApp.NewDocument("V:\Engineering\Software\Solidworks\TATA_Templates\Tooling_Drawing.drwdot", 12, 0.21, 0.297)
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 22



'Load Drawing View


Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Dim myView As Object
Set myView = Part.CreateDrawViewFromModelView3("V:\Engineering\AMC Tool Library\Tool Assemblies\TA-1001\TA-1001.SLDASM", "Current Model View", 0.146409898581714, 0.11700997510004, 0)
boolstatus = Part.Extension.SelectByID2("Drawing View11", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.ActivateView("Drawing View11")
Part.ClearSelection2 True


' Bill of materials


Set Part = swApp.ActiveDoc
Part.ClearSelection2 True
Dim swActiveView As Object
Set swActiveView = Part.ActiveDrawingView
Dim swBOMTable As Object
Set swBOMTable = swActiveView.InsertBomTable2(False, 0.110111505717365, 0.199996468697135, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, swBomType_e.swBomType_Indented, "Default", "V:\Engineering\Software\Solidworks\TATA_Templates\bomtooling.sldbomtbt")
boolstatus = Part.EditRebuild3()


' Auto Baloon


Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.13842553485699, 0.137862387566601, 0, False, 0, Nothing, 0)
boolstatus = Part.ActivateView("Drawing View1")
Dim vNotes As Variant
Dim autoballoonParams As Object
Set autoballoonParams = Part.CreateAutoBalloonOptions()
autoballoonParams.Layout = 1
autoballoonParams.ReverseDirection = False
autoballoonParams.IgnoreMultiple = True
autoballoonParams.InsertMagneticLine = True
autoballoonParams.LeaderAttachmentToFaces = False
autoballoonParams.Style = 1
autoballoonParams.Size = 2
autoballoonParams.EditBalloonOption = 1
autoballoonParams.EditBalloons = 1
autoballoonParams.UpperTextContent = 1
autoballoonParams.UpperText = """"
autoballoonParams.Layername = "-None-"
autoballoonParams.ItemNumberStart = 1
autoballoonParams.ItemNumberIncrement = 1
autoballoonParams.ItemOrder = 0
vNotes = Part.AutoBalloon5(autoballoonParams)
Part.ClearSelection2 True

End Sub