Pack and go need to omit library parts
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Pack and go need to omit library parts
I found the example of how to Pack and Go an assembly with a macro (VBA). I will want to add a prefix.
This works great, except, how do I not include my library parts? I don't want to rename them or change the folder location. If I were doing a manual pack and go, I would uncheck my library parts and it would keep the reference back to the original file location.
I do have the advantage that this macro will only be run on a specific assembly, so I can know which files are library parts and hard code that into the macro if that helps.
Thanks,
Carrie
SolidWorks 2020 SP5.0
This works great, except, how do I not include my library parts? I don't want to rename them or change the folder location. If I were doing a manual pack and go, I would uncheck my library parts and it would keep the reference back to the original file location.
I do have the advantage that this macro will only be run on a specific assembly, so I can know which files are library parts and hard code that into the macro if that helps.
Thanks,
Carrie
SolidWorks 2020 SP5.0
- AlexLachance
- Posts: 2174
- Joined: Thu Mar 11, 2021 8:14 am
- Location: Quebec
- x 2353
- x 2008
Re: Pack and go need to omit library parts
Hey Carrie, if your library is in a specific location, perhaps you could do a filter to omit the items that are in that specific location? Just a thought. I know you're speaking macro wise, but maybe that could inspire your solution. I can't really help you programming wise, sorry.CarrieIves wrote: ↑Tue Aug 03, 2021 1:41 pm I found the example of how to Pack and Go an assembly with a macro (VBA). I will want to add a prefix.
This works great, except, how do I not include my library parts? I don't want to rename them or change the folder location. If I were doing a manual pack and go, I would uncheck my library parts and it would keep the reference back to the original file location.
I do have the advantage that this macro will only be run on a specific assembly, so I can know which files are library parts and hard code that into the macro if that helps.
Thanks,
Carrie
SolidWorks 2020 SP5.0
Re: Pack and go need to omit library parts
That's a good thought. If you get your full list of documents with IPackAndGo.GetDocumentSaveToNames and then remove the library files manually from the list based on their file directory. Then you could pass the updated array into IPackAndGo.SetDocumentSaveToNames before completing the procedure.AlexLachance wrote: ↑Tue Aug 03, 2021 1:47 pm Hey Carrie, if your library is in a specific location, perhaps you could do a filter to omit the items that are in that specific location? Just a thought. I know you're speaking macro wise, but maybe that could inspire your solution. I can't really help you programming wise, sorry.
I haven't used this myself yet so I'm only assuming that's how this works based on the help files and few examples. Good Luck!
- Glenn Schroeder
- Posts: 1518
- Joined: Mon Mar 08, 2021 11:43 am
- Location: southeast Texas
- x 1754
- x 2126
Re: Pack and go need to omit library parts
I will preface this by saying I have only a vague idea about what macros are, with absolutely no knowledge about writing one, but when I'm going a Pack and Go and want to exclude my library parts I don't select them manually. I use the Select/Replace function, selecting "In Folder", enter a key word that's in the file path for my library parts, then select "Uncheck All" (thanks again @gupta9665 for teaching me that). Can you get your macro to exclude all components at a certain location? (I assume they're all in a single location.)
"On the days when I keep my gratitude higher than my expectations, well, I have really good days."
Ray Wylie Hubbard in his song "Mother Blues"
Ray Wylie Hubbard in his song "Mother Blues"
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Re: Pack and go need to omit library parts
Currently, I'm doing everything on a network drive, so the part I'm messing with isn't actually in the library. I just want to leave it referencing the original file/file location at this time.
I have hard coded the file names and locations at the moment as I am working through this problem.
I started from the example here:
http://help.solidworks.com/2020/english ... ple_VB.htm
According to this help page:
http://help.solidworks.com/2020/english ... Names.html
"To remove a file from Pack and Go, specify an empty string for that file's element in the PathNameList array. To override the paths and filenames set by this method, use IPackAndGo::SetSaveToName."
So, I have my macro able to find the file in the list of files. I can't figure out how to change the name for that file to be an empty string. I think that will solve this problem, but I haven't figured out how to do that. I'm sure it's something that someone with more experience like @gupta9665 would know how to do with no problem.
I am attaching my macro and a zip file of my assembly I am using.
I am in Texas so my work hours are from about 9 - 6 Central time.
Thanks for the suggestions so far. And thanks in advance for any additional pointers.
I have hard coded the file names and locations at the moment as I am working through this problem.
I started from the example here:
http://help.solidworks.com/2020/english ... ple_VB.htm
According to this help page:
http://help.solidworks.com/2020/english ... Names.html
"To remove a file from Pack and Go, specify an empty string for that file's element in the PathNameList array. To override the paths and filenames set by this method, use IPackAndGo::SetSaveToName."
So, I have my macro able to find the file in the list of files. I can't figure out how to change the name for that file to be an empty string. I think that will solve this problem, but I haven't figured out how to do that. I'm sure it's something that someone with more experience like @gupta9665 would know how to do with no problem.
I am attaching my macro and a zip file of my assembly I am using.
I am in Texas so my work hours are from about 9 - 6 Central time.
Thanks for the suggestions so far. And thanks in advance for any additional pointers.
- Attachments
-
- assy-and-macro.zip
- (2.32 MiB) Downloaded 145 times
Re: Pack and go need to omit library parts
You just need to change this:CarrieIves wrote: ↑Tue Aug 03, 2021 5:30 pm ...
...
So, I have my macro able to find the file in the list of files. I can't figure out how to change the name for that file to be an empty string.
...
...
...
Code: Select all
If pgFileNames(i) = "C:\Users\JSculley.azz\Desktop\Solidworks Files\assy-and-macro\96817A310_M3x6_SCREW.SLDPRT" Then
F1 = i
Code: Select all
If pgFileNames(i) = "C:\Users\JSculley.azz\Desktop\Solidworks Files\assy-and-macro\96817A310_M3x6_SCREW.SLDPRT" Then
pgFileNames(i) = ""
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Re: Pack and go need to omit library parts
@JSculley , Thanks for the suggestion.
I made that change and the list it prints looks OK, but I still end up with the screw being renamed as part of the pack and go. The new assembly is referencing the renamed screw.
There is something different between pgFileNames and pgGetFileNames and I'm not figuring out why they have the two different variables or why they do the ReDim on it either.
I made that change and the list it prints looks OK, but I still end up with the screw being renamed as part of the pack and go. The new assembly is referencing the renamed screw.
There is something different between pgFileNames and pgGetFileNames and I'm not figuring out why they have the two different variables or why they do the ReDim on it either.
Re: Pack and go need to omit library parts
Once you have retrieved the current file names and have set the hardware item names to empty strings (as shown in my first reply), you have to call IPackAngGo::SetDocumentSaveToNames:CarrieIves wrote: ↑Tue Aug 03, 2021 6:26 pm @JSculley , Thanks for the suggestion.
I made that change and the list it prints looks OK, but I still end up with the screw being renamed as part of the pack and go. The new assembly is referencing the renamed screw.
There is something different between pgFileNames and pgGetFileNames and I'm not figuring out why they have the two different variables or why they do the ReDim on it either.
Code: Select all
' Get current paths and filenames of the assembly's documents
status = swPackAndGo.GetDocumentNames(pgFileNames)
Debug.Print ""
Debug.Print " 1 Current path and filenames: "
If (Not (IsEmpty(pgFileNames))) Then
For i = 0 To UBound(pgFileNames)
'check if the library part is there and set it to empty
If pgFileNames(i) = "C:\Users\jsculley.AZZ\Desktop\SOLIDWORKS Files\assy-and-macro\96817A310_M3x6_SCREW.SLDPRT" Then
pgFileNames(i) = "" 'Set hardware item to empty string
Debug.Print "We hit the IF " & F1
' swApp.SendMsgToUser2 "in if" & F1, swMbWarning, swMbOk
End If
Debug.Print " The path and filename is: " & pgFileNames(i)
Next i
'Update pack and go file names
status = swPackAndGo.SetDocumentSaveToNames(pgFileNames)
End If
Code: Select all
pgGetFileNames(F1) = ""
Code: Select all
Dim anItem
anItem = pgGetFileNames(3)
Code: Select all
pgGetFileNames(F1) = ""
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Re: Pack and go need to omit library parts
@JSculley Thanks! That works!
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Re: Pack and go need to omit library parts
So, first you make it work, and then try to understand it?
From the example
http://help.solidworks.com/2020/english ... ple_vb.htm
So most of the things are being done with the array pgFileNames.
then near the end, you suddenly see pgGetFileNames
Why is there a redim for it?
And why did we suddenly change from pgfileNames to pgGetFileNames?
Thanks,
Carrie
From the example
http://help.solidworks.com/2020/english ... ple_vb.htm
So most of the things are being done with the array pgFileNames.
then near the end, you suddenly see pgGetFileNames
Code: Select all
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)
And why did we suddenly change from pgfileNames to pgGetFileNames?
Thanks,
Carrie
-
- Posts: 98
- Joined: Thu Mar 18, 2021 11:19 am
- Location: St. Louis, MO
- x 288
- x 56
Re: Pack and go need to omit library parts
Looks like they're just using another variable (pgGetFileNames) to gather the newly renamed file list, to display in your Immediate Window, to show that it's working. Notice they're only 'getting' the new filenames, without doing anything else with it? Not sure the ReDim is necessaryCarrieIves wrote: ↑Wed Aug 04, 2021 1:04 pm So, first you make it work, and then try to understand it?
From the example
http://help.solidworks.com/2020/english ... ple_vb.htm
So most of the things are being done with the array pgFileNames.
then near the end, you suddenly see pgGetFileNamesCode: Select all
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)
Why is there a redim for it?
And why did we suddenly change from pgfileNames to pgGetFileNames?
Thanks,
Carrie
Austin
- CarrieIves
- Posts: 163
- Joined: Fri Mar 19, 2021 11:19 am
- Location: Richardson, TX
- x 376
- x 136
Re: Pack and go need to omit library parts
I commented out the last section of debug.prints and the macro still works.Austin Schukar wrote: ↑Wed Aug 04, 2021 2:14 pm Looks like they're just using another variable (pgGetFileNames) to gather the newly renamed file list, to display in your Immediate Window, to show that it's working. Notice they're only 'getting' the new filenames, without doing anything else with it? Not sure the ReDim is necessary