Macro to pack and go selected document?

Shown as picture above, I want to write a macro to only pack and go the parts/document I want(by telling the api what name the files are). I need a api, that if you put file names in it, it will remove the document with the name so it won't be packed.

Any ideas?

Many thanks

SolidworksApi macros
Answers 7
AT
AT 2016-02-16 Best Answer

You need to use this method: 2014 SOLIDWORKS API Help - SetDocumentSaveToNames Method (IPackAndGo) . According to the API help:

<p>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 <a>IPackAndGo::SetSaveToName</a>.</p>

Thanks,

Artem

CF
CF 2016-02-17

Hi Artem, I am getting close. but I got this error

As printed below, the pgSetFileNames Array is what I want, that the three files I don't want to pack and go has been changed to "" (empty)

Yet when I try to get this array into swPackAndGo.SetDocumentSaveToNames() Method, the status returns false and it cannot save at all.

Any Idea?

comment imagecomment image
AT
AT 2016-02-17

Take a look at this example: 2014 SOLIDWORKS API Help - Add and Remove Files from Pack and Go (VBA).​

Try to find the differences with your macro.

Thanks,

Artem

AT
AT 2016-02-17

Hi Charlie,

Here is another example which works for me: #CODE|Exclude files from Pack-n-Go

It looks like the path you are specifying in the SetSaveToName must be a full file path to the output .zip (not just a folder).

Thanks,

Artem

CF
CF 2016-02-17

Hi Artem,

The file I try to remove is a part file, in those examples they are are some xml files that may not relate to the assembly.

I tried with the second example you just given me, yet the out put and code is like

Note there is still "False" in the status, This thing will save but the result still have the "aluminium post fixings.sldprt" part file in the pack and go folder.

Can this method be used for part files at all?

Thanks

comment imagecomment image
CF
CF 2016-02-17

This one works, but yes it is just a zip file. I will try if I can put suffix on it, this is important for me...

CF
CF 2016-02-17

OK, You got your score.

It can still include drawing and apend suffix on file names. I found bunch of bugs when I try to write a loop to generate 10 copies with different names. But all bugs have work around. Still a big room for "pack and go" function to improve.

If you found any improvements in the future kindly let me know.

BTW, not as fast as I thought.

Thank you very much for your help