Hi there,
I'm trying to Pack and Go a Part or Assembly including Drawings based on the code from the SW help.
In fact, I'll suppose, it should be exactly the same when you run Pack and Go from within SW.
When I set include drawings to true I can get it working to include drawings for a Part or Assembly within the Pack and Go.
What am I doing wrong ?
Is there an extra step where I put the focus on a drawing or something ?
What I've tried now is to create a module 'Pack and Go' which finds out if there is a drawing related to the part or assy.
If so then close all files related to the Pack and Go and open the drawing, next goto another module 'Pack and Go Final' and do the Pack and Go.
It's working sometimes but Solidworks don't like it that much and crashes a lot of times, I don't know what makes SW crash.
It looks like the P&G is not fully closed in the first module, could that be the problem and if so how can I fully close the P&G object, I'm only using it to determine the next step.
I've tried now to use other variables then the ones in the final P&G.
Also I've tried to open the drawing invisible and then run the P&G, seems it's not working.
In fact I like to set the P&G focus on a file without opening or at least viewing the file.
'Open Drawing invisibly
''swApp.DocumentVisible False, swDocDRAWING
My final goal is to P&G standard designs into project specific designs, toolboxparts and other purchase parts I don't need in a project specific map.
Therefore I check the filenames and there folders, for example when the foldername contains 'solidworks data' I know it's a Toolbox part, leave it there by not treating the original path name.
Anyone experienced in using P&G within API ?
Greetings !
'------------------------------------------
'
' Preconditions:
' 1. Specified assembly exists.
' 2. The folder, c:\temp, exists.
' 3. Open the Immediate window.
' 4. Run the macro.
'
' Postconditions:
' 1. Names of the current path and filenames
' of the assembly documents are printed to Immediate window.
' 2. Names of the default path and filenames to which to
' save assembly documents are printed to Immediate window.
' 3. User-specified path and user-named files for assembly documents
' created.
' 4. Prefix and suffix added to user-named filenames.
' 5. Names of user-specified path and user-named filenames printed to
' Immediate window.
' 6. User-named files created in user-specified path using Pack and Go.
' 7. Examine c:\temp to verify.
'
'-------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPackAndGo As SldWorks.PackAndGo
Dim openFile As String
Dim myFileName As String
Dim pgFileNames As Variant
Dim pgFileStatus As Variant
Dim pgSetFileNames() As String
Dim pgGetFileNames As Variant
Dim pgDocumentStatus As Variant
Dim status As Boolean
Dim warnings As Long
Dim errors As Long
Dim i As Long
Dim j As Long
Dim namesCount As Long
Dim myPath As String
Dim statuses As Variant
Sub main()
Set swApp = Application.SldWorks
' Open assembly
openFile = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\advdrawings\handle.sldasm"
Set swModelDoc = swApp.OpenDoc6(openFile, swDocASSEMBLY, swOpenDocOptions_Silent, "", errors, warnings)
Set swModelDocExt = swModelDoc.Extension
' Get Pack and Go object
Debug.Print "Pack and Go"
Set swPackAndGo = swModelDocExt.GetPackAndGo
' Get number of documents in assembly
namesCount = swPackAndGo.GetDocumentNamesCount
Debug.Print " Number of model documents: " & namesCount
' Get whether to include any drawings and simulation results
Debug.Print " Include drawings: " & swPackAndGo.IncludeDrawings
Debug.Print " Include simulation results: " & swPackAndGo.IncludeSimulationResults
' Get current paths and filenames of the assembly's documents
status = swPackAndGo.GetDocumentNames(pgFileNames)
Debug.Print ""
Debug.Print " Current path and filenames: "
If (Not (IsEmpty(pgFileNames))) Then
For i = 0 To UBound(pgFileNames)
Debug.Print " The path and filename is: " & pgFileNames(i)
Next i
End If
' Get current save-to paths and filenames of the assembly's documents
status = swPackAndGo.GetDocumentSaveToNames(pgFileNames, pgFileStatus)
Debug.Print ""
Debug.Print " Current default save-to filenames: "
If (Not (IsEmpty(pgFileNames))) Then
For i = 0 To UBound(pgFileNames)
Debug.Print " The path and filename is: " & pgFileNames(i)
Next i
End If
' Folder where to save the files
myPath = "C:\temp\"
' Create your own filenames for the model's documents
ReDim pgSetFileNames(namesCount - 1)
Debug.Print ""
Debug.Print " My Pack and Go path and filenames before adding prefix and suffix: "
j = 0
For i = 0 To (namesCount - 1)
myFileName = pgFileNames(i)
' Determine type of SolidWorks file based on file extension
If InStr(LCase(myFileName), "sldprt") > 0 Then
myFileName = j & ".sldprt"
ElseIf InStr(LCase(myFileName), "sldasm") > 0 Then
myFileName = j & ".sldasm"
ElseIf InStr(LCase(myFileName), "slddrw") > 0 Then
myFileName = j & ".slddrw"
Else
' Only packing up SolidWorks files
Exit Sub
End If
pgSetFileNames(i) = myPath & myFileName
Debug.Print " My path and filename is: " & pgSetFileNames(i)
j = j + 1
Next i
' Set document paths and names for Pack and Go
status = swPackAndGo.SetDocumentSaveToNames(pgSetFileNames)
' Add a prefix and suffix to the new Pack and Go filenames
swPackAndGo.AddPrefix = "SW"
swPackAndGo.AddSuffix = "PackAndGo"
' Verify document paths and filenames after adding prefix and suffix
ReDim pgGetFileNames(namesCount - 1)
ReDim pgDocumentStatus(namesCount - 1)
status = swPackAndGo.GetDocumentSaveToNames(pgGetFileNames, pgDocumentStatus)
Debug.Print ""
Debug.Print " My Pack and Go path and filenames after adding prefix and suffix: "
For i = 0 To (namesCount - 1)
Debug.Print " My path and filename is: " & pgGetFileNames(i)
Next i
' Pack and Go
statuses = swModelDocExt.SavePackAndGo(swPackAndGo)
End Sub