Can't use global variable inside tree.enumNodeFragments() delegate The Next CEO of Stack OverflowWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var”?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?

Return the Closest Prime Number

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

What's the point of interval inversion?

Is it okay to store user locations?

Too much space between section and text in a twocolumn document

How long to clear the 'suck zone' of a turbofan after start is initiated?

Trouble understanding the speech of overseas colleagues

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Why Were Madagascar and New Zealand Discovered So Late?

If the heap is initialized for security, then why is the stack uninitialized?

Why do remote companies require working in the US?

How do we know the LHC results are robust?

Grabbing quick drinks

How to make a software documentation "officially" citable?

How to use tikz in fbox?

Opposite of a diet

What can we do to stop prior company from asking us questions?

How should I support this large drywall patch?

Apart from "berlinern", do any other German dialects have a corresponding verb?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

A pseudo-riley?

Why did we only see the N-1 starfighters in one film?

How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?

Inappropriate reference requests from Journal reviewers



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



The Next CEO of Stack OverflowWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var”?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

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович