ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
RRRyan Rutledge28/03/2013

Hi everybody!

I've got a macro that I successfully use to export STEP models of each configuration in a .SLDPRT, though I use excel and several manual operations to generate the right names. I started that macro by recording a macro where I just switch to a config then save it as a .STEP file, then I stopped the macro recording and edited the macro to handle all the configs. It would be really nice to have a macro that automatically iterates through all configs in a part and saves STEP models according to the configuration name, but that's a sub-issue. Please note that I am trying to generate Top view DWG exports of each config of a SLDPRT, not a SLDDRW file (which I can do manually by simply doing Save As and selecting DWG as the output type. Note that I'm using SW Premium 2012 x64 SP4.0.

The first issue I have is that I tried to do the same macro recording to save as a .DWG file, but the very macro that SW records doesn't work! I get an unsupported method error on the following line:

Set myView = Part.CreateDrawViewFromModelView3("L:\Eng\Working\CAD\Engineering Sandbox\Ryan\My Parts\CircuitWorks\Components\CAP_SMD.SLDPRT", "*Top", 0, 0, 0)

The whole macro, as recorded by SolidWorks, is as follows:

' ******************************************************************************

' C:\Users\rrutledge\AppData\Local\Temp\swx9384\Macro1.swb - macro recorded on 03/28/13 by rrutledge

' ******************************************************************************

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

boolstatus = Part.Extension.SelectByID2("CAPC1005X55N", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)

boolstatus = Part.ShowConfiguration2("CAPC1005X55N")

longstatus = Part.SaveAs3("L:\Eng\Working\CAD\Engineering Sandbox\Ryan\My Parts\STEP Models\CAPC1005X55N.DWG", 0, 0)

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameLeft = 0

myModelView.FrameTop = 21

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks 2011\templates\Drawing.drwdot", 0, 0, 0)

swApp.ActivateDoc2 "Draw1 - Sheet1", False, longstatus

Set Part = swApp.ActiveDoc

Set Part = swApp.ActiveDoc

Set myModelView = Part.ActiveView

myModelView.FrameLeft = 0

myModelView.FrameTop = 0

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

swApp.ActivateDoc2 "CAP_SMD.SLDPRT", False, longstatus

Set Part = swApp.ActiveDoc

Dim myView As Object

Set myView = Part.CreateDrawViewFromModelView3("L:\Eng\Working\CAD\Engineering Sandbox\Ryan\My Parts\CircuitWorks\Components\CAP_SMD.SLDPRT", "*Top", 0, 0, 0)

Part.ClearSelection2 True

End Sub

I'm stuck in a rut here because if SolidWorks isn't even recording a macro that I can base mine off of, then I don't have much hope being a novice here. I looked up the CreateDrawViewFromModelView3 method HERE and I can't tell why the unsupported method error is being thrown. It also looks to me like the macro isn't really finished since I can't see where the save is actually happening because there is so much code after the

longstatus = Part.SaveAs3("L:\Eng\Working\CAD\Engineering Sandbox\Ryan\My Parts\STEP Models\CAPC1005X55N.DWG", 0, 0) line that seems like it should preceed it.

To my novice eyes, here's what it looks like the macro is doing (in laymans terms):

Select config

Show config

Save current part as DWG

Center part in viewport

Maximise viewport

Center part in viewport

Maximise viewport

Create new drawing document

Switch to drawing document

Center drawing in viewport

Maximise viewport

Maximise viewport

Switch back to SLDPRT document

Create drawing view of SLDPRT document in "*Top" view at 0, 0, 0

Deselect newly added drawing view

To me, this looks incomplete or at best, out of order. It looks like the macro is showing me some of what happens in the background when I do a Save As and select DWG as the output, but all I am doing to invoke all this stuff is essentially choose Save As▸DWG▸Top view▸OK.

Any help would be greatly appreciated as I'm finding the API rather daunting and the macro recording a letdown.