Quantcast
Channel: Report Creator Scripts – Process Design, from the Outside

Introduction to Scripts with the Plant 3D Report Creator

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

Recently in a training class, I found out that you can use script with the Report Creator.  A user asked how to convert decimal numbers to feet and inches, and while seeing how the 3D Parts report was setup, I ran into scripts.

Scripts lie in a gray area about half-way between real programming and advanced users functionality.  They’re typically too loosely developed (no strict, architecture) to be considered development, but too technical for most users. Incidentally, that’s where a lot of us get into development, because we learn how to harness script power.

The report creator is built from a set of tools developed by a company called DevExpress.  DevExpress makes a living by building development tools.  Companies like Autodesk buy developer tools because it’s much cheaper than writing it themselves, and generally provides broader features and more stability.  It’s a great way to add a lot of functionality by doing a minimal amount of work.

Dev Express provides documentation on the report creatore here: http://docs.autodesk.com/PLNT3D/2013/ENU/report_designer.pdf

The documentation for the api is here: http://documentation.devexpress.com/#XtraReports/clsDevExpressXtraReportsUIXtraReporttopic

The search bar on the api documentation works well, so be sure to use that if you can’t navigate to an object.

Generally, the script functionality is limited to reacting to specific events which is perfect for us.

Scripts can be written in a variety of languages like C#, Visual Basic, or J# (Report Designer, p. 296).

We will look at using scripts with the report creator in the next couple of posts as we learn how to add a row number to bill of material items, and how to format decimal numbers to feet and inches.


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

$
0
0
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.

How I Start A Vessel in PV Elite (0 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.

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.