Jump to content

Attribute isn't created within Condition ?


CinnamonMetal

Recommended Posts

You can't really conditionally create attributes, they either exists on all points (prims etc...) or they don't. You can conditionally set values on a previously created attribute. If the attribute does not exist, it will be created when first referenced and set to a default value (typically zero). In your current setup if your condition is never met then the attribute will never be created because it will have never been referenced.

Edited by Atom
Link to comment
Share on other sites

@Vector_Pt_AC = Desired_Vert_A - VertM_A;

That line of code will display a vector in the viewport

int chngePrim = detail(0,"iteration",0);
if(chngePrim%2==1){
    @Vector_Pt_AC = Desired_Vert_A - VertM_A;
}

The above block of code when placed within detail wrangler wrapped within a forEach SOP with the forEach metadata node connected to the second input of the detail wrangler; does not show a vector attribute ?

Why does one work and not the other; when the second block of code is the code I want; rather then the first line of code ? 

I have a scene to demonstrate this and it has been frustrating as to what is going on ?  

Link to comment
Share on other sites

Keep in mind that for vectors, you need to preface your attribute name with "v", as in "v@Vector_Pt_AC".

Also, your "iteration" metadata is likely not on the input 0. If you've created an Import Metadata node from your For-Each block, you'd connect that to the second input of your wrangle and reference it like so:

int chngePrim = detail(1, "iteration");

 

Link to comment
Share on other sites

As mentioned elsewhere;

In the scene attached, you will see a purple vector that is 90 degrees to the yellow vector. Go into the primitive wrangler node and comment out the last line within the primitive wrangler node.  The purple vector disappears. Go into the detail_modulo node wrangler node which is between the begin and end forEach SOP block. 

When checking the geometry spreadsheet for the detail_modulo wrangler you see three vectors; the purple line has disappeared ? 

Why has it disappeared; when the forEach SOP is iterating over every primitive and with that known each primitive should have the purple vector line, considering the attribute it is created within the condition (if statement)  ? 

At this point the last line within the primwrangler node should be commented out. 

I understand that the attribute created within the detail_modulo is a vector node and that the attribute created contains two integers but remember; the line you commented out from the primwrangler node is identical to that line within the condition (if statement) of the detail_modulo node, except no purple vector is shown ?

When I mention purple vector, it's just the color I gave the vector in the viewport it has obviously no importance the color of the vector in the viewport, it's simply for description purposes.

Vector from Vertice.hiplc

Link to comment
Share on other sites

Your import metadata node had some kind of error, it looks like the Block Path value was improperly defined. If you delete it and create a new metadata node, the vector attribute appears correctly.

That said, the code you currently have isn't going to do much. First, it's a Detail Wrangle, so you can't expect bound attributes like "v@Vector_Pt_AC" to work correctly, since those were previously defined as primitive attributes. You'd have to use prim() and setprimattrib() functions to get and set values on primitives from a Detail Wrangle. Second, the "i@opinput0_Desired_Vert_A - i@opinput0_VertM_A;" expression won't return anything meaningful, because neither of those attributes exist at all, let alone as detail attributes. Assuming those attributes did exist as primitive attributes, again, you'd have to use prim() and setprimattrib() in your Detail Wrangle in order to set values, because you're not iterating over primitives in a Primitive Wrangle.

If the only reason you're using this for-each block is to apply your code to every other primitive, you're way better off defining a group comprised of every other primitive, and then setting that group as a mask for a Primitive Wrangle.

  • Thanks 1
Link to comment
Share on other sites

On 5/16/2018 at 2:39 PM, toadstorm said:

Your import metadata node had some kind of error, it looks like the Block Path value was improperly defined. If you delete it and create a new metadata node, the vector attribute appears correctly.

That said, the code you currently have isn't going to do much. First, it's a Detail Wrangle, so you can't expect bound attributes like "v@Vector_Pt_AC" to work correctly, since those were previously defined as primitive attributes. You'd have to use prim() and setprimattrib() functions to get and set values on primitives from a Detail Wrangle. Second, the "i@opinput0_Desired_Vert_A - i@opinput0_VertM_A;" expression won't return anything meaningful, because neither of those attributes exist at all, let alone as detail attributes. Assuming those attributes did exist as primitive attributes, again, you'd have to use prim() and setprimattrib() in your Detail Wrangle in order to set values, because you're not iterating over primitives in a Primitive Wrangle.

If the only reason you're using this for-each block is to apply your code to every other primitive, you're way better off defining a group comprised of every other primitive, and then setting that group as a mask for a Primitive Wrangle.

int v_c;
int chngePrim = detail(1,"iteration",0);
if(chngePrim%2==1){
    v@Vector_Pt_AC = prim(0,"Desired_Vert_A",0) - prim(0,"VertM_A",0);
    setprimattrib(0,"Vector_Pt_AC",0,"set");    
}

Using the prim() and setprimattrib() function within the detail wrangler (detail_modulo) as you mentioned and it should create the vector (purple vector as mentioned) per primitive, correct ?

Edited by CinnamonMetal
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...