Notifications
Clear all

[Closed] script controller : how to reference array of nodes ?

How, in a script controller, can i reference several nodes to be processed, in only one variable… without creating a bunch of variables ?
Array of nodes does not work.

(	
	mast = point name:"masterCtrl" wirecolor:red
	ptarr = for i=1 to 5 collect point pos:[20*i,0,0] wirecolor:green
		
	mast.scale.controller = scale_script()
	scr="arr="+ptarr as string+"
for p in arr do print p.name -- does nothing
[1,1,1]"
	mast.scale.controller.script=scr
)
7 Replies

first of all you have to make a decision what you want to pass and where.

#1 if you want to pass a list to a script controller expression (what you are trying to do in you snippet) you can pass node names or pathname values.

here is a snippet:

delete objects
  bb = for k=1 to 4 collect (box())
  s = sphere()
  c = s.position.controller = position_script()
  names = for b in bb collect b.name
  c.setExpression ("for n in " + names as string + " do (format \"pos:%
\" (getnodebyname n)); [0,0,0]")
  
  c = s.rotation.controller = rotation_script()
  pathnames = for b in bb collect ("$" + b.name)
  c.setExpression ("for n in " + pathnames as string + " do (format \"rot:%
\" (execute n)); (quat 1)")	

#2 if you want to pass list of nodes to a script controller you have pass it using an object.

this is more tricky… we have to make an object which is good to be added as value to a controller.
#1 custom attribute added as object (position controller)
#2 custom attribute added to controller itself (rotation controller)

ca = attributes ca 
  (
  	parameters params (nodes type:#nodeTab tabSizeVariable:on)
  )
  
  delete objects
  bb = for k=1 to 4 collect (box())
  node_holder = createinstance ca nodes:bb
  	
  s = sphere()
  c = s.position.controller = position_script()
  c.addObject "attr" node_holder 
  c.setExpression ("for n in attr.nodes do (format \"pos:%
\" n); [0,0,0]")
 
 c = s.rotation.controller = rotation_script()
 append c.custattributes node_holder
 c.setExpression ("for n in this.ca.nodes do (format \"rot:%
\" n); (quat 1)")

surely the #2 is a pro way

there are another ways to pass a list of nodes… some of them are weird … passing a layer for example

Thanks Denis,

I’m not familiar with custom attributes and its mechanisms but I think I see the point.
Just for curiosity, I was wondering about any “weird layer method” :

  • are you talking about layermanager ?
  • put nodes on named layer and get those nodes via “layer.nodes &myNodes”
  • or by refTarget : layRT=layer.layerAsRefTarg; myNodes=(refs.dependents layRT)
  • but how to add this as a value for expression ?
1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

‘layer’ method sounds weird, but for some pipelines it might make a sense. a layer’s name is unique instead of a node’s name. that means a script will take the exact node set as you passed with a layer’s name.
also you can pass a layer as its refTarget because it’s an object.

but as i said above… the CA way is a PRO way. at least it’s the way i would go

I’ve tried this before, but just for fun…

p = point name:"p1"
c = float_script()
p[#transform][#position][#x_position].controller = c
a = #((datapair "uparms" $armsUpper_000),(datapair "forearms" $armsLower_000))
b = #($armsUpper_000,$armsLower_000)
c.addConstant "a" a
c.addConstant "a" b

result:

-- Unable to convert: (DataPair "uparms" $PolyMesh:ArmsUpper_000 @ [0.000000,0.000000,0.000000]) to type: FPValue
-- Runtime error: IScriptCtrl::SetConstant - Value array contains MAXWrapper objects

Interesting things:

  1. According to autodesk docs, there is a list of types that can be FPValues, and “Tab<>s of above”. So NodeTab, ObjectTab, are viable FPValues. Is there a way to create one of these table types without committing to creating a custattribute def?

  2. While trying to add an array to a script controller constant causes an error, manually going into the script controller param UI, pasting an array into the field, and hitting the evaluate button causes the UI to update and show the array in the Value Expression Result field, but still won’t accept it if you then hit OK.

these value types are valid for parameter block only. you can’t create any table with param block.