Can't use global variable inside tree.enumNodeFragments() delegate2019 Community Moderator ElectionWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var” to declare a variable in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?Check if a variable is a string in JavaScriptRead environment variables in Node.jsJavaScript check if variable exists (is defined/initialized)Is there a standard function to check for null, undefined, or blank variables in JavaScript?How to access the correct `this` inside a callback?

Can a druid choose the size of its wild shape beast?

How to create the Curved texte?

how to write formula in word in latex

Why one should not leave fingerprints on bulbs and plugs?

Time travel from stationary position?

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

Did Ender ever learn that he killed Stilson and/or Bonzo?

Are there verbs that are neither telic, or atelic?

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

An inequality of matrix norm

How do I hide Chekhov's Gun?

Why do Australian milk farmers need to protest supermarkets' milk price?

Opacity of an object in 2.8

Charles Hockett - 'F' article?

How to deal with taxi scam when on vacation?

What are substitutions for coconut in curry?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

Are all passive ability checks floors for active ability checks?

Why do passenger jet manufacturers design their planes with stall prevention systems?

What should tie a collection of short-stories together?

Brexit - No Deal Rejection

What's the meaning of “spike” in the context of “adrenaline spike”?

What is the significance behind "40 days" that often appears in the Bible?

What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?



Can't use global variable inside tree.enumNodeFragments() delegate



2019 Community Moderator ElectionWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var” to declare a variable in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?Check if a variable is a string in JavaScriptRead environment variables in Node.jsJavaScript check if variable exists (is defined/initialized)Is there a standard function to check for null, undefined, or blank variables in JavaScript?How to access the correct `this` inside a callback?










1















I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.



 highlight(externalId, color, dict) 
let viewer = this.viewer;
var dbId = dict[externalId];


let myMaterial = this.createMaterial(color);

// used to rescale and remove the z-fighting
let scaleRatio = 1.005; // this was determined as optimal through visual inspection

var tree = NOP_VIEWER.model.getData().instanceTree;

document.oldMaterials = ;


tree.enumNodeFragments(dbId,
function(fragId)
document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);

viewer.model.getFragmentList().setMaterial(fragId, myMaterial);


/* important technique if you want to remove z-fighting */
let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);

viewer.impl.invalidate(true);










share|improve this question


























    1















    I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.



     highlight(externalId, color, dict) 
    let viewer = this.viewer;
    var dbId = dict[externalId];


    let myMaterial = this.createMaterial(color);

    // used to rescale and remove the z-fighting
    let scaleRatio = 1.005; // this was determined as optimal through visual inspection

    var tree = NOP_VIEWER.model.getData().instanceTree;

    document.oldMaterials = ;


    tree.enumNodeFragments(dbId,
    function(fragId)
    document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);

    viewer.model.getFragmentList().setMaterial(fragId, myMaterial);


    /* important technique if you want to remove z-fighting */
    let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
    fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
    fragProxy.updateAnimTransform();
    ,
    true);

    viewer.impl.invalidate(true);










    share|improve this question
























      1












      1








      1








      I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.



       highlight(externalId, color, dict) 
      let viewer = this.viewer;
      var dbId = dict[externalId];


      let myMaterial = this.createMaterial(color);

      // used to rescale and remove the z-fighting
      let scaleRatio = 1.005; // this was determined as optimal through visual inspection

      var tree = NOP_VIEWER.model.getData().instanceTree;

      document.oldMaterials = ;


      tree.enumNodeFragments(dbId,
      function(fragId)
      document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);

      viewer.model.getFragmentList().setMaterial(fragId, myMaterial);


      /* important technique if you want to remove z-fighting */
      let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
      fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
      fragProxy.updateAnimTransform();
      ,
      true);

      viewer.impl.invalidate(true);










      share|improve this question














      I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.



       highlight(externalId, color, dict) 
      let viewer = this.viewer;
      var dbId = dict[externalId];


      let myMaterial = this.createMaterial(color);

      // used to rescale and remove the z-fighting
      let scaleRatio = 1.005; // this was determined as optimal through visual inspection

      var tree = NOP_VIEWER.model.getData().instanceTree;

      document.oldMaterials = ;


      tree.enumNodeFragments(dbId,
      function(fragId)
      document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);

      viewer.model.getFragmentList().setMaterial(fragId, myMaterial);


      /* important technique if you want to remove z-fighting */
      let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
      fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
      fragProxy.updateAnimTransform();
      ,
      true);

      viewer.impl.invalidate(true);







      javascript autodesk-forge autodesk-viewer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 14:02









      Anton KosenkoAnton Kosenko

      6211




      6211






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:



          function highlight(externalId, color, dict) 
          const viewer = this.viewer;
          const dbId = dict[externalId];
          const myMaterial = this.createMaterial(color);
          // used to rescale and remove the z-fighting
          const scaleRatio = 1.005; // this was determined as optimal through visual inspection
          const tree = NOP_VIEWER.model.getData().instanceTree;
          const oldMaterials = ;

          tree.enumNodeFragments(dbId, function(fragId)
          oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
          viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
          /* important technique if you want to remove z-fighting */
          const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
          fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
          fragProxy.updateAnimTransform();
          ,
          true);

          viewer.impl.invalidate(true);






          share|improve this answer























          • I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

            – Anton Kosenko
            Mar 7 at 14:29












          • I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

            – Anton Kosenko
            Mar 7 at 14:38











          • As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

            – Petr Broz
            Mar 7 at 14:43











          • How I can make sure that the callback function inside enumNodeFragments actually executes?

            – Anton Kosenko
            Mar 7 at 14:50











          • What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

            – Petr Broz
            Mar 7 at 14:55










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045639%2fcant-use-global-variable-inside-tree-enumnodefragments-delegate%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:



          function highlight(externalId, color, dict) 
          const viewer = this.viewer;
          const dbId = dict[externalId];
          const myMaterial = this.createMaterial(color);
          // used to rescale and remove the z-fighting
          const scaleRatio = 1.005; // this was determined as optimal through visual inspection
          const tree = NOP_VIEWER.model.getData().instanceTree;
          const oldMaterials = ;

          tree.enumNodeFragments(dbId, function(fragId)
          oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
          viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
          /* important technique if you want to remove z-fighting */
          const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
          fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
          fragProxy.updateAnimTransform();
          ,
          true);

          viewer.impl.invalidate(true);






          share|improve this answer























          • I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

            – Anton Kosenko
            Mar 7 at 14:29












          • I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

            – Anton Kosenko
            Mar 7 at 14:38











          • As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

            – Petr Broz
            Mar 7 at 14:43











          • How I can make sure that the callback function inside enumNodeFragments actually executes?

            – Anton Kosenko
            Mar 7 at 14:50











          • What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

            – Petr Broz
            Mar 7 at 14:55















          1














          Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:



          function highlight(externalId, color, dict) 
          const viewer = this.viewer;
          const dbId = dict[externalId];
          const myMaterial = this.createMaterial(color);
          // used to rescale and remove the z-fighting
          const scaleRatio = 1.005; // this was determined as optimal through visual inspection
          const tree = NOP_VIEWER.model.getData().instanceTree;
          const oldMaterials = ;

          tree.enumNodeFragments(dbId, function(fragId)
          oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
          viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
          /* important technique if you want to remove z-fighting */
          const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
          fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
          fragProxy.updateAnimTransform();
          ,
          true);

          viewer.impl.invalidate(true);






          share|improve this answer























          • I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

            – Anton Kosenko
            Mar 7 at 14:29












          • I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

            – Anton Kosenko
            Mar 7 at 14:38











          • As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

            – Petr Broz
            Mar 7 at 14:43











          • How I can make sure that the callback function inside enumNodeFragments actually executes?

            – Anton Kosenko
            Mar 7 at 14:50











          • What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

            – Petr Broz
            Mar 7 at 14:55













          1












          1








          1







          Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:



          function highlight(externalId, color, dict) 
          const viewer = this.viewer;
          const dbId = dict[externalId];
          const myMaterial = this.createMaterial(color);
          // used to rescale and remove the z-fighting
          const scaleRatio = 1.005; // this was determined as optimal through visual inspection
          const tree = NOP_VIEWER.model.getData().instanceTree;
          const oldMaterials = ;

          tree.enumNodeFragments(dbId, function(fragId)
          oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
          viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
          /* important technique if you want to remove z-fighting */
          const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
          fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
          fragProxy.updateAnimTransform();
          ,
          true);

          viewer.impl.invalidate(true);






          share|improve this answer













          Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:



          function highlight(externalId, color, dict) 
          const viewer = this.viewer;
          const dbId = dict[externalId];
          const myMaterial = this.createMaterial(color);
          // used to rescale and remove the z-fighting
          const scaleRatio = 1.005; // this was determined as optimal through visual inspection
          const tree = NOP_VIEWER.model.getData().instanceTree;
          const oldMaterials = ;

          tree.enumNodeFragments(dbId, function(fragId)
          oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
          viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
          /* important technique if you want to remove z-fighting */
          const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
          fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
          fragProxy.updateAnimTransform();
          ,
          true);

          viewer.impl.invalidate(true);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 14:26









          Petr BrozPetr Broz

          1,5372912




          1,5372912












          • I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

            – Anton Kosenko
            Mar 7 at 14:29












          • I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

            – Anton Kosenko
            Mar 7 at 14:38











          • As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

            – Petr Broz
            Mar 7 at 14:43











          • How I can make sure that the callback function inside enumNodeFragments actually executes?

            – Anton Kosenko
            Mar 7 at 14:50











          • What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

            – Petr Broz
            Mar 7 at 14:55

















          • I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

            – Anton Kosenko
            Mar 7 at 14:29












          • I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

            – Anton Kosenko
            Mar 7 at 14:38











          • As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

            – Petr Broz
            Mar 7 at 14:43











          • How I can make sure that the callback function inside enumNodeFragments actually executes?

            – Anton Kosenko
            Mar 7 at 14:50











          • What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

            – Petr Broz
            Mar 7 at 14:55
















          I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

          – Anton Kosenko
          Mar 7 at 14:29






          I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.

          – Anton Kosenko
          Mar 7 at 14:29














          I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

          – Anton Kosenko
          Mar 7 at 14:38





          I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).

          – Anton Kosenko
          Mar 7 at 14:38













          As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

          – Petr Broz
          Mar 7 at 14:43





          As I mentioned, referring to a global variable (and especially document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.

          – Petr Broz
          Mar 7 at 14:43













          How I can make sure that the callback function inside enumNodeFragments actually executes?

          – Anton Kosenko
          Mar 7 at 14:50





          How I can make sure that the callback function inside enumNodeFragments actually executes?

          – Anton Kosenko
          Mar 7 at 14:50













          What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

          – Petr Broz
          Mar 7 at 14:55





          What I meant was: confirm that the callback function is actually executed, for example by putting a console.log or debugger statement in it.

          – Petr Broz
          Mar 7 at 14:55



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045639%2fcant-use-global-variable-inside-tree-enumnodefragments-delegate%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229