What it does
Creates a new point and writes an attribute value onto it by point number. Where @Cd = ... edits the current element, setpointattrib lets you write to any point you name - including one you just added.
When to use it
Use it whenever you generate geometry in a wrangle and need to set attributes on the new elements: scattering points, building curves, or emitting from a detail wrangle where there is no current point to bind.
The VEX code
int pt = addpoint(0, set(0, 0, 0));
// addpoint returns the new point number; pass it to setpointattrib.
// The final arg is the write mode ("set", "add", "max", and so on).
setpointattrib(0, "Cd", pt, {1, 0, 0}, "set");
Inputs and assumptions
- Input 0 is the geometry you are writing to (the wrangle edits input 0 by default).
addpointreturns the new point number, which you pass tosetpointattrib.- Often run in a detail (or points) wrangle when generating geometry.
Common mistakes
- Using
@Cdinstead ofsetpointattribwhen the point is not the current element -@only writes the element the wrangle is on. - Wrong value type:
Cdis a vector, so pass{1, 0, 0}, not a single float. - Forgetting the mode argument (
"set","add","max", and so on) or misspelling it. - Expecting the attribute to exist for later nodes - creating it here is fine, but downstream nodes must reference the same name.
Frequently asked questions
What is the difference between @Cd and setpointattrib?
@Cd writes to the current element the wrangle is running on; setpointattrib writes to any point by number, including points you create with addpoint.
Which wrangle should I use setpointattrib in?
Any, but it is most common in a detail or points wrangle when you are generating geometry and setting attributes on new points.