AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

REPORT CREATOR, CALCULATED FIELDS - HOW TO TURN type field STRING INTO DOUBLE?

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
alexander..sokolov
2225 Views, 17 Replies

REPORT CREATOR, CALCULATED FIELDS - HOW TO TURN type field STRING INTO DOUBLE?

Hello! Please help me! In Report creator I want to calculate area of  sheet metall around tube (after insulation) and for that I need to use thinkness of insulation. Thinkness of insulation it's list in plant 3d for example: 30, 40, 60 .... AND IT'S HAVE TYPE FIELD - STRING, but with this type I can't make any expression, for example: [insulationthinkness]*2+[outdiametr]..... becouse, as I undestand, it have to be DOUBLE type..... and the question is: HOW CAN I CONVERT STRING INTO DOUBLE   for make any expression? 

 

I will be happy to get any advice!!!!)

 

Thanks!)

17 REPLIES 17
Message 2 of 18

The calculation can be done in Report Creator with a script:

 

private void cellTotalOd_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
{
	if (cellInsThk.Text == null)
        	return;
	if (cellOd.Text == null)
        	return;
	
	double insThkDbl = System.Convert.ToDouble(cellInsThk.Text);
	double pipeOdDbl = System.Convert.ToDouble(cellOd.Text);
	double totalOdDbl = (insThkDbl * 2) + pipeOdDbl;

	cellTotalOd.Text = System.Convert.ToString(totalOdDbl);
}

 Result:

Calc Example.PNG

Message 3 of 18

Thank you very much!!!)
Message 4 of 18
mcray100500
in reply to: jabowabo

Hello Jabowabo!

I have the exact same problem, but Convert.ToDouble doesn't work... 😞

I did everything as shown above and Report Creator wrote me error, that "Input string was not in the correct format".

What am I doing wrong??? Please help me!

 

Thanks in advance!

Artyom Khrapov
Refrigeration Systems and Technologies
Message 5 of 18

What is the value of your input string? You need to make sure it is only numerical characters - or you will have to trim out the other characters.
Message 6 of 18
mcray100500
in reply to: jabowabo

The values of my input strings are "25", "32" and "50".

Artyom Khrapov
Refrigeration Systems and Technologies
Message 7 of 18
mcray100500
in reply to: jabowabo

To check the "Convert,ToDouble" I did this simple example:

 

private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
{
	double insThkDbl = System.Convert.ToDouble(label3.Text);

	label5.Text = System.Convert.ToString(insThkDbl);
}

Result:

4.jpg

 

See more pictures in attachments

Artyom Khrapov
Refrigeration Systems and Technologies
Message 8 of 18
jabowabo
in reply to: mcray100500

Not sure what the problem is.  You may have a hidden character in your property such as a space or new line.  Try this (not tested):

 

private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
{
	string numStr = label3.Text;
	numStr = numStr.Trim(); // <-- this is the typical way to trim spaces, etc. in c#.  I assume it will work with report scripts.
	numDbl = System.Convert.ToDouble(numStr);
	newNumDbl = numDbl + 2; //<--do your math here
	string newValStr = System.Convert.ToString(newNumDbl);
	label5.Text = newValStr;
}

 

Message 9 of 18
mcray100500
in reply to: jabowabo

Jabowabo, thank you for your answer!

But I made some experiments and figured out, that spaces doesn't causes the error. If the "Insulation thickness" value is "_50" or "50_" and even "5_0", program calculates correctly and the error doesn't occur.(see the picture below). 

 

1.png

Script for this picture:

 

private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
{
	if (label3.Text == null)
        	 return;
	if (label4.Text == null)
        	 return;
	
	double insThkDbl = System.Convert.ToDouble(label3.Text);
	double pipeOdDbl = System.Convert.ToDouble(label4.Text);
	double totalOdDbl = (insThkDbl * 2) + pipeOdDbl;

	label5.Text = System.Convert.ToString(totalOdDbl);
}

 

 I found, that the error occurs when the "Insulation thickness" value is empty. But I don't understand why this is happening, because I thought, that the "if(label3.Text == null) return;" should solve this problem. Or is this not as?

 

Artyom Khrapov
Refrigeration Systems and Technologies
Message 10 of 18
jabowabo
in reply to: mcray100500

Try this:

if (System.String.IsNullOrEmpty(label3.Text))
        	 return;
if (System.String.IsNullOrEmpty(label4.Text))
        	 return;

 

Message 11 of 18
mcray100500
in reply to: jabowabo

Yes! It work!

Thank you very much!

Artyom Khrapov
Refrigeration Systems and Technologies
Message 12 of 18
jamie.norbury
in reply to: jabowabo

Having a similar problem with the above.

 

Doing a calcualtion for velocity. When trying to convert the maxflow.Text to a double I get an error that the input string was not in correct format.

 

The cellSize.Text works fine. Both are strings.

 

 

 

private void maxvelo_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e) {

 

double cellSizeDbl = System.Convert.ToDouble(cellSize.Text);

double maxflowDbl = System.Convert.ToDouble(maxflow.Text);

double totalDbl = (maxflowDbl / (((cellSizeDbl/1000)* (cellSizeDbl/1000)) / 4 * 3.142)) ;

maxvelo.Text = System.Convert.ToString(totalDbl);

}

Message 13 of 18
jabowabo
in reply to: jamie.norbury

Are you checking your cell values with 'IsNullOrEmpty' before passing them to the ConvertToDouble?

Message 14 of 18
jamie.norbury
in reply to: jabowabo

Thanks. Missed that on previous post.

 

Is there a way to leave the result as blank if one of the field is empty? Also to limit the number of decimal places?

 

Thanks in advance for your help.

Message 15 of 18
jabowabo
in reply to: jamie.norbury

Something like this (not tested):

 

// check if empty values
if (System.String.IsNullOrEmpty(cellSize.Text) || System.String.IsNullOrEmpty(maxflow.Text))
{
     // leave cell blank
     maxvelo.Text = "";
}
else // values are not empty
{
     double cellSizeDbl = System.Convert.ToDouble(cellSize.Text);
     double maxflowDbl = System.Convert.ToDouble(maxflow.Text);
     double totalDbl = (maxflowDbl / (((cellSizeDbl/1000)* (cellSizeDbl/1000)) / 4 * 3.142)) ;
     // round t two decimal places
     double totalDblRnd = Math.Round(totalDbl, 2);
     maxvelo.Text = System.Convert.ToString(totalDblRnd);
}
Message 16 of 18

Hi guys!!

How can I take the value of a calculated field and assign to a cell?

It seems hard to me figure it out

Message 17 of 18
jabowabo
in reply to: mikael.santospj

You can assign script values via the Properties of the cell.

 

jabowabo_0-1704725176539.png

 

Message 18 of 18
mikael.santospj
in reply to: jabowabo

Hi, I still don't figure it out how those scripts works. I see things "Before Print", "After Print", Data Source Demand....

I wasn't ble to find any documentation.

In this example, I am trying to assign the project number to cell90 via script.. just an example:

 

private void tableCell90_SummaryCalculated(object sender, DevExpress.XtraReports.UI.TextFormatEventArgs e) {
tableCell90. = General_Project_Number.Value.ToString();
}

not working

There is no debug information. the help is forum and a bit of Google search.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost