Jump to content

Introducing sQuery - a jQuery-like library for Houdini


Recommended Posts

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:

 


 

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 by hibernationTheory
  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

@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!

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...