Jump to content

How to get copy group name as a string


tricecold

Recommended Posts

I have this lots of geo imported as alembic. In the naming convection we have material IDs , objects inherit these names as group names in Houdini, I need to copy these names to points as strings, and then need to split them by "_" which I think I can manage, but I cannot find a way to copy the group names as strings in any kinda of wrangle sop ?

 

any ideas

Link to comment
Share on other sites

I'm not sure how to wrangle that but in python you can fetch the groups using geo.primGroups(). How you get that string back out into where you need it is another question.

node = hou.pwd()
geo = node.geometry()
 
# Add code to modify contents of geo.
# Use drop down menu to select examples.
print geo.primGroups()
for g in geo.primGroups():
    print g.name()

post-12295-0-91330900-1441388739_thumb.p

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

Guest mantragora

Something along those lines Run Over Points should do the trick:

string groupName = chs("groupnamepattern");
int groupCount = chi("groupcount");
 
for(int i = 0; i < groupCount; i++)
{
    string formattedName = sprintf("%s%d", groupName, i);    
    
    int success = inprimgroup(@OpInput1, formattedName, @primnum);    
    if (success) s@groupname = formattedName;
}
groupCount expression:

groupCount = argc(primgrouplist(opinputpath(".", 0)))
groupName is partial name, so if you have 100 groups called id_number, you want to put there only id_ Edited by fântastîque Mântragorîè
Link to comment
Share on other sites

Something along those lines Run Over Points should do the trick:

string groupName = chs("groupnamepattern");
int groupCount = chi("groupcount");
 
for(int i = 0; i < groupCount; i++)
{
    string formattedName = sprintf("%s%d", groupName, i);    
    
    int success = inprimgroup(@OpInput1, formattedName, @primnum);    
    if (success) s@groupname = formattedName;
}
groupCount expression:

groupCount = argc(primgrouplist(opinputpath(".", 0)))
groupName is partial name, so if you have 100 groups called id_number, you want to put there only id_

 

 

 

I'm not sure how to wrangle that but in python you can fetch the groups using geo.primGroups(). How you get that string back out into where you need it is another question.

node = hou.pwd()
geo = node.geometry()
 
# Add code to modify contents of geo.
# Use drop down menu to select examples.
print geo.primGroups()
for g in geo.primGroups():
    print g.name()

 

 

I'm not sure how to wrangle that but in python you can fetch the groups using geo.primGroups(). How you get that string back out into where you need it is another question.

node = hou.pwd()

geo = node.geometry()

 

# Add code to modify contents of geo.

# Use drop down menu to select examples.

print geo.primGroups()

for g in geo.primGroups():

    print g.name()

 

 

Hi Atom, I already got it working with python, and i set the names like this

 

mat_attrib = geo.addAttrib (hou.attribType.Prim, "material","")

and

primitive.setAttribValue(my_string)

 

I found sth similar to this on this forum also, which I cannot find now for some reason.

I find it again, I will update this post

Link to comment
Share on other sites

Something along those lines Run Over Points should do the trick:

string groupName = chs("groupnamepattern");
int groupCount = chi("groupcount");
 
for(int i = 0; i < groupCount; i++)
{
    string formattedName = sprintf("%s%d", groupName, i);    
    
    int success = inprimgroup(@OpInput1, formattedName, @primnum);    
    if (success) s@groupname = formattedName;
}
groupCount expression:

groupCount = argc(primgrouplist(opinputpath(".", 0)))
groupName is partial name, so if you have 100 groups called id_number, you want to put there only id_

 

 

Like I said, I got it working with pyhton, but it feels like its too slow, and I am really bad at python, so I would like to do this is vex,

so I tried your code

 

but the code returns groupname attribute empty

what I dont understand is;

 

there is one string and one integer you declare that should be a channel on the wrangle node or groupnamepattern and groupcount are already avaliable by default from Houdini.

 

as far as I understood argc primgrouplist will get the numbers of total groups to run define the loop amount, but since every point has a group i use @ptnum instead.

so I think I failed to understand the groupnamepattern part,

 

I made a string input in my wrangle, and since my groups are named like object_something_IDmetal_shape , when I put in my string ID, it does not return anything

Link to comment
Share on other sites

Guest mantragora

Group names are the same on each point? Do you have some common name there or does it change completely, not only by number at the end of group name?It you don't have common name, than you will need to use python.

You really don't want to do any too complicated string formatting in VEX.

If you can't share the original file, can you copy group names to some simple geometry, lock it and attach here, so we could look?

EDIT:

Or just grab all group names with Python and pack them into string field on AttribWrangle, and then split this field text in Vex and run over each string from it.

 

string groupnames = chs("groupnames");
string groups[] = split(groupnames);
 
foreach (string group; groups)
{
    // if point in group
    // transfer name to point
}
than you can run over any group name and don't care about any common pattern in name. Edited by fântastîque Mântragorîè
Link to comment
Share on other sites

The object can have 1000 or 100000 points with random amount of group names ( group names are due to alembic being set as Name Group using Shape node Name),

 

Some can be

 

cityname_streetname_road_IDconcrete_shape

cityname_streetname_bench_IDwood_shape

cars_brand_IDmetal_shape

building_floor01_furnitures_IDplastic_shape

 

etc etc, IDmaterial could be after 2nd underscore, or 3rd or 4th, depends on how deep is the asset in the maya scene.

 

I cannot upload anything from work, but I will make an example file at home. I will continue to use python then, thnx a lot for the input.

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