Jump to content

Creating primitive groups with Python


alican

Recommended Posts

I am trying to create a primitive group with using a syntax something like this;

 

n = hou.node('/obj/geo1/grid1')

g = n.geometry()

p = g.createPrimGroup("myGroup") 

 

I get an error when I do the last line. What is the way to create primitive or point groups with python, if I just want that group to have all the prims/points in that geometry? 

 

Thank you for the help,

Alican Görgeç

Link to comment
Share on other sites

I assume you are doing this within Python SOP

if your grid is connected to first input of Python SOP then this should work:

n = hou.pwd()
g = n.geometry()
p = g.createPrimGroup("myGroup")
p.add(g.prims())

as Python SOP can only modify geometry that it owns, you can't modify geometry linked to an external sop

in theory you could as well freeze (hou.Geometry.freeze()) the geometry coming from custom sop path and modify that and merge (hou.Geometry.merge()) with current (possibly empty) geo, I haven't tried it though

Edited by anim
  • Like 1
Link to comment
Share on other sites

Thank you for your response. What if I want to create a shelf tool and want it to work with in that tool. Is there no way to make it work externally? Currently I am practicing python and trying to create a tool that collects all the SOP nodes that comes with an alembic or FBX import and merges them into single object merge node. I have done this part, bu then I want to split them out again after the object merge node with a delete sop according to the groups that I will be creating before putting them into the object merge node. Thanks again!

Link to comment
Share on other sites

- taking this as a python practice:

 

the data have to be stored somewhere in the scene or disk so you'd have to insert Python SOP with (similar code to above) into every line coming to merge so that every merged geo has it's individual group

but for that matter you would be rather creating/inserting Group SOPs if you want speed or attribwrangles if it as well entails more robust grouping

 

- from less Python needy workflow (however you can still build the setup with Python)

 

don't forget you can bring the whole alembic into sops with Alembic SOP and geo will have path attribute, that you can use to create your names and groups easily with a few SOP nodes

 

for FBX (or imported Alembic as objects) you can import it into flat hierarchy,

then create empty geo object and objectmerge the whole geo level at once using path like: /obj/importedfbx/*

or multiple levels: /obj/importedfbx/*/*/*

Object Merge has options to create individual groups for them or attribs so you can access corresponding geos later

Link to comment
Share on other sites

Oh i didn't know about those options :) . I thought it would be a good practice as well as something useful in the end. But thanks for your help. I will try those methods and try to push it for the sake of practicing.

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