Skip to main content
12-Amethyst
June 18, 2025
Solved

How to access sub-routines in relations

  • June 18, 2025
  • 3 replies
  • 1260 views

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.

Best answer by mpsaju

Dear RPN

 

Thanx for your comments. My purpose is to convert the given dimension as decimal in the Hole notes (which are in string form), so that, when I call the HN or HN1 in the hole table when doing the 2D of the drawing, they come in their proper decimal form. Say for a hole of M5 thread, the pre-hole drill dia is 4.5(mm). If I call the drill dia in the hole note directly, it will be displayed as 5mm which is wrong info. It should be called in as 4.5mm. This little snippet does this beautifully, but if I have to write that bit of code every time for every parameter, it becomes a little clumsy. It would have been served better if it could be called as a sub-routine. Hence this post

 

Dear BenLoosli

Thanx for the info that it is possible to convert decimal values directly to decimal values in string form (Hole Notes) in Creo-11. I am at the moment using Creo - 10.5. I will try this shortly and come back

 

Dear KenFarley

 

Thanx for your comment that it is not possible to have sub-routines in Relations at the moment. But I still look forward to the time when it will be possible to do so. It would make a lot of my work easier, perhaps for other functions. (if I shift to Creo-11, perhaps it would be easier for this function!!) 

 

Regards

Saju

 

Thanx all

3 replies

23-Emerald III
June 18, 2025

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.

21-Topaz II
June 18, 2025

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.

18-Opal
June 21, 2025

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. 

 

mpsaju12-AmethystAuthorAnswer
12-Amethyst
August 18, 2025

Dear RPN

 

Thanx for your comments. My purpose is to convert the given dimension as decimal in the Hole notes (which are in string form), so that, when I call the HN or HN1 in the hole table when doing the 2D of the drawing, they come in their proper decimal form. Say for a hole of M5 thread, the pre-hole drill dia is 4.5(mm). If I call the drill dia in the hole note directly, it will be displayed as 5mm which is wrong info. It should be called in as 4.5mm. This little snippet does this beautifully, but if I have to write that bit of code every time for every parameter, it becomes a little clumsy. It would have been served better if it could be called as a sub-routine. Hence this post

 

Dear BenLoosli

Thanx for the info that it is possible to convert decimal values directly to decimal values in string form (Hole Notes) in Creo-11. I am at the moment using Creo - 10.5. I will try this shortly and come back

 

Dear KenFarley

 

Thanx for your comment that it is not possible to have sub-routines in Relations at the moment. But I still look forward to the time when it will be possible to do so. It would make a lot of my work easier, perhaps for other functions. (if I shift to Creo-11, perhaps it would be easier for this function!!) 

 

Regards

Saju

 

Thanx all

21-Topaz II
August 18, 2025

I would not hold out any hope for subroutines being implemented in relations. That would require a complete change to the processing method for the code. In particular, adding the capability of looping structures adds the possibility of infinite loops being written through careless coding or unanticipated variable states. Having Creo freeze up because you didn't realize a certain condition could arise would be nasty.