AnsweredAssumed Answered

Pack & Go - Rename - Custom property

Question asked by Devas Sheth on Jul 4, 2019
Latest reply on Jul 17, 2019 by Deepak Gupta



I started to learn API, It will be great help if someone solve this issue.


Making a macro for "Pack & Go" Assembly with parts and drawings, I used below code that I found on internet it works to pack & go files with same name and 1st letter lower case.



1) 1st Letter should be Upper case (or no change in name style)

2) Assembly, Parts and drawings have same format  and that is for example as below (important for pack and go : 1234567-8 Rev.1)


"PART ASSEMBLY 1234567-8 Rev.1.SLDASM", 

"PART ASSEMBLY 1234567-8 Rev.1.SLDDRW"

"PART-1 1234567-8 Rev.1.SLDPRT"

"XYZ-2 1234567-8 Rev.1.SLDPRT"

"ABC 1234567-8 Rev.1.SLDPRT"


so user form should have 3 different entry for this, 1st for 7 digit number that is order number(1234567), 2nd for sub section number(8) and last is for revision.


3) we have same custom property in assembly and parts that need to be link with pack & go

- Number : "1234567"

-Sub section : 8

- Revision - Rev.1



Const strOutputPath As String = "C:\Users\PC\Downloads\test\"

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPackAndGo As SldWorks.PackAndGo
Dim intDocCount As Integer
Dim vPathNames As Variant
Dim strSetPathNames() As String
Dim i As Integer
Dim vStatus As Variant


   Set swApp = Application.SldWorks
   Set swModel = swApp.ActiveDoc


If swModel Is Nothing Then
swApp.SendMsgToUser "Please open an assembly or drawing."
Exit Sub
ElseIf swModel.GetType <> swDocASSEMBLY And swModel.GetType <> swDocDRAWING Then
swApp.SendMsgToUser "Please open an assembly or drawing."
Exit Sub
End If


Set swPackAndGo = swModel.Extension.GetPackAndGo

intDocCount = swPackAndGo.GetDocumentNamesCount
ReDim strSetPathNames(intDocCount - 1) As String


swPackAndGo.GetDocumentNames vPathNames


swPackAndGo.SetSaveToName True, strOutputPath


swPackAndGo.IncludeDrawings = True


vStatus = swModel.Extension.SavePackAndGo(swPackAndGo)


End Sub



Warm Regards.