Tips, Tricks, and Insight into Process and Power Software

Creating a Bill of Material Row Number in Plant 3D Reports

This entry is part 1 of 2 in the series Report Creator Scripts

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.

[Download not found]

 

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.

Calculated Fields

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:

SNAGHTML1dc2d2

Base the report on the existing Plant 3D BOM.

image

Give the report a unique name and click Edit report layout.

SNAGHTML1f2c3e

Switch to the Field list, right+click and select Add Calculated Field.

image

Right-click on the newly added field and select Edit Calculated fields.

image

Change the Name (Mark), expand the Scripts row, click the drop-down for Get A Value, select New and then click Ok.

SNAGHTML233bc8

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 “}”.

image

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):

image

 

Here’s the script to enter in the function (and a little piece above it.

image

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.

image

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.

image

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.

image

Without further ado, the final report output:

image

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.

Series Navigation