- Introduction to Scripts with the Plant 3D Report Creator
- Creating a Bill of Material Row Number in Plant 3D Reports
One question that we were able to work through in the past week was due to a breakthrough regarding using scripts in the Report Creator. The question of getting a row number in the Bill of Materials has come up on the forums before, but we hadn’t found a solution until last week.3D BOM with Row Numbers (83 downloads)
The solution involves a couple concepts. First, we’ll have to create a calculated field. Then we will have to create a script that makes the appropriate value for that field.
A calculated field is a field that does not get its information directly from the source of the report. Instead a calculated field can use expressions or scripts to create a value out of existing reports fields, or create a completely new value.
In the Report Creator, start a new report:
Base the report on the existing Plant 3D BOM.
Give the report a unique name and click Edit report layout.
Switch to the Field list, right+click and select Add Calculated Field.
Right-click on the newly added field and select Edit Calculated fields.
Change the Name (Mark), expand the Scripts row, click the drop-down for Get A Value, select New and then click Ok.
You should be taken to the Scripts Window which created a function for us at the bottom. The function is that part that starts with private void and ends with the last brace “}”.
Now, this script is in C#. Do NOT PANIC. We are going to add about 3 short lines that make the magic happen.
First a little background. I found instructions on how this function works on the GetValueEventArgs topic on the DevExpress site.
The important piece is where it shows us how to set the calculated field value (e.Value):
Here’s the script to enter in the function (and a little piece above it.
The rows that start with “//” are just comments to help explain what is happening. Outside of the function, we are storing a number that represents the current row that is about to be in the report (int rowcount = 1). When the report is generated, the calculated field we’re going to place will ask for a value. When it does, we are going to give it the value of the row we are on (e.Value = rowcount). After we set the value, we have to add 1 so that we can use it for the next row.
All the code lines end in a “;” which is C#’s way of letting the program know there is nothing else happening on the line.
That wasn’t so bad, was it?
Adding the Calculated field to the Report
Now that we set up the calculated field so it has the correct value, we need to put it in our report. In the far left cell, right+click, select Insert –> Column to Left.
Once the blank cell is in place, drag and drop our calculated field onto it.
Here’s what it looks like after I cleaned up the cell styles and fonts some.
In the report for downloaded below I also added the PartSizeLongDescription field to the grouping. Without this field in the grouping, the report doesn’t gather components correctly, and we’ve seen clients with flanges grouped together wrong.
Without further ado, the final report output:
And yes, I can’t resist putting our logo on stuff…BTW, that’s a hyperlink so you can put that to your companies logo and pull it from the web instead of embedding it.