Getting radius of text during rendering
-
I am able to get the bounding box of text with .GetRad() and it works nicely in the viewport. However, when I render my radius goes to zero. I created a simple scene to show the problem. Rad_NotUpdatingRender_01.c4d Is there any hacks to get the radius working in render?
In a python Generator
import c4d #I'm trying to get the bounding box of each text object working in the renderer #The viewport works fine, but when I render the 'widths' list goes to [0,0] children = op.GetChildren() widths = [] #loop through children (text objects) for i in range(len(children)): #get the radius of each child radius = children[i].GetRad() #bbox = c4d.utils.GetBBox(children[i], children[i].GetMg())[0].x #build list of widths. widths.append(round(radius.x)) print(widths) def main(): #send width list to another object to see in the render op[c4d.ID_USERDATA,1][c4d.PRIM_TEXT_TEXT] = str(widths) return
-
Hi @gsmetzer ,
Thank you for providing the scene that shows the problem!
Your code in the Python generator should be scoped with functions and classes. The code outside of main() function is only run once. Please also make sure you're familiar with cinema threading restrictions: Threading Manual.
Once you cover the code into a separate function it starts working (check the code below). Although, you are kind of misusing the python generator object (as it doesn't generate any cache). The Python Tag could probably be a better fit here.
Another note is that although changing other object's attributes is somewhat acceptable, you can still fall into a trap of changes being delayed, because of lacking the recalculate pass after you've changed the value. It might be worth trying to store your text in a user data attribute of python generator. And for the text object just create an xpresso tag that drives the text value from the string in the user data attribute of python generator. This way you can fine tune the execution priority order: documentation.
One more thing. I've also received the missing font error upon loading your test scene, make sure it is fixed to have the code working.
Cheers,
IliaCode for your python generator:
import c4d def foo(): children = op.GetChildren() widths = [] for i in range(len(children)): radius = children[i].GetRad() widths.append(round(radius.x)) return widths def main(): op[c4d.ID_USERDATA,1][c4d.PRIM_TEXT_TEXT] = str(foo()) return