j00ey Posted March 28, 2014 Share Posted March 28, 2014 Hi I'm having difficulty doing something which I think it probably quite straightforward. I have a new VEX operator type which takes a user string input. For each of the characters I want to be able to append a group of integers to an integer array, effectively I want to do something like this : for S in STRING{ do something; } I've tried all sorts of braces and such but it's not working. Can anyone help? Thanks very much Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 You can process the parameter in python adding a special character in between each letter and then use that string by splitting it. Or create a literal string array in python and reference it using chs. Quote Link to comment Share on other sites More sharing options...
j00ey Posted March 28, 2014 Author Share Posted March 28, 2014 Thanks Ryan - I think that might be beyond me for now unfortunately, I'm a bit of a newcomer to coding in Houdini. I'll look into python when I get chance - would I do that with a python SOP or what? Thanks again Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 I can show you when I get home But you need to use python expression to transform the string into what you need since VEX lacks even the most basic string manipulation. Quote Link to comment Share on other sites More sharing options...
j00ey Posted March 28, 2014 Author Share Posted March 28, 2014 That's very kind, thanks! I didn't realise that VEX was limited like that with strings. I'm coming from a Maya background where you can do for ($S in $STRING) and I just presumed I could do that here too. Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 Unfortunately VEX is pretty dry when it comes to utility functions. Quote Link to comment Share on other sites More sharing options...
j00ey Posted March 28, 2014 Author Share Posted March 28, 2014 I'd best learn some python! Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 Also submit RFEs to SESI to remedy these issues please Quote Link to comment Share on other sites More sharing options...
j00ey Posted March 28, 2014 Author Share Posted March 28, 2014 Can I do that as an Apprentice user? Quote Link to comment Share on other sites More sharing options...
Tom Posted March 28, 2014 Share Posted March 28, 2014 (edited) Yes, you can submit bugs (and they get fixed quite fast, but that can depend ) or RFEs, even if you use free apprentice version. Edited March 28, 2014 by Tom Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 Yes just like Tom said, every Houdini artist has an equal voice for SESI, maybe some more than others The reason I ask people to submit these is because as much as SESI uses VEX inside Houdini, it's not comparable to regular usage of VEX day in and day out in the long run. Also SESI is enjoying the mighty boost library to notice the pain of manipulating strings in VEX Quote Link to comment Share on other sites More sharing options...
symek Posted March 28, 2014 Share Posted March 28, 2014 string my_string = "t h i s i s m y s t r i n g"; string char_array[] = split(my_string); foreach(string char; char_array) printf("%c, ", char); //do someting else with char... Not perfect as characters have to be separated with spaces, but works. Wonder if sprintf() can't be used to separate chars? Another trick would be to make two params. First for user's usage, second for python expression returning spaced copy of first parm... 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 28, 2014 Share Posted March 28, 2014 That's exactly what I thought too Symek, or creating an actual VEX string array as a string in python where you reference it using 'chs' Quote Link to comment Share on other sites More sharing options...
j00ey Posted March 30, 2014 Author Share Posted March 30, 2014 Thanks Symek. I thought I would try and do it in python as Ryan suggested, good opportunity to learn some. This is what I have come up with in the end, in case anyone wants to do the same sort of thing or has suggestions to improve the code : --------------------------- def pixeldisplay(): n = hou.pwd() g = n.geometry() #get geometry attributes and calculate index row = g.pointFloatAttribValues('row') col = g.pointFloatAttribValues('col') numrows = g.attribValue('numrows') numpts = len(row) g.addAttrib(hou.attribType.Point,'index',-1) for point in g.points(): ptnum = point.number() index = (col[ptnum] * numrows) + row[ptnum] point.setAttribValue('index',int(index)) #declare letters letterA = [0,1,1,1,1,1,0,1,0,0,0,1,1,1,1] letterB = [1,1,1,1,1,1,0,1,0,1,0,1,0,1,0] letterC = [0,1,1,1,0,1,0,0,0,1,1,0,0,0,1] letterD = [1,1,1,1,1,1,0,0,0,1,0,1,1,1,0] letterE = [1,1,1,1,1,1,0,1,0,1] letterF = [1,1,1,1,1,1,0,1,0,0] letterG = [1,1,1,1,1,1,0,0,0,1,1,0,0,1,1] letterH = [1,1,1,1,1,0,0,1,0,0,1,1,1,1,1] letterI = [1,0,0,0,1,1,1,1,1,1,1,0,0,0,1] letterJ = [0,0,0,0,1,1,1,1,1,0,0,0,0,0,0] letterK = [1,1,1,1,1,0,0,1,0,0,0,1,0,1,1] letterL = [1,1,1,1,1,0,0,0,0,1] letterM = [1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1,1,1,1] letterN = [1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1] letterO = [0,1,1,1,0,1,0,0,0,1,0,1,1,1,0] letterP = [1,1,1,1,1,1,0,1,0,0,0,1,0,0,0] letterQ = [0,1,1,1,0,1,0,0,0,1,0,1,1,1,1] letterR = [1,1,1,1,1,1,0,1,0,0,0,1,0,1,1] letterS = [0,1,0,0,1,1,0,1,0,1,1,0,0,1,0] letterT = [1,0,0,0,0,1,1,1,1,1,1,0,0,0,0] letterU = [1,1,1,1,1,0,0,0,0,1,1,1,1,1,1] letterV = [1,1,1,0,0,0,0,0,1,1,1,1,1,0,0] letterW = [1,1,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0] letterX = [1,1,0,1,1,0,0,1,0,0,1,1,0,1,1] letterY = [1,1,0,0,0,0,0,1,1,1,1,1,0,0,0] letterZ = [1,0,0,1,1,1,0,1,0,1,1,1,0,0,1] letter_ = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] #empty string to store letters text = [] #get user input text inputtext = hou.evalParm('text') #append letter lists to text list for char in inputtext: l = "letter" l+=char seq=eval(l) space=eval("letter_") for digit in seq: text.append(int(digit)) for s in space: text.append(int(s)) #for each point assign correct value p = g.points() points_in_text = len(text) for point in p: ptnum = point.number() if ptnum < points_in_text: #avoid out of range error on = text[ptnum] point.setAttribValue('on',on) pixeldisplay() Quote Link to comment Share on other sites More sharing options...
RobiDoes3d Posted July 12, 2019 Share Posted July 12, 2019 Hi, this seems a lot like the problem L-systems are used to. this is my take on this subject: Strings in Houdini have a index property, so if a string is: word="Hello" then word[3]="l" Also you can find out the length of a string by strlen(), It's one of the rare string functions in vex. A cheap way to do something from a user string input would be this: string word=chs("Axiom"); for(int l=0 ; l<strlen(word) ; l++){ if(word[l]==F) doSomething(); if(word[l]==B && word[l+1]==t) doSomethingElse(); if(word[l]==B && word[l+1]==g) doSomethingElse(); } 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.