3 Replies Latest reply on Jan 11, 2017 6:05 PM by Shane Suffolk

    Modify output path in Office to PDF task

    Shane Suffolk

      Hello all,

       

      For our Solidworks files, we currently use a modified Convert task to save the PDFs to a different folder than the native file by altering the Advanced Scripting Options in that task, according to S-046146 in the KB.

       

      In short, this revolves around adding the following line into the Advanced Scripting Options in the Convert task:

      convFileName = Replace (convFileName, "portion of the native file path", "portion of the destination file path")

       

      As I've recently upgraded PDM to 2017 SP1 to make use of the handy Office to PDF task, I'm hoping to modification this Office task in a similar way. Unfortunately my coding skills are basically non-existent.

       

      So, is there someone out there that can help me to modify the Office to PDF task to create the equivalent?

       

      PS. Using the standard functionality in the output folder in the Office task isn't working in this case as our folder structure only differs slightly as per the following:

      Native files is located in FolderA\FolderB\FolderC and the PDF should go to FolderA\FolderX\FolderC. This is why I like to code something to modify the output path by replacing FolderB with FolderX.

        • Re: Modify output path in Office to PDF task
          Martin Solem

          Hi Shane,

           

          By any chance, is the "folder x" a variable on the source file data card, then you can use that information in building the PDF output path.

           

          Maybe not the best example, but it took little effort to test and the concept should be clear:

          My project folders consists of two variables, project number and project name, like 2017-0003 Body Kit.

          The files i put in this project will inherit those values to their data cards.

          When i run PDF task on a Word doc, these values will be part of building the output folder path, so in Task setup it will look like:

          <RootFolder>\Projects\<%Project number%> <%Project Name%>\Documentation\PDF\<FileName>

          Where the values within %% are my "folder x".

           

          Anyway, just an idea

            • Re: Modify output path in Office to PDF task
              Shane Suffolk

              Hello Martin,

               

              Thank you for your response.

              Unfortunately, 'Folder X" isn't a variable at the moment. And to complicate things, "Folder C" could have subfolders with subfolders in it. Also, "Folder C" could be "Folder E", "Folder F, etc. So basically the only fixed folders are "Folder A", "Folder B" and "Folder X".

              I could look into using variables to drive the output path, as your suggest, but because of the previous it's going to be a bit challenging to derive the folder structure under and name of "Folder C", so to speak, unless all folders are assigned a variable perhaps.

               

              This all can be avoided if with a couple of lines of code that replace "Folder B" with "Folder X".

               

              Any coding gurus out there?

            • Re: Modify output path in Office to PDF task
              Shane Suffolk

              So, I've made some progress but it's still not quite resolved yet.

               

              In the Advanced Scripting Options I've added the following lines of code at the location shown in the attachment:

              Office to PDF_Extra lines location.jpg

              'Build destination filenames

              Dim Ext = Path.GetExtension("<SourceFileName>")

              Dim Path1 As Object = Path.Combine("<SourceFolderPath>", "<SourceFileName>")

              Dim convFileName As Object = Path1.Replace("Folder B", "Folder X").Replace(Ext, ".pdf")

               

              I'm sure there are better ways to do this but this creates the desired filepath including the filename.pdf

               

              Then, I've replaced all occurences of "<OutputPath>" in the rest of the script with convFileName.

               

              So, the result is that the task creates the pdf in the desired location but it leaves it checked out with no data card variables copied to the pdf.

              The task shows up in the task list as failed and the error log gives me the following error:

               

              Error: The supplied object ID is not valid

               

              Would anybody have an idea what causes this error? I feel like I'm so close to resolving this