AnsweredAssumed Answered

api - pack and go - SetDocumentSaveToNames always return false -- when equations files are involved.

Question asked by Chris Reil on Dec 7, 2016

Hi All,

 

I have an addin I'm working on that is used to pack-and-go assemblies AND will also include other external files automatically.

 

I have been working with the 2014 libraries because there are 4 versions of Solidworks that need this so I'm using the oldest.

 

Everything seemed to be working OK until parts or assemblies with linked equation files were introduced.  The code below are the important steps - last one comes back false for assemblies with equation files.

 

abbreviated code steps.----------------------------------------

 

           swExt = ModelDoc.Extension

            ' Get Pack and Go object

            swPackAndGo = swExt.GetPackAndGo

      

            ' Get number of documents in assembly

            namesCount = swPackAndGo.GetDocumentNamesCount

            ReDim pgDstFilenames(namesCount - 1)

 

            ' Get current paths and filenames of the assembly's documents

            status = swPackAndGo.GetDocumentNames(pgSrcFilenames)

 

            ' Get current save-to paths and filenames of the assembly's documents

            status = swPackAndGo.GetDocumentSaveToNames(pgDstFilenames, pgFileStatus)

 

               '  this is where the renaming would take place in pgDstFilenames - but the array is not being touched here

 

            'set the destination after all the names are set

            status = swPackAndGo.SetSaveToName(True, myPath)

 

            ' Set document paths and filenames for Pack and Go -- this is a search and replace function

       

            status = swPackAndGo.SetDocumentSaveToNames(pgDstFilenames)

 

STATUS comes back false.   - ONLY when if a file has a linked equation ---

 

The P&G works but always to the original names.

 

 

IF I use the regular manual way on the same assembly (File, Pack & Go etc), it will allow me to rename files with equations and Pack&Go.

 

What am I missing here ??

 

I appreciate any and all replies ...

 

 

UPDATE -- Tried the 2016 DLLs with the same result.  As soon as a external equation file is added,  the SetDocumentSaveToNames returns false..

 

Pretty much makes the Pack & Go API useless for assemblies driver by external values.

 

Message was edited by: Chris Reil

 

Message was edited by: Chris Reil

 

OK -- finally solved the problem

 

The original problem is that GetDocumentNames INCLUDES the equations file if it is an external equation file.  Ok sounds reasonable but as soon as this files is included then we can't change the names of the files, not via prefix or suffix but with a search and replace.

 

So, the first thing to do if check all the file types (as some example show) but the trick here is to set the newfile name to blank for the equation file  AND include it in a list of other external files.

 

The whole point of our macro is to include other 'related' files that are not tightly linked but must travel together. Without the the equation file in the list used to SetDocumentSaveToNames() the other name changes are accepted.

 

Then just add the equations file back in with AddExternalDocuments(otherfiles) Since we have the list of equations files separated anyway, we also checked all the TARGET files (parts and assemblies) if there were any linked equation files and updated them also. This way the pack and go assembly can be relocated, prefixed, etc and fully renamed with search and replace) and it will also handle linked equations and relink them correctly.

Outcomes