cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

The PTC Community email address has changed to community-mailer@ptc.com. Learn more.

Real to String in Relations

Real to String in Relations

I would like to have a Real to String function in relations. Our company standard defines the display of the dimensions of a part as a string parameter in our BOM;

T=6.35 100x500

In order to get this currently I have to write a very complex relation to extract the values from the models;

    

IF MODEL_THICKNESS < 10

TK=ITOS(MODEL_THICKNESS*100)

DIMENSION="T= "+ EXTRACT(TK,1,1) + "." + EXTRACT(TK,2,2) + " X " + ITOS(MODEL_WIDTH) + " X " + ITOS(MODEL_LENGTH)

ENDIF

IF MODEL_THICKNESS >= 10

TK = ITOS(MODEL_THICKNESS*100)

DIMENSION="T= "+ EXTRACT(TK,1,2) + "." + EXTRACT(TK,3,2) + " X " + ITOS(MODEL_WIDTH) + " X " + ITOS(MODEL_LENGTH)

ENDIF

Luckily we display our dimensions in mm, so I only have to support the imperial thickness of the materials.

17 Comments
DavorGranic
14-Alexandrite

Same problem here. Too many lines of relations to get the same result.

James62
10-Marble

Rtos function would be a huge timesaver for starters.

DomenicLaritz
16-Pearl

We developed a "real to string" function for relations with Pro/TOOLKIT.

Only some 10 or 20 lines of code were necessary to realize this.

@ PTC: It's so easy, why we're still waiting for that?!

RaymonDavies
6-Contributor

Not sure why we're waiting, as you said this should be a very simple request. I opened a request for this back in.... I would say 2004. It seems things have changed from their side, I don't see it in the SPR anymore.

jkent
3-Visitor

We ended up using JLink to create our real to string function.

fgermain
7-Bedrock

We are in the same case

We use relation:

     rtos_param=itos(floor(param))+"."+extract(itos((1+(param-floor(param)))*10000),2,3)

if param=2.05 rtos_param returns 2.050

for 4 digits after comma, use

     rtos_param=itos(floor(param))+"."+extract(itos((1+(param-floor(param)))*10000),2,4)

if param=2.05 rtos_param returns 2.0500

...

TomU
23-Emerald IV

Here is my three decimal place version.  This includes automatic rounding.  X is the real number and Y is the string.

/* String Output - No Leading Zero, Three Decimal Places

Y = ITOS(FLOOR(X+.0005))+"."+EXTRACT(ITOS(((FLOOR((X+.0005),3))-FLOOR(FLOOR((X+.0005),3))+1)*1000),2,3)

Other versions are available here: Converting Real Numbers to Strings

psobejko
12-Amethyst

Wow.  Still shaking my head about this one.

Keep voting Does PTC ever read these?

PTCModerator
Emeritus
Status changed to: Acknowledged
 
Jaime_Lee
Community Manager

I would like to have a Real to String function in relations. Our company standard defines the display of the dimensions of a part as a string parameter in our BOM;

 

T=6.35 100x500

 

In order to get this currently I have to write a very complex relation to extract the values from the models;

 

    

IF MODEL_THICKNESS < 10

TK=ITOS(MODEL_THICKNESS*100)

DIMENSION="T= "+ EXTRACT(TK,1,1) + "." + EXTRACT(TK,2,2) + " X " + ITOS(MODEL_WIDTH) + " X " + ITOS(MODEL_LENGTH)

ENDIF

IF MODEL_THICKNESS >= 10

TK = ITOS(MODEL_THICKNESS*100)

DIMENSION="T= "+ EXTRACT(TK,1,2) + "." + EXTRACT(TK,3,2) + " X " + ITOS(MODEL_WIDTH) + " X " + ITOS(MODEL_LENGTH)

ENDIF

 

Luckily we display our dimensions in mm, so I only have to support the imperial thickness of the materials.

TomU
23-Emerald IV

This product idea is nearly 10 years old and still hasn't received a single response from anyone in Creo product management.

 

To put this in perspective, this idea was created when Creo Parametric 1.0 M040 was current.  Since then we've seen Creo 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, and 8.0 (89 separate builds) come and go.  Other ideas have been implemented with only a single vote, yet this one with 192 votes (10th most voted idea) has not.

 

It would be great if someone from Creo product management, responsible for this area of the product, could reply to this idea with an explanation.  Why hasn't this idea been implemented at some point in the past 10 years?  Are there any plans to implement it in the near future?  Any feedback at all would be greatly appreciated!

PetrP
14-Alexandrite

Typical PTC. Instead of implementing "RtoS" command they give us complicated workaround and after 10 years expecting to archive this topic as "solved". I really don't know why they run this ideas comedy when not willing to implement it. Every "acknowledged" idea with 100+ votes should be implemented to next Creo version asap.

VMcD
12-Amethyst

Bump. I need RtoS

Andrew_410
8-Gravel

Bump. Simple RtoS function would be very helpful.

DomenicLaritz
16-Pearl

PTC, here's the Toolkit code - feel free to use it:

 

// Customized relation function "rtos"

ProError convertDoubleToString(ProRelset *pro_relset, ProMdl pro_model, char *extfunc_name, ProParamvalue *pro_args, ProAppData app_data, ProParamvalue *pro_result)
{
	pro_result->type = PRO_PARAM_STRING;
	if (pro_args[1].type == PRO_PARAM_INTEGER)
		ProTKSwprintf(pro_result->value.s_val, L"%.*f", pro_args[1].value.i_val, myRound(pro_args[0].value.d_val, pro_args[1].value.i_val));
	else
		ProTKSwprintf(pro_result->value.s_val, L"%f", pro_args[0].value.d_val);

	return PRO_TK_NO_ERROR;
}

ProError convertDoubleToStringArgscheck(ProRelset *pro_relset, ProMdl pro_model, char *extfunc_name, ProParamvalue *pro_args, ProAppData app_data)
{
	if (pro_args[1].type == PRO_PARAM_INTEGER && (pro_args[1].value.i_val < 0 || pro_args[1].value.i_val > 6))
		return PRO_TK_GENERAL_ERROR;

	return PRO_TK_NO_ERROR;
}

ProArrayAlloc(2, sizeof(ProRelfuncArg), 1, &args_array);
args_array[0].type = PRO_PARAM_DOUBLE;
args_array[0].attributes = PRO_RELF_ATTR_NONE;
args_array[1].type = PRO_PARAM_INTEGER;
args_array[1].attributes = PRO_RELF_ATTR_OPTIONAL;
ProRelationFunctionRegister("rtos", args_array, convertDoubleToString, NULL, convertDoubleToStringArgscheck, PRO_B_FALSE, NULL);
ProArrayFree(&args_array);

 

hheinze
6-Contributor

Hello PTC,

maybe you can implement this now, in 2023?
There is no need for 3D printing or Industry 10 dot ohhh, sometimes you have to work under the hood and dont polish the new version to make it even more shiny.

Work on the engine itself - please.

ArnaudVandeVeer
15-Moonstone
Status changed to: Under Consideration

This is under consideration for Creo 11