Macro create drawing of an assembly then DWG

Hello

I will explain myself in more detail on the matter,

I would like to create a macro that makes me the drawing of my active assembly, on a model drawing that has predefined views,

who then records it in DWG and then closes the MEP without saving it,

normally when I do "create drawing from" and I select the MEP model, it puts my views well, except there when I use the macro recorder and I run it no views of my 3D on the MEP,

Here is the draft of the macro:

-----------------------------------------------------------------------

Dim swApp As Object

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

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
Set Part = swApp.NewDocument("V:\BE\Cartridges\Drawing DWG.drwdot", 12, 0.21, 0.297)
Part.ViewZoomtofit2
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomtofit2
longstatus = Part.SaveAs3("C:\Users\j-delepine\Desktop\Test DWG\to be renamed. DWG", 0, 0)
boolstatus = Part.Extension.SelectByID2("Drawing", "SHEET", 0.236201718247981, 0.158738777908343, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
Set Part = Nothing
swApp.CloseDoc "to be renamed - Drawing"
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "part", False, longstatus
Set Part = swApp.ActiveDoc
End Sub

-----------------------------------------------------------------------------

Thank you in advance for your answers

PS: I'm not a complete beginner in VBA, but I don't know everything:)

Hello

I found a macro that does the same thing. It is advisable to draw inspiration from existing code to create macros when you are not an expert! Edit: the macro is attached at the bottom of this message.

Other interesting information on the instructions to use:

https://forum.solidworks.com/thread/28202

Otherwise, I also found this utility: http://amcbridge.com/?q=Drawing.Works

But if the macro development is ongoing, it's better to focus on the first link.


auto-create_drawing_from_model.zip
1 Like