How to use the Script SOP for modifying vertex attributes

I’m trying to modify the vertex attribute in a ScriptSOP and can’t quite get my syntax worked out.

def onCook(scriptOp):
	mesh = scriptOp.inputs[0]
	for i in scriptOp.points:
		i.Cd = 1 # this works to set the point attrib color Cd
		#i.uv = 0 # this does not work because my uv attribute is on the vertex

to loop through vertex I’ve tried this

for i in scriptOp.vertex:

but ^ this also does not seem to work?

I’ve looked through the op snippets and it would be useful to see more modifying of attribute examples, like bringing in a piece of geo and modifying point, prim and vertex attributes. Eventually I’ll need to wrangle more data types in geo and the python commands to access those counterparts.

According to the docs, a Vertex instance is always contained within a Prim object.

So looping over all vertices can be done like this:

def onCook(scriptOp):
	sop = scriptOp.inputs[0]
	for prim in sop.prims:
		print("primitive: ",  prim.index)
		for v in prim:
			# do something with v, which is a Vertex
			print("vertex index in prim: ", v.index, "uv attribute for this vertex : ", v.uv.val)

I did not yet succeed in changing the uv attribute values for a vertex like this, not sure if that is supported atm

Thanks Idzard,

Unfortunate that uv vertex doesn’t work. I guess ill do the old SOP >>> DAT trick, modify my values, then do the conversion back from DAT >>> SOP. I wish modifying SOP attributes was easier to script natively in SOPs, but maybe someday.