[Closed] Saving object node variables in an array
When saving a node in an array, I sometimes run nto the problem where I have a variable, say ‘objectctrl’, which gets saved as a whole node description (eg $EditableSpline @ [0,0,0] etc ) which creates problems where it expects a factor.
What’s the best way to deal with this? i.e, I want the node to be saved as $Circle01 or whatever without the additional info …I know I can save the name nd use getnodebyname to recover, but is there a way that automaticaaly saves the node variable in its usable form?
I’m not quite sure if I understood exactly what’s your problem, but the “getnodebyname” function requires a string. That’s why you should give the objects name, for example:
getnodebyname objectctrl.name
You can use weak references. The article looks confusing but it’s pretty simple.
http://paulneale.com/tutorials/Scripting/weakReferences/weakReferences.htm
What’s cool about weak references is that even if the object is renamed it still holds the node.
Io – the listener says that the array expects a factor. it all arises because of the full desciption of the object node including a space and or other errant strings not needed to identify the object node.
Sorry, I’ve lost you completely. Please post relevant code, and explain what your goal is.
Ok, I’ll try without clogging up sace with redundany code. First I set up a dummy CA to store data, then save an array called CtrlObjects, the first element of which contains an object node saved as variable ‘objectctrl’:
struct ObjLims (objectCtrl, deftransform, locXU, locYU, locZU, rotXU, rotYU, rotZU,locXL, locYL, locZL, rotXL, rotYL, rotZL, CtrlTypeName)
local ctrlerd = getnodebyname ctrlsplines[s]
if ctrlerd.parent.modifiers[1]== undefined do (
addmodifier ctrlerd.parent (EmptyModifier ())
dummydef = attributes data
(
)
custAttributes.add ctrlerd.parent.modifiers[1] dummydef
);
local ctrl = ObjLimits[index].objectCtrl ;
ObjLimits[index].CtrlTypeName = TempUpl[i];
append CtrlObjects ObjLimits[index]
if ctrlerd.parent.modifiers[1] != undefined do (
fr = custAttributes.getDefs ctrlerd.parent.modifiers[1];
T=(mats as string + "^" +CtrlObjects as string +"&"+params as string)
if T.count != 0 do (
custAttributes.setDefData fr[1] (T as string)
)
)
(I’ve left out of lot of unproblematic code)…the problem arises when I atempt to extract the data from the ctrlObjects array using:
fr = custAttributes.getDefs $.parent.modifiers[2]
T = custAttributes.getDefData fr[1];
if T != undefined do (
delimiter1 = findstring T "^";
delimiter2 = findstring T "&";
delimiter3 = T.count ;
matspart = substring T 1 (delimiter1-1);
CtrlObjectspart = substring T (delimiter1+1) (delimiter2-delimiter1-1);
local dd = " struct ObjLims (objectCtrl, deftransform, locXU, locYU, locZU, rotXU, rotYU, rotZU,locXL, locYL, locZL, rotXL, rotYL, rotZL,CtrlTypeName);
";
objstring = with printallelements on (dd as string);
objstring+= "CtrlObjects="
objstring += with printallelements on (CtrlObjectspart as string);
execute objstring
The following error is generated:
-- Error occurred during fileIn in StringStream:" struct ObjLims (objectCtrl, deftransform, locXU, locYU, locZU, rotXU, rotYU, rotZU,locXL, locYL, locZL, rotXL, rotYL, rotZL,CtrlTypeName);
CtrlObjects=#((ObjLims objectCtrl:$Editable_Spline:Sphere_CNT001 @ [3.730142,-0.000000,5.377388] deftransform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [3.73014,-2.35053e-007,5.37739]) locXU:undefined locYU:undefined locZU:undefined rotXU:undefined rotYU:undefined rotZU:0.0 locXL:undefined locYL:undefined locZL:undefined rotXL:undefined rotYL:undefined rotZL:0.0 CtrlTypeName:"Sphere_CNT001_localZRotation"))"; line number: 1
-- Syntax error: at name, expected :
-- In line: struct ObjLims (objectCtrl, deftransform, locXU, locYU, locZU, rotXU, rotYU, rotZU,locXL, locYL, locZL, rotXL, rotYL, rotZL,Ctrl
SO it doesn’t like the first element node description:(objectCtrl:$Editable_Spline:Sphere_CNT001 @ [3.730142,-0.000000,5.377388] )
what i need is something like $Sphere_CNT001, not the full reference. Never had this kind of problem before and I know I could use object name instead of node, then use getnodebyname but this creates other headaches.
You can save the node’s handle instead of the object and use getAnimByHandle in your string to return the node.