2 Replies Latest reply on Jan 8, 2015 4:58 PM by Marcos Nieto

    Editing a Macro Program

    Marcos Nieto

      Hello everyone!


      This is my first time creating/editing/debugging a Macro Program, so please bare with me.


      I am currently in the process of editing a Macro Program that I have created that saves a drawing into a PDF and DXF file simultaneously. However, when I run the program, it will save the PDF and the DXF file into my desktop, which is how I recorded the Macro originally. Here is how the line of code looks like:


      longstatus = Part.SaveAs3("C:\Users\MNieto\Desktop\Cube.PDF", 0, 0)


      longstatus = Part.SaveAs3("C:\Users\MNieto\Desktop\Cube.DXF", 0, 0)


      However, I would like to know if I can edit these two lines in where it will save the PDF and the DXF into the folder where the drawing is originally located and name the DXF and the PDF files how the drawling is originally named as.


      Any help will be greatly appreciated!


      - Marcos

        • Re: Editing a Macro Program
          Daniel Andersson

          The easiest way to do this is by using IModelDoc2::GetPathName and then manipulate that string a bit.

          Remove the last seven characters (which is the file extension and the dot that separate it from the file name) of the string and then add the wanted file extension.

              Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".PDF"


          Since you do not share any code, I assume that you have defined swApp As Sldworks.Sldworks = Application.SldWorks

          You most likely already have the swModel also defined...



          Dim swModel As SldWorks.ModelDoc2 'Assumed that you already got the swApp defined.

          Dim sPathPDF As String

          Dim sPathDXF As String


          Set swModel = swApp.ActiveDoc

          sPathPDF = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".PDF"

          sPathDXF = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".DXF"


          longstatus = Part.SaveAs3(sPathPDF, 0, 0)

          longstatus = Part.SaveAs3(sPathDXF, 0, 0)


          Or, if you want you can included it all in the line with the SaveAs3 method...

          longstatus = Part.SaveAs3(Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".PDF", 0, 0)

          longstatus = Part.SaveAs3(Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".DXF", 0, 0)


          Just let me know if you have any further questions.

          // Daniel