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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Dimension to Description Relation

SEaswaran2
9-Granite

Dimension to Description Relation

I am creating family table components. The probelem I have is that, I cant enter description for all instances of family table, so i created a relation like

DESCRIPTION=" BOLT DIA &DIAMETER IN , &LENGTH IN LONG"

so that it will display like,

BOLT DIA 1 IN, 2 IN LONG

Instead it displays like, BOLT DIA &DIAMETER IN , &LENGTH IN LONG in the description.

Can someone say whats wrong with the expression ??

 

Thanks,

Santhosh

9 REPLIES 9

The double quote tells the relation to use the literal characters instead of interpreting them as parameter flags.

 

You need something like DESC = "THIS IS " + &LENGTH + " A TEST"

 

Edited later - "&" is not needed and Creo won't convert a Real to a String. I confused it with the way Drawing Notes work.

 

<rant> It's easy to forget that Creo is one of the few languages besides 6502 Assembler that is unable to make this conversion. Thousands of languages have been created and the only ones without it are ones without any floating point support at all. It's an amazingly brutal oversight, given how much this lack of conversion from Real to String and String to Real hurts users of Creo Relations. It's like there was a meeting and this was purposely done, though I have no good guess as to why. </rant>

If I use DESC = "THIS IS" + &LENGTH 

it displays "Invalid data type combination at right side of expression"

You can't mix types in an assignment statement.  You need to convert the value from a real number to a text string. Unfortunately, Creo and ProE before it has consistently provided no simple "real to string" function. 20+ years in the business and they don't give us a simple freshman year programming problem solution. What we do have is a function to convert an integer value to a string, and a means of extracting a portion of a string. With these two and some logic we can "build" the string we want.

Let's assume you want a real number with three decimal places. Here's how I'd get a string from the actual value, in relations code:

 

--- [ Begin Relations Code ] ---

 

numDigits = 3

/*

/* Get the integer portion of the number. Negative numbers have to be

/* handled differently because of the need for "floor". floor ( -1.9 ) = -2, which

/* isn't what we're looking for.

/*

stringValue = ""
IF realValue < 0.0
  stringValue = stringValue + "-"
ENDIF
IF ABS( realValue ) < 1.0
    stringValue =  stringValue + "0."
ELSE
  stringValue = ITOS ( FLOOR ( ABS ( realValue ) ) )  + "."
ENDIF

 

/*

/* Now, add on the desired digits after the decimal place.

/*

stringValue = stringValue + EXTRACT ( ITOS ( 10^numDigits * ( 1 + abs ( realValue ) - floor ( abs ( realValue ) ) ) ), 2, numDigits )

 

--- [ End Relations Code ] ---

 

That's a lot of stuff to do a "simple" conversion, but there you go.

BenLoosli
23-Emerald II
(To:SEaswaran2)

You do not need the & before the parameter in a relation.

DESC = "THIS IS" + LENGTH 

It's not just the "&", you can't add a numeric value to a string. If only it were that easy...

psobejko
13-Aquamarine
(To:SEaswaran2)

Well, the problem is you are assigning the literal value " BOLT DIA &DIAMETER IN , &LENGTH IN LONG" (because of the quotation marks) - to the string type parameter DESCRIPTION.

I think in Creo relations, in order to join strings together, you have to use the + operation, like this:

DESCRIPTION="BOLT DIA" + itos(DIAMETER) + "IN., " + ...


Also see:

How-to-adjust-decimal-places-in-a-parameter

Parameters-and-relations

 

There is a more comprehensive list:

 

https://community.ptc.com/t5/Creo-Modeling-Questions/Converting-Real-Numbers-to-Strings/m-p/189624

 

PTC missed the boat on this. There are two ways to go in every other programming language. Either provide a Real to String conversion with an optional decimal control -OR- provide a String to Real conversion so that the values can be pulled from the Description. PTC took the middle road and did neither.

TomU
23-Emerald IV
(To:SEaswaran2)

These are always fun to do.  Smiley Happy  Here is a fully functional code block.  This is based on the dimensions being named LENGTH and DIAMETER.  You will need to change the code if they are actually named something different.  Let me know if you have any questions.

 

/* Logic to convert DIAMETER and LENGTH to strings
/* and then include them in the DESCRIPTION parameter.

/* Number of Digits
ND = 3

/* Convert LENGTH
LEN_STR = ""
RN = FLOOR((LENGTH+(5/10^(ND+1))),ND)
IF FLOOR(RN) == 0
    LEN_STR = "0."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(ND)),2,ND)
ELSE
    LEN_STR = ITOS(FLOOR(RN))+"."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(ND)),2,ND)
ENDIF

/* Convert DIAMETER
DIA_STR = ""
RN = FLOOR((DIAMETER+(5/10^(ND+1))),ND)
IF FLOOR(RN) == 0
    DIA_STR = "0."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(ND)),2,ND)
ELSE
    DIA_STR = ITOS(FLOOR(RN))+"."+EXTRACT(ITOS((RN-FLOOR(RN)+1)*10^(ND)),2,ND)
ENDIF

/* Generate DESCRIPTION
DESCRIPTION = "BOLT DIA " + DIA_STR + " IN, " + LEN_STR + " IN LONG"

Awesome i have been looking for this formula for long time.

Thank you @TomU I Appreciate the effort and solution.

Announcements
NEW Creo+ Topics: Real-time Collaboration


Top Tags