AnsweredAssumed Answered

need help with a macro

Question asked by Ray Calhoon on Mar 16, 2017
Latest reply on Mar 17, 2017 by Ray Calhoon

I want to create a macro to save the flat pattern as a .dxf in a specified location (user entry) with the name of the part file that is open.  Here is what I've recorded, but it's not working, and I know basically nothing of VB nor API.  Any help would be greatly appreciated.

 

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

' C:\Users\raycal\AppData\Local\Temp\swx8544\Macro1.swb - macro recorded on 03/16/17 by raycal

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

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("Flat-Pattern", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

longstatus = Part.Save2(False)

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameLeft = 0

myModelView.FrameTop = 33

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Set Part = swApp.NewDocument("S:\Custom Setup Files\True Templates\SHEET METAL DRW DEC-16.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

swApp.ActivateDoc2 "Part1", False, longstatus

Set Part = swApp.ActiveDoc

Part.EditUnsuppress2

boolstatus = Part.Extension.SelectByID2("Flat-Pattern", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Part.BlankSketch

Part.BlankSketch

Part.BlankSketch

Part.BlankSketch

Part.BlankSketch

Part.BlankSketch

Dim myView As Object

Set myView = Part.CreateDrawViewFromModelView3("Part1", "DxfOutputModelView", 0, 0, 0)

boolstatus = Part.DeleteNamedView(DxfOutputModelView)

Part.BlankSketch

Part.BlankSketch

Part.UnblankSketch

Part.UnblankSketch

Part.EditSuppress2

boolstatus = Part.Extension.SelectByID2("Flat-Pattern", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Part.ClearSelection2 True

End Sub

Outcomes