AnsweredAssumed Answered

Basic Macro - Create drawing from current part and save as dxf

Question asked by Toby Webbley on Mar 25, 2019
Latest reply on Mar 25, 2019 by Carrie Ives

Hello,

 

I am new to VBA in Solidworks, I am trying to create a basic macro that will take the part I currently have open, create a blank drawing, insert the part at 1:1 scale, as current model view and save it as a dxf as the same name as the filename. I have recorded what I want to do but I don't want it to refer to a particular part name or location;

 

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("P:\CAD Templates\SolidWorks\Templates\Drawing.drwdot", 2, 0.2794, 0.4318)
swApp.ActivateDoc2 "Draw7 - Sheet1", False, longstatus
Set Part = swApp.ActiveDoc
Dim myView As Object
Set myView = Part.CreateDrawViewFromModelView3("K:\2) CNC Data\6000LL Node Plates\S200_E8819_2018\Archive\E8819_B.SLDPRT", "Current Model View", -0.144143871807488, 0.136827902039255, 0) '<<<I want this to insert the part that is currently open, at 1:1 scale, as current model view and put it anywhere on the page.
boolstatus = Part.ActivateView("Drawing View1")
Part.ViewZoomtofit2
Part.SheetPrevious
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
longstatus = Part.SaveAs3("K:\2) CNC Data\6000LL Node Plates\S200_E8819_2018\Archive\", 0, 0) '<<<I want this to prompt a window asking where to save, or to save it in the same location as the open file.
End Sub

 

Are there commands that I can insert into each of the orange highlighted sections that will do what I want them to?

 

Thanks,

 

Toby.

Outcomes