Retrieve detail attributes and display them in overlay text

   2022   15   2
User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Hi,

I’ve made a small setup to do wedges and cached the result using TOPs, it’s working fine, and I’m happy with the result.
Now I’m working another setup to do flipbooks of the results and a mosaic montage, it’s almost done, the last roadblock I have is about the overlay text. I want to display the detail attributes on the overlay, because I store the wedges attributes (names and values) as detail attributes on my caches.
I wrote a python script to retrieve the detail attributes and print the result, for now, it’s working fine on a “static” geo, but it’s not working on the frame range, even with the “Evaluation Time” set to custom ($T). Nothing is printed in this case.
I’m not a python expert, I’ve made the code after a lot of try and fail, and search on the net and the forum, but I can’t figure out this last issue.

Maybe there is a better way to retrieve/collect the detail attributes to add them in the overlay text.
If someone has an idea

I join a hip file with just this part

Thanks
Ben

PS: We are on Houdini version 19.5.805 at work, so if you have a solution not using new node/code from v20, it will be perfect

Attachments:
TOP_python_script_rnd.hipnc (434.4 KB)

User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Hi,

I figure it out, sort of.
The python script evaluated the geo at frame 1 not matter what (my frame range start at 1001).
I fixed it by replacing

geo = hou.node(geo_path).geometry()

by

geo = hou.node(geo_path).geometryAtFrame(work_item.frame)

Now I just need to find the proper way to use it in a overlay text
I've seen this post explaining how to use python in an overlay [www.sidefx.com] , but for now I can't make it work with my code, it seems "work_item" is not defined in this context, so if someone as an idea of what to change to make it work in the overlay text.

Thanks
Ben
User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Ok, so I'm dumb.
Just replacing "wedgeattribs" by "detailattribs" in the code tpetrick gave does the jobs perfectly.
I don't need my python code in fact, at least I've learn a few things about python and tops so it's not totally a waste of time.
User Avatar
Member
9 posts
Joined: 2月 2017
Offline
I spoke too early, it'w working fine at home (Houdini 20.5.370) but not at work (Houdini 19.5.805).

I have this error inside the overlay text node

Attachments:
error.jpg (55.0 KB)

User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Hi,

I've fixed the typo for "workitemDep", replaced by "workItemDep", but I still have an issue, active_item doesn't seems to be defined

Attachments:
NoneType.jpg (54.9 KB)

User Avatar
Member
301 posts
Joined: 1月 2013
Offline
Hi,
Attach the scene to the post please, it will be easier to figure out the issue.
User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Here the last version of the scene

Attachments:
FX_Test_Wedges.hipnc (482.2 KB)

User Avatar
Member
275 posts
Joined: 9月 2012
Offline
Why are you creating the detail attribute outside Top, and attach it as an item process attribute?
It will be more straightforward no?
I haven't use python in the TOP ropoverlay, maybe also you have different version of Python between your 2 differents versions?

When doing wedge and so, PDG is relatively simple. But try to have HDA with multiples output, and link output dependency with other brick later is really not that simple and intuitive at all, something you could play easily in SOP by accessing any attributes, in TOP just doesn't work that way. And you could ended with lot's of file or bad memory management too.
Try to creat the attribute in TOP before , and after in the top overlay just add something like:
Building Variation: `@Nameextract`
Building Family: `@Category`
Vincent Thomas   (VFX and Art since 1998)
Senior Env and Lighting  artist & Houdini generalist & Creative Concepts
http://fr.linkedin.com/in/vincentthomas [fr.linkedin.com]
User Avatar
Member
9 posts
Joined: 2月 2017
Offline
I want to read and display detail attribute from a cache, not created before in the network.
In the case of test scene, I created some detail attributes in sop just to have something to read in the TOP network
User Avatar
Member
275 posts
Joined: 9月 2012
Offline
I see... In my experience, what i just mean, is the way you have to think a full setup in TOP has some particularities that force me to do some change in my approach. And some more important than i was hoping at first and also more time consuming.

You could also output a log file in sop per frame, and with partition , you could eventually pair the association with the output...
After sorry i have never tried the python approach you picked here...
Vincent Thomas   (VFX and Art since 1998)
Senior Env and Lighting  artist & Houdini generalist & Creative Concepts
http://fr.linkedin.com/in/vincentthomas [fr.linkedin.com]
User Avatar
スタッフ
600 posts
Joined: 5月 2014
Offline
For Python expressions you can use the pdg.workItem() global method to access the current active work item: https://www.sidefx.com/docs/houdini/tops/pdg/index.html#workItem [www.sidefx.com]

One caveat with this is that if you're evaluating the expression in the Houdini UI, i.e. not during a cook, there will only be an active work if you've actually selected one in the user interface. pdg.workItem() will be None in a fresh Houdini session for example, until a work item dot is selected in a TOP node. It'll always be set to the active task during the scope of a cook, either in-process or out-of-process.

If you're writing a Python expression that uses that method to access the active work item, you'll need to check if it's None and return some sort of default value in that case if you want your expression to work interactively. This isn't required for HScript expressions like @attrib because they internally default to returning 0 or empty string if there's no active work item in the evaluating thread.

In your file, you have other errors in your script that are causing the task to fail. After selecting a task to use for evaluation, the COP has the following Python evaluation error:

Error 
Unable to evaluate expression (
Traceback (most recent call last):
File "<stdin>", line 16, in expression
NameError: name 'vel' is not defined
(/obj/TEST/topnet1/overlaytext1/overlaytext)).

Your Python code is also not returning a value. The last line in your expression should be a return statement -- instead of print(attribs) you should use return attrib so the expression knows what the actual result is.

Finally, the Overlay Text COP expects to overlay text onto some kind of input image. It does that by loading the output file of the parent task, and applying COP nodes to write text onto the images. In your file there are no input files, so the Overlay Text fails to cook because it can't load anything. In order to get it working I added an OpenGL node as an input that renders the scene.

The attached file should cook/overlay the text values correctly.

Attachments:
FX_Test_Wedges_Updated.hipnc (553.2 KB)

User Avatar
スタッフ
600 posts
Joined: 5月 2014
Offline
Actually, as a followup, I've made some further changes to the file. Rather than trying to use a multi-line Python parameter expression, it's probably easier to just use a Python Script TOP. I also updated the code to use the new attribute API introduced in H18.0 onward.

Attachments:
FX_Test_Wedges_Updated2.hipnc (572.7 KB)

User Avatar
Member
9 posts
Joined: 2月 2017
Offline
Hi,

Thanks for your help, I didn't think using a python script before the overlay to create an attribute I can use easily on it, thanks for the tip.
I've made the change in my scene, but it's still failing, weirdly the state of the overlay text is "failed" but I don't have any error in the log, and inside in the COP the attributes are correctly display in the font node. So i'm not sure why it's failing.

see attachment for the new scene

Note : I want to keep the flipbook process independent than the wedges one, so it can be used to flipbook caches coming from different inputs

Attachments:
FX_Test_Flipbook_Wedges_v02.hipnc (1.5 MB)

User Avatar
スタッフ
600 posts
Joined: 5月 2014
Offline
It's failing because your Overlay Text doesn't have any input images. The Overlay Text TOP expects the incoming work items to have existing image outputs on them, and it overlays text onto those existing images. That's why I added an OpenGL ROP in my version of your .hip file.
User Avatar
スタッフ
600 posts
Joined: 5月 2014
Offline
The issue in the new file is that the Geometry Import is wired in after the ROP Fetch doing the render. The Geometry Import will overwrite the output file list, so the downstream Overlay Text doesn't see the input images.

You can set this up with an attribute copy to copy the specific attribute data you need from the Geometry Import, without overwriting anything upstream. Also, from what I can tell, it seems like you only actually only need to run 5 geometry import tasks. The values for the detail attribute seem to be the same for all frames, so they don't need to be imported 100 times.

I've updated the file so that the Geometry Import is wired directly into the wedge, an Attribute Copy is used to copy the attributes onto the renders.

One other thing to note is that you can inspect the inputs/outputs of a given item by Ctrl+MMB-ing on that work item. So for example on one of the Overlay Text work items, the MMB should show some sort of image file in the Inputs section.
Edited by tpetrick - 2024年10月17日 16:03:45

Attachments:
FX_Test_Flipbook_Wedges_v02_Fixed.hipnc (1.2 MB)

User Avatar
Member
9 posts
Joined: 2月 2017
Offline
It's working fine, thank you !
I've made a lot of mistake, but learn a lot. I just scratched the surface of the possibility of TOPs, but it's really great and fun to work with.
I still have a few things to fixed, the detail attribute doesn't seems to be refresh for each item on the geoimport for example, but I'm on the right path now.
Edited by bebenc - 2024年10月17日 16:49:22
  • Quick Links