Below is a section of a macro I am currency working that dependant up file type runs a save as.

What I am looking to do after this section of code is to open the document that has been saved in order to make changes to the custom properties programmatically.

 

Select Case swModel.GetType       

            Case swDocPART

                 swModel.Extension.SaveAs Path & FileName & ".sldprt", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0

            Case swDocASSEMBLY

                 swModel.Extension.SaveAs Path & FileName & ".sldasm", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0

            Case swDocDRAWING

                swModel.Extension.SaveAs Path & FileName & ".slddrw", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0

End Select

 

I'm guessing that I need to use the Open6 call to do this but that requires that you know the path.

My question is how do I record/retrieve the save destination of the Save As call so that I can then use it for the Open6 location?

 

Assuming that I have to push this to a variable before/after save as?

 


Categories: API∕Macros

Comments
Last comment By: Jonathan Westcott   Tue, 16 Jan 2018 23:18:45 GMT
Re: Macro to Saves As, Reopen, Update Properties, Save, Close

Hi Jonathan,

 

The code below closes the drawing and reopens it. That should help you.

 

Elmar

 

'------------------------------------------------------

'

' Preconditions: Specified file to open exists.

'

'                NOTE: The specified file in this example is shipped as a

'                      sample file for a SolidWorks tutorial. After

'                      opening the file with this macro, close it without saving it so

'                      that it will continue to work with the tutorial.

'

' Postconditions: Specified file is opened as view-only.

'

'------------------------------------------------------

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swDocSpecification As SldWorks.DocumentSpecification

Dim sName, filename As String

Dim longstatus As Long, longwarnings As Long

Dim myFSO As FileSystemObject
Dim myFilePath As String

Sub main()

 

Set swApp = Application.SldWorks
Set ModelDoc2 = swApp.ActiveDoc

filename = GetFilename(ModelDoc2.GetPathName)

myFilePath = ModelDoc2.GetPathName

 

Set swDocSpecification = swApp.GetOpenDocSpec(myFilePath)

sName = swDocSpecification.filename

swDocSpecification.DocumentType = swDocDRAWING

swDocSpecification.ReadOnly = False

swDocSpecification.Silent = False

swApp.QuitDoc ModelDoc2.GetPathName

Set swModel = swApp.OpenDoc7(swDocSpecification)

longstatus = swDocSpecification.Error

longwarnings = swDocSpecification.Warning

 

End Sub

Function GetFilename(strPath As String) As String

    Dim strTemp As String

    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)

    GetFilename = Left$(strTemp, InStrRev(strTemp, ".") - 1)

End Function

By: Elmar Klammer  Sat, 13 Jan 2018 08:17:23 GMT
Re: Macro to Saves As, Reopen, Update Properties, Save, Close

Great.

Thanks for this Elmar.

By: Jonathan Westcott  Tue, 16 Jan 2018 23:18:45 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.