5 Replies Latest reply on Apr 11, 2013 11:33 AM by Jacob Cordingley

    Document manger - Rename & Update references

    Ash Can

      I'd like to update the file names of all parts within an assembly, and update the referneces to all documents (other parts & drawings)


      I tried using the pack & Go api, but wasn't to succesful with getting the referneces for the drawings updated.


      Is this possible in the document manager? I coudn't find any VBA examples for the DM api.


      Is there any other way of hooking the explorere rename option that one can get in the right click contextual menu from Win explorer?




        • Re: Document manger - Rename & Update references
          Keith Rice



          The Pack and Go API interfaces are pretty buggy so I understand what you mean. I have received word that they will be fixed in SolidWorks 2014.


          You probably already know this, but you should never rename documents through windows explorer because this does not update references.


          The DM contains this API call: ISwDMDocument::ReplaceReference. It should accomplish what you want. Of course, you will first need to get the document containing the references that need to be changed. To do this you will use ISwDMApplication::GetDocument.


          The DM should be used with a stand-alone program. It is dangerous to use it while SolidWorks is open because you could easily have a case where SolidWorks and the DM are trying to modify the file simultaneously. Since VBA can only be used with macros, and since macros can only be used (with few exceptions) when SolidWorks is open, it is not recommended that you try to use VBA with the document manager. A stand-alone program using VB.NET or C# would be preferable. (You could use VB6, but this an obsolete language, which is why no examples exist for it.)


          If you need help beginning to use the document manager, I recommend this article.



          Video Tutorials for the SolidWorks API

            • Re: Document manger - Rename & Update references
              Ash Can




              I should clarify, I meant the Solidworks Explorer Reanme that you get when you right click on a part in Windows Explorer.


              I have been succesful in using the SwDMExternalReferenceOption.ExternalReferences call in getting all the referenced files in an assembly, and then using get document to read it's custom properties and renaming it.


              But, I found I wasn't able to do the same with a drawing document. Ie, find the part referneced in the drawing documetn using DM. Shall post the code I am using on Monday.I used a woraround using SW API calls, but would like to know how it's done in DM.




                • Re: Document manger - Rename & Update references
                  Jacob Cordingley

                  a few years ago i create a program to move file and fix the Ref from an ECR Folder to a Vault Folder


                  it should be about the same thing

                  first check to make sure noone has it opened


                  then use


                  iSwDMSearchOption = swDMApplication.GetSearchOptionObject();

                  int swDmMoveCopyError;


                  swDmMoveCopyError = swDMApplication.MoveDocument(fromName, toName, null, null, 1, iSwDMSearchOption);


                  then you will have to open the file

                  and update the ref


                  this part you might need to ask the user where it exists

                    string ReferenceToTemp;



                  iswDMDocument = (ISwDMDocument8)swDMApplication.GetDocument(toName, SwDmDocumentType.swDmDocumentDrawing, false, out swdocerror);

                                                          string[] reftemp = (string[])iswDMDocument.GetAllExternalReferences2(iSwDMSearchOption, out Refstatus);



                                                              string refpath = NetworkDriveLocation.UNCPath.GetNetworkPath(reftemp[0]);

                                                              if (refpath != ReferenceToTemp && ReferenceToTemp != " " && ReferenceToTemp != "")


                                                                  if (System.IO.File.Exists(ReferenceToTemp))


                                                                      iswDMDocument.ReplaceReference(reftemp[0], ReferenceToTemp);




                                                          catch { }


                  I can go into it more if you need to

                    • Re: Document manger - Rename & Update references
                      Ken Allbee

                      Hi Jacob,


                      I am not a programmer, but have run into a similar situation at my new employer.  I've been assigned as CAD Administrator (lucy me), and the powers that be want me to centralize all SW native files to selctected sub-folders.  It's a real pain to have to pack & go.  Can I simply move files using SW Explorer and keep all associations?


                      Also, can you explain your "program" a little more?  What/where do you write it and how to activate it?



                        • Re: Document manger - Rename & Update references
                          Jacob Cordingley

                          The above is just a small portion of my code


                          Pack and go is buggy and copy files  it not to move file there is Solidworks expolore that will rename files have you tried that.


                          what i do thought i  list all file in a folder these are  file that have been ECR  they select the files that are ready to be vaulted and then

                          I check the rev of the drawing to make sure there not a drop rev

                          then display the ref to so if it incorrect they can fix it

                          then they click continue and it will move the files and change the ref to then UNC path so there no network mapping issues


                          I wrote my program in Visual Studio  as an windows application