Automate PDF report export in Polyworks using Macro script

Published by CMMXYZ on December 8, 2022

This video demonstrates the steps to export report in Polyworks manually and to automate the export using a Macro script.

Click Here to learn more about our affordable Software Support Packages - the same group that makes these Tech Tips!

Welcome to another Tech Tips video by CMMXYZ. In this video, let's see how to export reports in PolyWorks, both manually and automatically using a Macro Script at the end of a measurement sequence.

Here I have a PolyWorks CNC project with a report ready to be exported. There are multiple ways to manually export reports in PolyWorks. We can export the report by right-clicking on the created report in tree-view, Export, and export it as HTML files, image files, or PDF file. Or in Report Editor, we can go to File, Export Report and choose the file format. You can also use the PDF icon given in the Report Editor.

If you want to export the report table in Excel file, in Report Editor, select the report table and go to File, Export Items, and using the dropdown in the dialogue box, select Microsoft Excel.
This should save the table as an Excel file.

Now, let's automate this process of exporting the report using macro scripting. First, let's use the PolyWorks Command History pane to see how PolyWorks exports the report and then using script in the Command History to automate this process. To get the Command History pane, go to the empty area next to the Control Reviewer pane, right-click and select Command History. In Command History dialogue, we can see all the commands that were executed from the inception of this project.

Now, we need the command for exporting the report as pdf. So, let's go ahead and export this report in PDF format and save it.

You can now see a command for exporting the report as PDF has been generated in the Command History pane. Next, let's insert a macro script at the end of the sequence. In Report Editor, go to Insert Macro Script. An undefined Macro Script command will be added at the end of the sequence. Use the dropdown next to the command and create a new Macro Script.

Give a name for the script and click on Create. Then copy the code for exporting the PDF report and paste it in the script.

To give a unique name to the report, I'll use the piece name and the part name as the name of the report. To set the piece name and the part name go to Piece Properties icon. First, I'll set the part name by using the dropdown and selecting Project, enter a part name and close the dialogue. The command to set the part name appears in Command History. Copy the command in the created script and use the GET method by adding GET in the command line. After adding GET, we can see the argument for GET method. The first argument is the property name, which is the Part Name, and the second argument is the value, which is Machine Cover.

Instead of making the value as Machine Cover, we can generalize the script for other projects with different part name. To do that, instead of Machine Cover, introduce a variable, I'll call it Pname, and declare the variable above project properties GET command line.

Next, let's get the command line for piece name. Go to Piece Properties icon and enter the piece name. Close the dialogue. A command line will appear in Command History. Copy the command line to the script. Then add a GET method to the command.

Here the first argument is optional and can be omitted. The second argument is the property name, which is piece name, and the third argument is the property value. I'll remove the first optional argument, and to generalize the script for other projects, I'll introduce a variable and I'll call it Sname, and declare the variable.

Here, the command line will get the piece name of the current project and stores the value in Sname. Next, we have to add the two declared variables in the export command line. I'll rename the file name from Report Export to Pname and Sname. Use the dollar sign to add these variables.

I'm separating the two variables with a hyphen, and then I'm adding the extension for the file as .pdf. Save the script and execute the Macro Script in the Sequence Editor.

After execution, a PDF will be automatically exported to the part set in the script with the given names, which is the part name and the piece name. Now you'll be able to use the script by using the dropdown and selecting this script for different projects.

Related Articles

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram