Jump to content

Convert Group Array Suffix to Integer Value


Recommended Posts

Ok, I have many objects separated into point groups by unique suffixes.

I'd like to split the suffix integer value from the array of group names.

Then assign that integer to a custom attribute. 

 

I'm terrible at VEX so any suggestions would be greatly appreciated.

 

Link to comment
Share on other sites

you need to realize that one point can belong to multiple groups

that's why it's much easier to use name attribute to separate geometries within one detail

you can use name SOP to convert groups into name attrib

then you can use opdigits() vex function to extract number from the name

 

if you still decide to use groups, here is example how you can get array of all groups each point belongs to: 

http://forums.odforce.net/topic/23822-how-to-get-the-group-name-from-points/?p=140187 

Edited by anim
Link to comment
Share on other sites

Thanks for the quick reply! Big fan of your blog posts.

 

Yeah, it certainly isn't an ideal setup but I'm working from a cache; so it's a bit wonky from the start. 

I had no idea there was a name node, that's awesome. Thanks for that bit.

The point group array setup is super helpful too.

 

I'm just stuck on the opdigits part though. From within the Point Wrangle node, opdigits isn't a recognized function...? Would you apply it from another node? 

Link to comment
Share on other sites

if you are using H14, you could still write something yourself using the find() function to search for 0-9 and then split the string based on the index found using the python notation: groupname[idx:], that should return you the end of the string where the numbers are (unless you also use numbers halfway into your group)

and afterwards simply use a atoi() function.

 

If you are still on H13, Im afraid you are basically out of luck, string functions back then were not really great :P

so in that case you probably want to use a python SOP

Edited by acey195
Link to comment
Share on other sites

Yeah, I'm in H14.

Ok, so I apologize in advance for my stupidity. So here's what I have but it basically just spits out a matrix. 

I'd ideally like a for loop within a for loop, if that makes any sense. 

Or is there a way to store/reference the original split string array without splitting the group array?

 

string ptGrps[] = detailintrinsic(0, "pointgroups");

s[]@ptinGrps = {};

foreach(string grp;ptGrps){

    if (inpointgroup(0, grp, @ptnum)) append(s[]@ptinGrps, grp);

    split(s[]@ptinGrps, grp, "_");

}

 

s[]@indexAttr = {};

foreach(int i; string s; ptGrps){

    s@indexAttr = @ptinGrps[1];

}

 

/* String to Int

string indexString[] = {};

foreach(int i; string s; indexString){

    i@objectID = atoi(s);

    }

*/

Group_ID_Array_01.hipnc

Link to comment
Share on other sites

for extracting last digits you can for example use regular expressions:

// this is mostly for <=H14, since H15 you can use native opdigits() function instead, however that will return 0 if digit not found
int getTrailDigits(string name)
{
    // returns trailing digits of the name
    // returns -1 if no triling digits found
    int digit = -1;
    string sdigit = re_find(r"\d*$", name);
    if (sdigit != "") digit = atoi(sdigit);
    return digit;
}

- so what's wrong with name attribute? If you use Name SOP to create name attrib from group matching your pattern (group*) then you can just additionally to defining above getTrailDigits() function do

i@digit = getTrailDigits(s@name);

- or if you really want all in VEX you can go through point groups belonging to the point and if group matches pattern, extract digit, so in addition to defining the getTrailDigits() function you can do:

// finds first group that matches pattern that point belongs to and extracts it's digit, -1 otherwise
string grppattern = "group*";
string ptgrps[] = detailintrinsic(0, "pointgroups");

i@digit = -1;
foreach(string grp;ptgrps)
{
    if (inpointgroup(0, grp, @ptnum) && match(grppattern, grp))
    {
        i@digit = getTrailDigits(grp) ;
        break;
    }
}

 

- if you really want to go with gathering all the groups that the point is in and then extracting all the digits from them, which I don't think you really care about but just for completness, again in addition to defining the getTrailDigits() function (notice no nested loops necessary):

// gets array of groups that point belongs to and extract array of digits from them
string ptgrps[] = detailintrinsic(0, "pointgroups");
s[]@ptingrps = {};
i[]@grpdigits = {};
foreach(string grp;ptgrps)
{
    if (inpointgroup(0, grp, @ptnum))
    {
        append(s[]@ptingrps, grp);
        append(s[]@grpdigits, getTrailDigits(grp) );
    }
}

all methods in attached fixed example

 

Group_ID_Array_01_fix.hipnc

  • Like 3
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...