hibernationTheory Posted January 25, 2015 Share Posted January 25, 2015 (edited) Hey guys! Meet sQuery, a jQuery-like library I have been developing for easy scene queries and modifications in Houdini. You can download and read more about it on github: https://github.com/hibernationTheory/sQuery sQuery provides an easy-to-use interface to perform complex scene queries and modifications over your scene. Better to show an example than to try to explain: After importing the module, you would initialize it for a context. sq = sQuery.sQuery("obj") Here is a simple example: sq.children("*house*").filter("t#instance").children("t#alembic").replaceAttrValue("filename, "v002", "v003") # for all the children of the object context that has the word "house" in it filters those that are of type 'instance', gets the alembic nodes inside them and replaces the v002 in their filename attr value to v003. Here is a more complex example: sq.children("*geo*").remove("*HOUSE*).filter("t#instanc*").children("t#alembic [filename~=main]").replaceAttrValue("filename", "v002", "v003") .setUserData("is_altered", "true").addToBundle("alembics_inside_instances").layout().next("t#switch").createNodeAfter("delete", {"group":"*_arms_"}).toggle("affectnumber").select().setColor("red").move(-10, -10) """ gets all the children in obj context with name that matches to the *geo* pattern, from that removes those that have the word *HOUSE* in it, from the result filters those whose type name matches to the *instanc* pattern, chooses the alembic type children of the result for which the filename value contains the word "main" in it. replaces the 'v002' on the alembic nodes filename parameter with 'v003', creates a user data on them called "is_altered" with the value "true" and adds those alembics to the bundle "alembics_inside_instances", lays them out (layoutChildren on the nodes) and selects the next node if it is of type switch and creates a delete node after them with the 'group' parameter set to '*_arms_*', toggles the affectnumber parameter on this delete nodes (meaning if it is on, makes it off or vice versa) and then sets a viewport selection on these 'delete' nodes that were created, also sets their color to red and moves them to -10 at x and -10 y. all in a single line. """ Let me know what you think of it. Thanks! Edited January 25, 2015 by hibernationTheory 2 Quote Link to comment Share on other sites More sharing options...
pezetko Posted January 25, 2015 Share Posted January 25, 2015 Pardon me if it's stupid question. But have that spaghetti (too long) code have any benefit? Could it be divided into couple of commands, or there is some penalty for doing so? Like getting filtered objects. Then select instance type. Then on another line do the replacing. Then on next line do the bundle etc. But it looks handy, thanks for sharing. 1 Quote Link to comment Share on other sites More sharing options...
hibernationTheory Posted January 25, 2015 Author Share Posted January 25, 2015 Hey, thanks for checking it out! That example is for demonstration purposes only; to show how concise and legible a sQuery command can be for an otherwise complicated operation... and also to showcase the API a bit which I haven't properly documented yet If you are running it from the shell and if that is exactly the operation you want to do, then you might go for it in one line using chaining like this. But obviously if you using this in a script there is benefit in piecing it up to have results stored in variables for re-usage or for easier debugging. Thanks! Quote Link to comment Share on other sites More sharing options...
edward Posted January 26, 2015 Share Posted January 26, 2015 Shouldn't replaceAttrValue be replaceParmValue? 1 Quote Link to comment Share on other sites More sharing options...
hibernationTheory Posted January 26, 2015 Author Share Posted January 26, 2015 @edward : haha good point. I wanted to have an API that is application agnostic for common operations since I want to make this library available for different packages as well. So in a Houdini context "parm" makes sense, but in other applications this can be called something else right? So I went with .attr for two reasons: - jQuery library uses the keyword .attr since it deals with HTML attrs. - Maya calls parameters attributes, so does Nuke. Do you think that's a bad call? Should it be" replaceParmValue" for Houdini and maybe "replaceAttrValu"e for a different software package where parms are called attrs? Thanks for the feedback! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.