Jump to content

If statement Problem


Xims

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Xims
Link to comment
Share on other sites

Guest mantragora

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest mantragora

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Guest mantragora

here is python version

...

here it is with comments:

...

Lol, is there speed difference between commented and not-commented version ? :)

Link to comment
Share on other sites

:)

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

Link to comment
Share on other sites

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

Thanks for all the feedback people.

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