2 Replies Latest reply on Sep 24, 2013 3:17 AM by Pierre Vergneault

    How to save a draw with its reference?

    Pierre Vergneault

      Hi everybody,


      I use a macro to make copy of opened drawings, but I can't manage to copy the part/assembly attached to this drawing.

      Here is my code:


      Dim swApp As SldWorks.SldWorks
      Dim swDoc As SldWorks.ModelDoc2
      Dim ext As ModelDocExtension
      Dim errors As swFileSaveError_e
      Dim warnings As swFileSaveWarning_e


      Set swApp = CreateObject("SldWorks.Application")
      Set swDoc = swApp.ActiveDoc

      Set ext = swDoc.Extension
      Call ext.SaveAs("C:\....", swSaveAsCurrentVersion, swSaveAsOptions_SaveReferenced, Nothing, errors, warnings)


      Is there another "save as" method? I can't find anything else interesting...


      Thank you!

        • Re: How to save a draw with its reference?
          Keith Rice



          I am not exactly sure what the "swSaveAsOptions_SaveReferenced" enumeration member does but it doesn't copy all of the components referenced by the drawing to the desired directory.


          I think what you're trying to accomplish requires Pack and Go. Use the IPackAndGo interface. I will note, however, that this interface has a lot of bugs so you might not be able to accomplish exactly what you need.


          There are several examples in the API Help, but for a more thorough example I would recommend you check out the example in our Macro Library called "Create pack and go with specified custom property as prefix".



          SolidWorks API Video Tutorials

            • Re: How to save a draw with its reference?
              Pierre Vergneault

              Thank you Keith


              Your code is very usefull, it is close to what I need.


              Using PackAndGo I succeeded in copying a file with its drawing (and components if it is an seembly)

              I used "SetSaveToName" and it worked properly.


              The only problem is that I wished to rename my new files, and I did not manage to use "SetDocumentSaveToNames" properly. I think I followed your code properly, but I keep on getting the answer "File already exists".


              So what I do now is a "save as" of each created file, then change their references, then delete all files created by PackAndGo.

              It works for Part files, I have to try it for Assembly files now. The code will be much longer than expected, but unfornately PackAndGo seems a little bit tricky to use...


              Good help anyway, thank you.