AnsweredAssumed Answered

Automate: Make & Save New Drawing From Part/Assembly

Question asked by Jason Beeksma on Feb 6, 2017
Latest reply on Mar 14, 2017 by Jason Beeksma

I am in the midst of creating a macro to automate all the "clicks" that are done in the process of making a "New Drawing From Part/Assembly"

 

The macro process:

 

1) The process begins with a part or assembly that is open in Solidworks.

2) The user decides to make a drawing from that part or assembly by clicking the custom button I created "New Drawing From Part/Assembly".

3) The user picks the drawing template.

4) The automation then takes over to insert the part into the drawing, saves the drawing as current file name and file path (of the part/assembly), adds to vault, 'ok' of file data card.

5) Finnish's by showing the drawing as the active doc to now be edited.

 

The result is there would be only 2 clicks from the user, thus providing a drawing ready to be edited. I can actually get it down to 1 click by simply making a macro for the 5 sheet sizes we use. However, I am focused on just 2 clicks now.

 

The macro is not working:

 

'Description: Make a drawing from model. Automates the file name, path, adding to vault, and save.

 

'Pre-condition(s): Model is open and the active window.

 

'Post-status(s): Drawing is open and ready to be edited.

 

'Variable

Dim instance As swCommands_e

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

'Dim swPart As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim CompPathName As String

'Dim DrawView As SldWorks.View

Dim boolstatus As Boolean

Dim FilePath As String

Dim FileName As String

Dim PathSize As String

Dim PathNoExtension As String

'Dim NewFilePath As String

Dim lErrors As Long

Dim lWarnings As Long

'Dim instance As IModelDoc2

'Dim value As System.String

 

 

Sub main()

 

'value = instance.GetPathName()

'MsgBox (value)

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

'swApp.Visible = True

'Set swPart = swModel

 

'Set FilePath = swApp.GetPathName

'Set FileName = swModel\

'MsgBox (FileName)

 

'run the actual SolidWorks commands

swApp.RunCommand swCommands_MakeDrawingFromPartAssembly, "NewDrawingFromPartAssembly"

swApp.RunCommand swCommands_Save

 

'Get path name of model

 

Set swDraw = swApp.ActiveDoc

 

'MyFolder = CurDir$

'MyPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") - 1)

'MyPath = Right(MyPath, Len(MyPath) - InStrRev(MyPath, "\"))

 

'Show File path in message box

'MsgBox (MyPath)

 

Debug.Print "File = " & swModel.GetPathName

Debug.Print "Folder = " & MyPath

Debug.Print "Current Folder = " & MyFolder

 

'Save drawing into same file path and filename as model

boolstatus = swDraw.Save(swSaveAsOptions_Silent, lErrors, lWarnings)

 

' Errors

Debug.Print ("Errors as defined in swFileSaveError_e: " & lErrors)

 

' Warnings

Debug.Print ("Warnings as defined in swFileSaveWarning_e: " & lWarnings)

 

End Sub

Outcomes