Get node name and parent
RajDarge
Posts: 17
I am struggling with this bit of code for what seems like foreever.
i am trying to print a scence object next to its parent
But whenever I have an non-root object the recursive function just returns undefined.
function getParentRecurse(nodein){ //print(nodein.name); if (nodein.isRootNode()) { return nodein.name; } var newparent = nodein.getNodeParent(); getParentRecurse(newparent);}function getSceneGeom(){ var oNodes = Scene.getNodeList(); for (a_idx = 0 ; a_idx < oNodes.length ; a_idx++) { var oObject = oNodes[a_idx].getObject(); if (oObject) { var curNode = oNodes[a_idx]; var localObjName = getParentRecurse(curNode); var curPrint = localObjName + "|" + curNode.name; print(curPrint); } }}getSceneGeom();
this is the output:
Executing Script...undefined|pCone(11cg000_vo0000)3_1Genesis3Female|Genesis3Femaleundefined|Poinsettia Earrings Lundefined|Poinsettia Earrings Rundefined|Genesis3FemaleGenitaliaundefined|aprilyshCadyHairG3F_121385Result: Script executed in 0 secs 5 msecs.
if if you uncomment line 3 you get
Executing Script...
pCone(11cg000_vo0000)3_1
MAIN_CAMERA
undefined|pCone(11cg000_vo0000)3_1
Genesis3Female
Genesis3Female|Genesis3Female
Poinsettia Earrings L
head
neckUpper
neckLower
chestUpper
chestLower
abdomenUpper
abdomenLower
hip
Genesis3Female
undefined|Poinsettia Earrings L
Poinsettia Earrings R
head
neckUpper
neckLower
chestUpper
chestLower
abdomenUpper
abdomenLower
hip
Genesis3Female
undefined|Poinsettia Earrings R
Genesis3FemaleGenitalia
Genesis3Female
undefined|Genesis3FemaleGenitalia
aprilyshCadyHairG3F_121385
Genesis3Female
undefined|aprilyshCadyHairG3F_121385
Result:
Script executed in 0 secs 13 msecs.
I am not sure why I keep getting undefined as the result from the recursive function?
Comments
I think you just need to change the last line of your recursive function to include a return statement, so it reads:
Otherwise, you are only returning nodein.name up one level in the stack and it doesn't emerge to be assigned to localObjName.
Recursion is never pretty, and in Javascript it's really ugly. Pity there isn't a 'getRootNode' convenience function somewhere.
You could short-circuit a certain amount by checking to see if the parent inherits DzBone and if it does using .getSkeleton() to skip to the figure.
Fixed it with one word! Seems i still don't understand how to write recursive functions.
@richard - I think I will take that on board to simplify the code. I always feel uncomfortable with recursion - it's like staring into the abyss. Clambering iteratively up and down Heirarchies is not always efficient though.
Just need to figure out the details of all the inrinsic classes and what they mean. Instances, groups etc. didn't know DS even had these things.
Does anyone know what the pane "UI widget map" is meant to do? I can see it bullds a UI class structure, but documentation and even functionality on this is sparse ? Is it so you can eventually customise the UI with the SDK?
Just for completeness before I modify the script so much it will be unusable to others here is the working version: the recursive function is still there for reference, but is not called anywhere, I used the .getSkeleton() method to get the figure that the prop is attached to (not sure why its not displaying the code snippet as one ?)