Jump to content

possible convert/create point group to prim group in python??


efx

Recommended Posts

Hi,

I have simple question.

Is it possible to convert or create point group from prim group in Python??

If not, I will use foreach sop though.... I just don't wanna use any other sop.

I would appreciate any help!!

Thanks

Link to comment
Share on other sites

You mean in PythonSOP? (it's not possible outside this node, as groups belong to geometry). You can do this explicitly by iterating over prims, like (not tested):

prims = hou.pwd().geometry().globPrims("mygroup")
pgroup = hou.pwd().geometry().createPointGroup("mypointgroup")

for prim in prims:
   for v in prim.vertices():
      if not pgroup.contains(v.point()): pgroup.add(v.point())

cheers,

skk.

Link to comment
Share on other sites

I seem to have this kicking around:

def primToPointGroup(geometry, prim_group, point_group_name=None, keep=False):
    """ Convert a primitive group to a point group. 

        If point_group_name is None, the new point group will have the
        same name as the primitive group.

        If keep is False, the original primitive group will be destroyed.
    """
    # Handle the name of the new group.
    if point_group_name is None:
        point_group = geometry.createPointGroup(prim_group.name())
    else:
        point_group = geometry.createPointGroup(point_group_name)
    # Iterate over each primitive in the group.
    for prim in prim_group.prims():
        # Iterate over each vertex in the primitive and add its referenced
        # point to the new group.
        for vert in prim.vertices():
            point_group.add(vert.point())

    # Destroy the source group.
    if not keep:
        prim_group.destroy()

    return point_group

Edited by graham
Link to comment
Share on other sites

Wow Thank you2 SO much !!

I did not expect this fast reply!!

I did not test it yet though,

I'm pretty sure the way graham shows will fit my situation and should work.

Again guys thanks a lot!!

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