"WARNING: ReferenceError: getNodeParent is not defined" for DzDistantLight::getNodeParent() ??

3dcheapskate3dcheapskate Posts: 2,719

I'm a little rusty since I haven't looked at any DAZ script for half a year. Here's a code snippet that's crashing my script...

   print("wbNode="+wbNode)
   print("wbGndNode="+wbGndNode)
   print("wbSunNode="+wbSunNode)
   print("wbIblNode="+wbIblNode)
   
   // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
   var oParent=wbSunNode.getNodeParent();
   if (oParent && oParent!=wbNode){ // If the sun's already parented to anything except the worldball it must be unparented first
    oParent.removeNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
   }

...and this is what ends up in the logfile when I run it in DS 3.1 ...

DEBUG: wbNode=DzNode(name = "WorldBall")
DEBUG: wbGndNode=DzNode(name = "WorldBall Ground DS3")
DEBUG: wbSunNode=DzDistantLight(name = "WorldBall Sun")
DEBUG: wbIblNode=DzShaderLight(name = "WorldBall IBL")
WARNING: Script Error: Line 1854
WARNING: ReferenceError: getNodeParent is not defined
WARNING: Stack Trace:
()@:1854
()@:1946
()@:-1
Error in script execution!

...or in DS 4.6...

DEBUG: wbNode=[object Object]
DEBUG: wbGndNode=[object Object]
DEBUG: wbSunNode=[object Object]
DEBUG: wbIblNode=[object Object]
WARNING: Script Error: Line 1854
WARNING: TypeError: Result of expression 'wbSunNode.getNodeParent' [undefined] is not a function.
WARNING: Stack Trace:
()@:1854
Error in script execution!

Line 1854 is the 'var oParent=wbSunNode.getNodeParent();'

But the debug shows that wbSunNode is a DzDistantLight, and getNodeParent() is a valid member function (inherited from DzNode).

So why's it telling me getNodeParent isn't defined?

What's the obvious thing I'm missing/overlooking?

Post edited by 3dcheapskate on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,458
    edited December 1969

    I don't know - I copied your script, copied the name of your variable from the print statement to a var declaration to get the light and it works - with or without a semicolon after the print statement, which is the only thing leaping out as a fault in your code.

    var wbSunNode = Scene.getPrimarySelection();
       print("wbSunNode="+wbSunNode)
       
       // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
       var oParent=wbSunNode.getNodeParent();
       if (oParent){ // If the sun's already parented to anything except the worldball it must be unparented first
        oParent.removeNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
       }
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    Thanks Richard, that's actually a good start. I copied your version of my snippet to a new test.dsa, selected a distant light, and ran the snippet (i.e. without the preceding 1850 or so lines of my original). Got this in DS 3.1...

    Executing DAZ Script file: H:/Studio/!ONGOING/Test.dsa
    DEBUG: wbSunNode=DzDistantLight(name = "DistantLight 1")
    Script executed successfully.

    ...and this in DS4.6...

    Executing DAZ Script file: H:/Studio/!ONGOING/Test.dsa
    DEBUG: wbSunNode=[object Object]
    Script executed successfully.

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    I still haven't solved this, but I've run into another problem where a section of code works fine in isolation, but does something odd when it's part of the main 1600-or-so line script - "Update Prop Origin Only Working If I Display Message Boxes ???"

    Although it's a different script, I'm wondering whether the root of the problem may lie somewhere in those other lines of code...

  • rbtwhizrbtwhiz Posts: 2,249
    edited December 1969

    In your snippet, "wbSunNode" is assumed to be a valid DzNode object. Don't assume. Make sure that it is not undefined/null. As written, if a node is not selected you will get that error, since you are then attempting to call getNodeParent on a null, not a DzNode object.

    -Rob

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    Agreed, I should check it's valid first (I wasn't checking). But if wbSunNode is undefined/null then why does the print statement earlier seem to indicate that it's valid?

    Here's the chunk of code immediately preceding it (mainly for my own reference - I haven't looked at this for months):

            ...
            // ...we should now have exactly one of each. If not, I've messed up!
            if(aBalls.length==1 && aSuns.length==1 && aIbls.length==1 && aGnds.length==1){
            
                // Identify the WorldBall and WorldBall Ground nodes
                var wbNode = undefined;
                var wbGndNode = undefined;
                var wbSunNode = undefined;
                var wbIblNode = undefined;
                wbNode = this.getOurNode(allNodes[aBalls[0]].getLabel());
                wbGndNode = this.getOurNode(allNodes[aGnds[0]].getLabel());
                wbSunNode = this.getOurNode(allNodes[aSuns[0]].getLabel());
                wbIblNode = this.getOurNode(allNodes[aIbls[0]].getLabel());
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
       
       print("wbNode="+wbNode)
       print("wbGndNode="+wbGndNode)
       print("wbSunNode="+wbSunNode)
       print("wbIblNode="+wbIblNode)
       
       // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
       var oParent=wbSunNode.getNodeParent();
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    Adding the check makes no difference (or probably I've done the check wrongly - it's been so long since I wrote any DAZ script!) - it thinks wbSunNode is valid


       print("wbNode="+wbNode)
       print("wbGndNode="+wbGndNode)
       print("wbSunNode="+wbSunNode)
       print("wbIblNode="+wbIblNode)
       
       if (!wbSunNode){
        print("wbSunNode is NOT valid")
       }else{
        print("VALID wbSunNode")
        // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbSunNode.getNodeParent();


    And running that in DS 4.6 I get this

    Executing DAZ Script file: H:/Poser/3DCheapskate/runtime/libraries/Props/3DCheapskate/WorldBall/WorldBall Setup DS3,4 ~~~ ONGOING.dsa
    ...
    (lots more of my debug)
    ...
    Loaded file: WorldBall Setup DS3,4 ~~~ ONGOING.ppz
    DEBUG: wbNode=[object Object]
    DEBUG: wbGndNode=[object Object]
    DEBUG: wbSunNode=[object Object]
    DEBUG: wbIblNode=[object Object]
    DEBUG: VALID wbSunNode
    WARNING: Script Error: Line 1858
    WARNING: TypeError: Result of expression 'wbSunNode.getNodeParent' [undefined] is not a function.
    WARNING: Stack Trace:
    ()@:1858
    Error in script execution!
    Ran tdlmake on image H:/Poser/3DCheapskate/Runtime/Textures/3DCheapskate/ReflectionMaps/E03SandLL1024INV.jpg

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    With this check...

    
       print("wbSunNode="+wbSunNode)
       print("wbIblNode="+wbIblNode)
       
       if (wbSunNode == undefined){
        print("wbSunNode is undefined")
       }else{
        print("wbSunNode seems OK")
        // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbSunNode.getNodeParent();   // THIS IS LINE 1858

    ...I get ...

    DEBUG: wbSunNode=[object Object]
    DEBUG: wbIblNode=[object Object]
    DEBUG: wbSunNode seems OK
    WARNING: Script Error: Line 1858

    This smacks of self-screwing-up code! Which could explain why sometimes other odd things happen.

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 100,458
    edited December 1969

    Try printing the className() for your objects - it looks as if they are there but not what you expect.

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    Thanks Richard, just tried that and you're right - they're not nodes (and it's so obvious! Look where the 'getLabel()' is! )...

               ...
                wbNode = this.getOurNode(allNodes[aBalls[0]].getLabel());
                wbGndNode = this.getOurNode(allNodes[aGnds[0]].getLabel());
                wbSunNode = this.getOurNode(allNodes[aSuns[0]].getLabel());
                wbIblNode = this.getOurNode(allNodes[aIbls[0]].getLabel());
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
       
       print("wbNode="+wbNode+", className()="+wbNode.className())     // THIS IS LINE 1848
       print("wbGndNode="+wbGndNode+", className()="+wbGndNode.className())
       print("wbSunNode="+wbSunNode+", className()="+wbSunNode.className())
       print("wbIblNode="+wbIblNode+", className()="+wbIblNode.className())
       
       if (wbSunNode == undefined){
        print("wbSunNode is undefined")
       }else{
        print("wbSunNode seems OK")
        // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbSunNode.getNodeParent();
        ...

    ...and got this...

    ...
    WARNING: Script Error: Line 1848
    WARNING: TypeError: Result of expression 'wbNode' [undefined] is not an object.

    Then I noticed that wbNode, wbSunNode etc are all strings, not nodes - they're set up with wbNode=xyz.getLabel()

    I thought that this would explain things, but...

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    ...but here's the same section in the original version of the script (with an extra print to confirm the section of code is actually being run), which works. I've also added a comment to show where I inserted new code to crash it...

            ...
            // ...we should now have exactly one of each. If not, I've messed up!
            if(aBalls.length==1 && aSuns.length==1 && aIbls.length==1 && aGnds.length==1){
       print("Just to check I'm running this section of code")
                // Identify the WorldBall and WorldBall Ground nodes
                var wbNode = undefined;
                var wbGndNode = undefined;
                var wbSunNode = undefined;
                var wbIblNode = undefined;
                wbNode = this.getOurNode(allNodes[aBalls[0]].getLabel());
                wbGndNode = this.getOurNode(allNodes[aGnds[0]].getLabel());
                wbSunNode = this.getOurNode(allNodes[aSuns[0]].getLabel());
                wbIblNode = this.getOurNode(allNodes[aIbls[0]].getLabel());
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
    
                // HERE'S WHERE I LATER INSERTED CODE TO CRASH THE SCRIPT
                
                // Apply the WorldBall material
                if (wbNode){
                    this.m_oNode = wbNode[0];
                    ...

    ...and the log file...

    Loaded file: WorldBall Setup DS3,4.pp2
    DEBUG: Just to check I'm running this section of code
    DEBUG: @@@ oMatWb.name=Preview
    Compiled C:/Users/c/AppData/Roaming/DAZ 3D/Studio4/shaders/brickyard/{b90ce5c2-776d-4dd4-b150-7a9cfa847205}/shader_Surface.sdl...
    Script executed successfully.

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited December 1969

    ... and here's the same section with the crashing code inserted...


            ...
            // ...we should now have exactly one of each. If not, I've messed up!
            if(aBalls.length==1 && aSuns.length==1 && aIbls.length==1 && aGnds.length==1){
            
                // Identify the WorldBall and WorldBall Ground nodes
                var wbNode = undefined;
                var wbGndNode = undefined;
                var wbSunNode = undefined;
                var wbIblNode = undefined;
                wbNode = this.getOurNode(allNodes[aBalls[0]].getLabel());
                wbGndNode = this.getOurNode(allNodes[aGnds[0]].getLabel());
                wbSunNode = this.getOurNode(allNodes[aSuns[0]].getLabel());
                wbIblNode = this.getOurNode(allNodes[aIbls[0]].getLabel());
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
       
       print("wbNode="+wbNode+", className()="+wbNode.className())
       print("wbGndNode="+wbGndNode+", className()="+wbGndNode.className())
       print("wbSunNode="+wbSunNode+", className()="+wbSunNode.className())
       print("wbIblNode="+wbIblNode+", className()="+wbIblNode.className())
       
       if (wbSunNode == undefined){
        print("wbSunNode is undefined")
       }else{
        print("wbSunNode seems OK")
        // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbSunNode.getNodeParent();
        if (oParent && oParent!=wbNode){ // If the sun's already parented to anything except the worldball it must be unparented first
         oParent.removeNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
        }
        if (!oParent){ // If the sun's not already parented to the worldball then parent it
         oHand.addNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
        }
        
        // Parent the IBL to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbIblNode.getNodeParent();
        if (oParent && oParent!=wbNode){ // If the IBL's already parented to anything except the worldball it must be unparented first
         oParent.removeNodeChild(wbIblNode); // no second parameter given (so inPlace=false)
        }
        if (!oParent){ // If the IBL's not already parented to the worldball then parent it
         oHand.addNodeChild(wbIblNode); // no second parameter given (so inPlace=false)
        }
       }
                
                // Apply the WorldBall material
                if (wbNode){
                    this.m_oNode = wbNode[0];
                    ...
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    The 'Apply worldball material bit at the end continues like this...

                // Apply the WorldBall material
                if (wbNode){
                    this.m_oNode = wbNode[0];
                    this.m_aMaterials = new Array;
                    g_oPresetHelper.collectMaterials( this.m_oNode, false, false, false );
                    this.m_aMaterials = g_oPresetHelper.getCollectedMaterials();
                    
                    oWb = this.m_oNode.getObject();

    So in my origibal working version of the script this.m_oNode is being set as a single character, the first character of the label.

    I'm surprised that g_oPresetHelper.collectMaterials() and/or getObject() don't crash ?

    So wbNode was always intended to be a DzNode, not a string.
    I therefore assumed that correcting the getLabel() bit would resolve things, but...

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    If I remove the getLabel() then the script with inserted code no longer crashes. But it always does the 'wbSunNode is undefined' bit


            ...
            // ...we should now have exactly one of each. If not, I've messed up!
            if(aBalls.length==1 && aSuns.length==1 && aIbls.length==1 && aGnds.length==1){
            
                // Identify the WorldBall and WorldBall Ground nodes
                var wbNode = undefined;
                var wbGndNode = undefined;
                var wbSunNode = undefined;
                var wbIblNode = undefined;
                wbNode = this.getOurNode(allNodes[aBalls[0]]);
                wbGndNode = this.getOurNode(allNodes[aGnds[0]]);
                wbSunNode = this.getOurNode(allNodes[aSuns[0]]);
                wbIblNode = this.getOurNode(allNodes[aIbls[0]]);
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
       
       print("wbNode="+wbNode)
       print("wbGndNode="+wbGndNode)
       print("wbSunNode="+wbSunNode)
       print("wbIblNode="+wbIblNode)
       
       if (wbSunNode == undefined){
        print("wbSunNode is undefined")
       }else{
        print("wbSunNode seems OK")
        // Parent the sun to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbSunNode.getNodeParent();
        if (oParent && oParent!=wbNode){ // If the sun's already parented to anything except the worldball it must be unparented first
         oParent.removeNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
        }
        if (!oParent){ // If the sun's not already parented to the worldball then parent it
         oHand.addNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
        }
        
        // Parent the IBL to the worldball   (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
        var oParent=wbIblNode.getNodeParent();
        if (oParent && oParent!=wbNode){ // If the IBL's already parented to anything except the worldball it must be unparented first
         oParent.removeNodeChild(wbIblNode); // no second parameter given (so inPlace=false)
        }
        if (!oParent){ // If the IBL's not already parented to the worldball then parent it
         oHand.addNodeChild(wbIblNode); // no second parameter given (so inPlace=false)
        }
       }
              
                // Apply the WorldBall material
                if (wbNode){
        print("Applying worldball material")
                    this.m_oNode = wbNode[0];
                    ...

    So I've got something screwed up when I set up allNodes[], either here...

            // Regenerate the Worldball node counting arrays...
            aBalls = [];
            aSuns = [];
            aIbls = [];
            aGnds = [];
            allNodes =  Scene.getNodeList();
            for( n = 0; n < allNodes.length; n++ ) {
                nodelabel = allNodes[n].getLabel();
                if (nodelabel.left(16) == "WorldBall Ground"){
                    aGnds.push(n);
                }else if (nodelabel.left(13) == "WorldBall Sun"){
                    aSuns.push(n);
                }else if (nodelabel.left(13) == "WorldBall IBL"){
                    aIbls.push(n);
                }else if (nodelabel.left(9) == "WorldBall"){
                    aBalls.push(n);
                }
            }
            // ...we should now have exactly one of each. If not, I've messed up!
            if(aBalls.length==1 && aSuns.length==1 && aIbls.length==1 && aGnds.length==1){

    ...or here...

    DsActions.prototype.getOurNode = function(sNodeName)
    {
        var ourNode;
        var n;
        var newNodes =  Scene.getNodeList();
        ourNode = undefined;
        for( n = 0; n < newNodes.length && !ourNode ; n++ ) {
            ourNode = newNodes[ n ];
            if ( ourNode.getLabel() != sNodeName )
                ourNode = undefined;
        }
        if ( ourNode )
            return [ ourNode ];
    }
    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    Oh dear, I'm talking a load of rubbish here ! :oS
    Did I say I'm a little rusty in the OP? More like totally seized up and in need of a good whack with a mallet! LOL

    I'm not setting wbNode, etc to a string with xyz.getLabel() - I'm passing xyz.getLabel( as a parameter to getOurNode() , and setting wbNode to whatever that returns.

    And although the function getOurNode() was in the original script it was never called till I inserted this new code...

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited July 2015

    Finally ! And so stupid... as usual. getOurNode() is totally unnecessary :D


         // Identify the WorldBall and WorldBall Ground nodes
                var wbNode = undefined;
                var wbGndNode = undefined;
                var wbSunNode = undefined;
                var wbIblNode = undefined;
                wbNode = allNodes[aBalls[0]];
                wbGndNode = allNodes[aGnds[0]];
                wbSunNode = allNodes[aSuns[0]];
                wbIblNode = allNodes[aIbls[0]];
                
                beginUndo(); // Causes a script error if any object is added/deleted between here and 'acceptUndo()'
       
       if (wbSunNode == undefined){
        print("wbSunNode is undefined")
       }else{
        print("wbSunNode seems OK")
        ...

    Now just got to find out what that oHand should be... I obviously just cut-and-pasted a chunk of code from my Smart+ Prop stuff.

    Post edited by 3dcheapskate on
Sign In or Register to comment.