Xims Posted August 8, 2012 Share Posted August 8, 2012 Can someone help? I have this code: if(hasprimattrib("../roadtype", "Road_0"),==1,0, if(hasprimattrib("../roadtype", "Road_1"),==1,2, if(hasprimattrib("../roadtype", "Road_2"),==1,2, if(hasprimattrib("../roadtype", "Road_3"),==1,2, if(hasprimattrib("../roadtype", "Road_4"),==1,2, if(hasprimattrib("../roadtype", "Road_5"),==1,2, if(hasprimattrib("../roadtype", "Road_6"),==1,2, if(hasprimattrib("../roadtype", "Road_0_Road_1"),==1,1, if(hasprimattrib("../roadtype", "Road_0_Road_2"),==1,1, if(hasprimattrib("../roadtype", "Road_0_Road_3"),==1,1, if(hasprimattrib("../roadtype", "Road_0_Road_4"),==1,1, if(hasprimattrib("../roadtype", "Road_0_Road_5"),==1,1, if(hasprimattrib("../roadtype", "Road_0_Road_6"),==1,1, if(hasprimattrib("../roadtype", "Road_1_Road_2"),==1,2, if(hasprimattrib("../roadtype", "Road_1_Road_3"),==1,2, if(hasprimattrib("../roadtype", "Road_1_Road_4"),==1,2, if(hasprimattrib("../roadtype", "Road_1_Road_5"),==1,2, if(hasprimattrib("../roadtype", "Road_1_Road_6"),==1,2, if(hasprimattrib("../roadtype", "Road_2_Road_3"),==1,2, if(hasprimattrib("../roadtype", "Road_2_Road_4"),==1,2, if(hasprimattrib("../roadtype", "Road_2_Road_5"),==1,2, if(hasprimattrib("../roadtype", "Road_2_Road_6"),==1,2, if(hasprimattrib("../roadtype", "Road_3_Road_4"),==1,2, if(hasprimattrib("../roadtype", "Road_3_Road_5"),==1,2, if(hasprimattrib("../roadtype", "Road_3_Road_6"),==1,2, if(hasprimattrib("../roadtype", "Road_4_Road_5"),==1,2, if(hasprimattrib("../roadtype", "Road_4_Road_6"),==1,2, if(hasprimattrib("../roadtype", "Road_5_Road_6"),==1,2,0)))))))))))))))))))))))))))) The problem is that it takes houdini around 20 minutes to accept it. It does work after that, but am i doing something wrong? Or is there another way to whrite this that it works fast? Quote Link to comment Share on other sites More sharing options...
hopbin9 Posted August 8, 2012 Share Posted August 8, 2012 (edited) I'd change that to a Python expression and use for loops to check for the attributes. Edited August 8, 2012 by hopbin9 Quote Link to comment Share on other sites More sharing options...
anim Posted August 8, 2012 Share Posted August 8, 2012 does it really work? what is returned from if(hasprimattrib("../roadtype", "Road_0"),==1, 0, if... ) ? since as correct syntax I would assume if(hasprimattrib("../roadtype", "Road_0")==1, 0, if... ) or simply if(hasprimattrib("../roadtype", "Road_0"), 0, if... ) Quote Link to comment Share on other sites More sharing options...
Xims Posted August 8, 2012 Author Share Posted August 8, 2012 (edited) does it really work? what is returned from if(hasprimattrib("../roadtype", "Road_0"),==1, 0, if... ) ? since as correct syntax I would assume if(hasprimattrib("../roadtype", "Road_0")==1, 0, if... ) or simply if(hasprimattrib("../roadtype", "Road_0"), 0, if... ) yes it does seem work that way. I tried it the way you showed by simply using if(hasprimattrib("../roadtype", "Road_0"), 0, if... ) But it still has the same problem. I'd change that to a Python expression and use for loops to check for the attributes. How should I write that? My knowledge of python is almost zero. Edited August 8, 2012 by Xims Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 8, 2012 Share Posted August 8, 2012 First, I would start by rewriting it to this form that you can find in my post there. So you could at least understand what is happening there. After that I would rewrite it in inlineCPP or HDK. Quote Link to comment Share on other sites More sharing options...
Xims Posted August 8, 2012 Author Share Posted August 8, 2012 First, I would start by rewriting it to this form that you can find in my post there. So you could at least understand what is happening there. After that I would rewrite it in inlineCPP or HDK. Thanks for the link mantragorma I think i'm doing it all wrong but is used it simply like this { # Come back, come back to me comeback = 0; # I'll be waiting, ptype = hasprimattrib("../roadtype", "Road_0"); if (ptype == 0) { comeback = 0; } else if (ptype == 1) comeback = 1; else comeback = 2; # patiently return comeback; } I can understand the way its set up but am I allowed a houdini expression in python like this? I'm getting a syntex error on the: comeback = 0; part. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 8, 2012 Share Posted August 8, 2012 I can understand the way its set up but am I allowed a houdini expression in python like this? I'm getting a syntex error on the: comeback = 0; part. 1) This is Hscript not Python so don't switch operator to Python mode. 2) If I tried your expression my Houdini hangs for a while, don't know if it works, still waiting for it to complete. Anyway, I rewrited this to more managable form (I'm a little sleepy so maybe I made some mistakes) and it works without problems and very fast. { comeback = 0; if(hasprimattrib("../OUT", "Road_0")) comeback = 0; else if(hasprimattrib("../OUT", "Road_1")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_0_Road_1")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_2")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_3")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_4")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_5")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_6")) comeback = 1; else if(hasprimattrib("../OUT", "Road_1_Road_2")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_5_Road_6")) comeback = 2; else comeback = 0; return comeback; } /OUT Quote Link to comment Share on other sites More sharing options...
anim Posted August 8, 2012 Share Posted August 8, 2012 here is python version geo = hou.pwd().node("../road_type").geometry() attrib_pairs = { 'Road_0':0, 'Road_1':2, 'Road_2':2 } result = -1 prim_attribs = [attrib.name() for attrib in geo.primAttribs()] for attrib, value in attrib_pairs.iteritems(): if attrib in prim_attribs: result = value break return result here it is with comments: # get geometry from some node geo = hou.pwd().node("../road_type").geometry() # define your attributename-resulting value pair dictionary here (I didn't fill it with all your values, so feel free to extend it) attrib_pairs = { 'Road_0':0, 'Road_1':2, 'Road_2':2 } # value returned if no above defined attribute name found on geometry result = -1 # get names of all primitive attributes on the geometry as list prim_attribs = [attrib.name() for attrib in geo.primAttribs()] # loop over all prim attribs on geometry and return first match with above defined dictionary for attrib, value in attrib_pairs.iteritems(): if attrib in prim_attribs: result = value break return result Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 8, 2012 Share Posted August 8, 2012 here is python version ... here it is with comments: ... Lol, is there speed difference between commented and not-commented version ? Quote Link to comment Share on other sites More sharing options...
anim Posted August 8, 2012 Share Posted August 8, 2012 I guess not, just to distinguish what's the actual necessary code for Xims since he is Python beginner version with comments may be a little messy to look at, but good for trying to understand the steps Quote Link to comment Share on other sites More sharing options...
Xims Posted August 8, 2012 Author Share Posted August 8, 2012 1) This is Hscript not Python so don't switch operator to Python mode. 2) If I tried your expression my Houdini hangs for a while, don't know if it works, still waiting for it to complete. Anyway, I rewrited this to more managable form (I'm a little sleepy so maybe I made some mistakes) and it works without problems and very fast. { comeback = 0; if(hasprimattrib("../OUT", "Road_0")) comeback = 0; else if(hasprimattrib("../OUT", "Road_1")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_0_Road_1")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_2")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_3")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_4")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_5")) comeback = 1; else if(hasprimattrib("../OUT", "Road_0_Road_6")) comeback = 1; else if(hasprimattrib("../OUT", "Road_1_Road_2")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_1_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_3")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_2_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_4")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_3_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4_Road_5")) comeback = 2; else if(hasprimattrib("../OUT", "Road_4_Road_6")) comeback = 2; else if(hasprimattrib("../OUT", "Road_5_Road_6")) comeback = 2; else comeback = 0; return comeback; } /OUT thanks allot this one works great. I didnt think you could use an else if funcion in houdini exspression because I didnt find it in de documentation I havent been using houdini for long so i'm still learning allot. Still I wonder why mine works so slow :s here is python version geo = hou.pwd().node("../road_type").geometry() attrib_pairs = { 'Road_0':0, 'Road_1':2, 'Road_2':2 } result = -1 prim_attribs = [attrib.name() for attrib in geo.primAttribs()] for attrib, value in attrib_pairs.iteritems(): if attrib in prim_attribs: result = value break return result here it is with comments: # get geometry from some node geo = hou.pwd().node("../road_type").geometry() # define your attributename-resulting value pair dictionary here (I didn't fill it with all your values, so feel free to extend it) attrib_pairs = { 'Road_0':0, 'Road_1':2, 'Road_2':2 } # value returned if no above defined attribute name found on geometry result = -1 # get names of all primitive attributes on the geometry as list prim_attribs = [attrib.name() for attrib in geo.primAttribs()] # loop over all prim attribs on geometry and return first match with above defined dictionary for attrib, value in attrib_pairs.iteritems(): if attrib in prim_attribs: result = value break return result Thanks anim I'll try both the houdini expression and the python. I really need to start learning python. Thanks for all the feedback people. 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.