Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
I have a number of relations based udfs for creating manifold block designs. All the logic is built using Relations in Creo-Parametric. There is a specific logic I have built around transferring dimensions in decimal form (say 3 decimal places) to a 3D hole-note written with relations, so that the hole note shows the 3 decimal places. (Usually, when transferring to string form, Relations only transfers the integer part of the dimension) I have a work around for this, which works well, but then, every such hole, has to have the logic built in its relations.
Is it possible to have this common logic as a subroutine, written in the part relations , which I can access, every time I want to increase the decimal places ? I can call this subroutine with the value, number of places I want to show so that the sub-routines returns a string value with the correct decimal places.
This is the relations program for a counter bore dia with 2 decimal spaces and a counter bore depth with 3 decimal spaces.:
x=itos (CBORE_DIAMETER*10^2)
l=string_length(x)
if(extract(x,(l-1),2)=="00")
y=extract(x,1,(l-2))
else
if(extract(x,l,1)=="0")
y=extract(x,1,(l-2))+"."+extract(x,(l+1-2),1)
else
y=extract(x,1,(l-2))+"."+extract(x,(l+1-2),2)
endif
endif
c="."
if (acc<1)
c=""
endif
a=itos(CBORE_DEPTH*10^acc)
l=string_length(a)
b=extract(a,1,(l-acc))+c+extract(a,(l+1-acc),acc)
/*" ?" is the symbol for dia. in the 3D note
HN1="S.Face"+" ?"+y+" - "+b
Please note that "HN1" is what is called in the 3D Note
This works pretty well for each hole individually. But one can notice that this bit of program would be more efficient, if used as a sub routine.
What version of Creo are you using?
With Creo 11, there is now a rtos function that eliminates the trickery of converting a real number to a string for use in notes.
There is no capability of defining subroutines or any looping logic in relations. Relations are an analogue of reading a tape; all commands are executed once, line by line from top to bottom.
First and as long I remember, the number of decimals can be driven by special format specifier in Creo, check the Doc and I guess for 3D drawings this should work.
second, you may know this already, but just in case.
If you need 2 decimals from 14.35673
multipy this by 10^2 (the power of this 2 decimals = 100 😉)
the result is now 1435.673, to round add 0.5
Now you have 1436.173
Convert to an integer would give 1436
At least divide back by 10^2 and you get
14.36 (If you Substract the int of this you will get 0.36, just in case).
This works for any number of positive decimals and even 0! and Negativs to cut🙃
All can be written in one statement
like (with dot for dash, No idea for the English words, for this German statement 😅😅😅)
RealValRes = int(RealVal*10^NOD+05)/10.0^NOD
NOD = Number of Decimals
In the relation menu try Eval of the right hand expression, to see the outcome.
Just use the correct function in Creo and replace int = floor as far I remember.
For this there is no string conversion required.