potankav Posted April 9, 2016 Share Posted April 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
anim Posted April 9, 2016 Share Posted April 9, 2016 (edited) 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 April 9, 2016 by anim Quote Link to comment Share on other sites More sharing options...
potankav Posted April 9, 2016 Author Share Posted April 9, 2016 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? Quote Link to comment Share on other sites More sharing options...
anim Posted April 10, 2016 Share Posted April 10, 2016 opdigits() is part of VEX since H15 Quote Link to comment Share on other sites More sharing options...
acey195 Posted April 11, 2016 Share Posted April 11, 2016 (edited) 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 so in that case you probably want to use a python SOP Edited April 11, 2016 by acey195 Quote Link to comment Share on other sites More sharing options...
potankav Posted April 13, 2016 Author Share Posted April 13, 2016 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 Quote Link to comment Share on other sites More sharing options...
anim Posted April 13, 2016 Share Posted April 13, 2016 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 3 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 13, 2016 Share Posted April 13, 2016 There is also random_shash function available from H14. Return random integer determined by string seed. Somewhat related. Quote Link to comment Share on other sites More sharing options...
potankav Posted April 14, 2016 Author Share Posted April 14, 2016 Tomas. You're amazing. Thank you sooo much for taking the time to do all this. I can't emphasize how much I appreciate it. Just so awesome. Quote Link to comment Share on other sites More sharing options...
potankav Posted April 14, 2016 Author Share Posted April 14, 2016 There is also random_shash function available from H14. Return random integer determined by string seed. Somewhat related. I'm really trying to learn VEX so anything that gets thrown my way helps. Thanks so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.