Jump to content

prim function and ForEach node


Yorkst

Recommended Posts

I created some boxes with copy node.

 

I added an attribute "class" to each primitive by connectivity node. Primitives of the same class belong to the same box.

 

I try to do two things:

1)Add every primitive with class x to a group "box_x"

2)Add every primitive, a blue component of color of which is greater than 0.1, to group "big". (Every box is scaled according to its color)

 

To do it, I iterate with ForEach over values of "class". Each node is called "in"

 

There is a file attached with all three cases.

 

This compiles and works:

1)

Group name: box_`prim("../in",0,"class",0)`

Expression: all primitives

2)

Group name: big

Expression: $CB>0.1

This does not compile:

1)

Group name: box_`$CLASS`

This compiles, but threats blue component as 0:

2)

Group name: big

Expression: prim("../in",0,"Cb",0)>0.1

 

Why does prim work inside group name, but doesn't work inside expression field in this particular case? Why does $ behave the opposite way?

 

 

 

connectivity.hipnc

Link to comment
Share on other sites

1)

box_`$CLASS`

 

I have no idea, why $CLASS works inside expression or pattern fields and not works inside group name field. I use user variables once in a century by this reason. Since you are iterating over class' values, it can be changed to:

box_`stamp("../..", "FORVALUE", 0)`

2)

prim("../in",0,"Cb",0)>0.1

 

Just a typo, there is no Cb primitive attribute.

prim("../in", 0, "Cd", 2) > 0.1
$CB > 0.1
@Cd.b > 0.1

All three will work. The third one is a new Houdini 15's analog to second one. Looks like the most limited at current moment, working only on subset of existing locals, which are limited too. Use them for simplicity, but generally, first expression is better.

 

 

3) Useful expressions working inside For-Each Subnetwork SOP:

stamp("../..", "FORVALUE", 0)       # While iterating over scalar values.
stamp("../..", "FORVALUE3",  0)     # While iterating over vectors, to get third value (e.g blue in RGB color).
stamps("../..", "FORVALUE", "")     # While iterating over strings (e.g over name attribute).
stamp("../..", "FORIDXVALUE", 0)    # To get for loop's "i" variable.
Edited by f1480187
Link to comment
Share on other sites

1. no need for foreach SOP, just append Partition SOP after your connectivity and into Rule type:

box_$CLASS

however it's much better to keep it as class (or creating name attribute ) than generating hundreds of groups

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