Jump to content

Python operator for listing and loading files


ben

Recommended Posts

Hi,

I'm working on an OTL and I need the user to be able to choose sets of objects from directories.

So I've tried to do a custom python operator and I'm very close to what I need.

- specify a directory

- check obj and or fbx

- a list is populated

- object is loaded according to the user choice.

post-5378-129915793213_thumb.jpg

( SOP : TabMenu/Import -> ListFiles )

thx

ben

ListFiles.otl

Link to comment
Share on other sites

No it happens even with very low geometry.

Usually first time you pick something in the list it's ok but then if you change your choice it's kind of random.

Thanks for trying it.

Link to comment
Share on other sites

Sometimes you can have issues with script driven menus not always refreshing when you'd like and whatnot, but there are a couple things you can do. If you call hou.Parm.menuItems() on a menu parameter it will cause the script to reevaluate and be up to date. If you do this in the cook code it should ensure that if a valid file is available it is loaded. Also you can force it to update properly, at least visually when you change your directory or toggle the file types.

One thing I noticed that might also be causing problems is that you build the list of files in the menu parameter, but then build it again in the cook code. If you build it just once in the parameter then get the file from there after ensuring it's update you might get less problems as well.

Attached is a quickly modified version where I've done some of the things I mentioned above. Also, to add a little more flexibility and such I've modified it a little so that it builds the list of file extensions to check from the parameter interface itself. If you want to add any other available extensions all you need to do is add a parameter "ext_whatever" where whatever is the name i.e "ext_obj" and it will automatically add any .obj files to the list if they are toggled on. Be sure to copy the callback script which just ensures the menu is properly rebuilt when a toggle is toggled. I also threw in some error checking to be safe.

No guarantee it will solve the problem but it's worth a shot.

ListFiles.otl

Edited by graham
Link to comment
Share on other sites

Thanks a lot Graham !

Your script is really clean and nicely commented, I'm learning a lot from it.

Unfortunatly it doesn't solve the main problem but I don't give up.

I haven't downloaded the tool to check it out, but it sounds like your issues might be system I/O related rather than a Python issue. For example if the files being loaded are on a network drive then network connectivity might be intermittent (conflicting DNS, bad switch, bad NIC, etc.). Try from a local drive if you haven't already.

Link to comment
Share on other sites

Luke : I'm loading from local drive. I've just tried from another faster (10000rpm) drive and it's just the same.

Graham : There's no specific hip file right now. I just need to make this simple one to work before embeding it in bigger OTLs .

---

strange ...

I've just realise that exactly the same is happening using a fileNode (randomly need to hit Reload Geometry few times).

It's weird, and it's new, everything was fine before...

Right now I'm on 10.0.581 (win64), I'm going to try all of this on an other PC.

Thanks everyone for having a look at it.

Link to comment
Share on other sites

To conclude :

I've just tried it at home on my mac (same H release .581) and it works fine (with both my otl and graham one) ...

Still strange because the node takes about 550ms to cook on my PC at work and "only" 150ms less on mac at home.

I dont't know but I guess my problem was more a hardware issue (slow or fragmented hard drive maybe ?)

Anyway this was my first try with HOM and i've learn new stuff today.

Special thx to graham.

ben

Link to comment
Share on other sites

Glad it's working out now. One thing I noticed after testing my version a little bit is my callback scripts on my node that were meant to refresh the menu on toggle changing weren't working out as well as I'd hoped. A better solution is to change the callbacks for the toggle and directory to be 'hou.pwd().cook(True)'. This works a bit better because it causes the entire node to recook and thus causes the menu to properly refresh before hand and makes it so no matter how often the toggles change or whatever the menu is always accurate.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...