Jump to content

Using python to copy objects randomly upon points


hampuseh

Recommended Posts

Greetings!

I was wondering if there is a way with a Python script to be able to choose the source geometry library in Houdini (not from disk) and then choose the geometry randomly and copy to the points. 

To clarify,  I have a source of multiple geometries. Geo1, geo2, geo3, etc, which contains a different version of said object. So in this case I have 12 geometry nodes each with a different variation of a oak leaf. I know I can do this with for loop sops and such but I feel that having a script to do this would be quite nice.

 

Link to comment
Share on other sites

Thanks for directing me to the video.

It would seem that I lack the coding expertise to actually do my own version of the script. The script from the video is doing way more than what I would need. As all I would need is to be able pick the source library via a directory input in the python and then "simply" scatter the objects randomly across the points in which are input to the python node. 

I will try to work something out during the day. 

Thanks!

Link to comment
Share on other sites

An easier way would be to use VEX to build up a list of the object paths that you want to randomly copy, then write one of those paths to a point attribute on each point. This might be simpler to do than using Python, since you have the shortcut syntax available to bind attributes... it's a bit cumbersome to do that in Python.

Your VEX would look something like this:

string paths[] = {"/obj/objects/obj1", 
                  "/obj/objects/obj2",
                  "/obj/objects/obj3"};
int randnum = int(rand(@ptnum+ch("seed"))*len(paths));
s@instancepath = "op:"+paths[randnum];

You can then pass the result directly into an Instance SOP. Inserting the "op:" there in front of the path will allow the File SOP inside Instance to reference the correct geometry.

Incidentally, this "instancepath" attribute is going to be added to the Copy SOP in H18, so you might want to get yourself used to this sort of workflow.

  • Like 1
Link to comment
Share on other sites

Ah very nice toadstorm.
Yes this made much more sense, I was trying yesterday with Python but couldn't get my head around it really. 
What I am trying to do now is to make a list automatically of the source library so I don't need to manually type in every single variation of the object. 

I added a operator path as the source input of the wrangle:

string paths[] = {"`chs("source")`/"};

That makes me able to choose any object I desire, but the issue is I am not getting the whole list of available objects in the source. 
So this will be todays little fiddle!

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