Waiting until load done

I wana take several screenshot with api but the problem is sometimes the screenshot taken even screen isnt ready yet… how can take screenshot when everthing ready? (5000 is only about wen connection speed)

var resList = [{}, {}, {}, {}, {}, {}, {}];

return new Promise(function(resolve, reject) {

 //BOŞ//  

 api.updateSettingAsync('scene.camera.cameraTypes.active',6)

.then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);}).then(function(response) {return promiseTimeout(100);})

.then(function(response) {resList[0].screenshot = api.scene.getScreenshot(); return promiseTimeout(100);})

//ÖNDEN//  

.then(function(response) { 

api.updateSettingAsync('scene.camera.cameraTypes.active', 3);

zoomfunction();

api.parameters.updateAsync({name: "front_1", value: true});

api.parameters.updateAsync({name: "front_2", value: true});

api.parameters.updateAsync({name: "front_3", value: true});

api.parameters.updateAsync({name: "front_4", value: true});

api.parameters.updateAsync({name: "top_1", value: false}); 

api.parameters.updateAsync({name: "top_2", value: false});

api.parameters.updateAsync({name: "top_3", value: false});

api.parameters.updateAsync({name: "top_4", value: false});

api.parameters.updateAsync({name: "top_5", value: false});

api.parameters.updateAsync({name: "side_1", value: false});

api.parameters.updateAsync({name: "side_2", value: false});

api.parameters.updateAsync({name: "side_3", value: false});

api.parameters.updateAsync({name: "side_4", value: false});

})

.then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);}).then(function(response) {return promiseTimeout(5000);})

.then(function(response) {resList[1].screenshot = api.scene.getScreenshot(); return promiseTimeout(100);})

See details in this code example:

so which code is for “wait until screenshot ready” ?

I need code like :"

if (document.readyState === “loading”) {document.addEventListener(“DOMContentLoaded”, initSdvApp, false);

}

else {initSdvApp();}

hide “something” than " show other thing" etc etc etc… than be sure everything ready and than take screenshot…

@pavol Please, I need help about that subject…

I am not sure I understand your problem. Here are some things you can try:

  • Wait for the api.scene.EVENTTYPE.VISIBILITY_ON event to happen before you take the screenshots. You can do it like this:
api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {
  // take screenshots
}
  • Use the function getScreenshotAsync() instead of getScreenshot()
  • Make sure in your transitionParameters that the camera update takes 0ms
var transitionParameters = {duration: 1}

window.takeScreenshots = function(screen) 

{

api.updateSettingAsync('scene.render.shadows', false);

api.updateSettingAsync('scene.groundPlaneVisibility', false );

api.updateSettingAsync('scene.gridVisibility', false);

api.parameters.updateAsync({name: "sistem_gorunumu", value: 1});

api.parameters.updateAsync({name: "ledam_gorunumu", value: 0});

api.parameters.updateAsync({name: "suyolu", value: 0});

api.parameters.updateAsync({name: "top_led_1", value: false});

api.parameters.updateAsync({name: "top_led_2", value: false});

api.parameters.updateAsync({name: "top_led_3", value: false});

api.parameters.updateAsync({name: "top_led_4", value: false});

var resList = [{}, {}, {}, {}, {}, {}, {}];

return new Promise(function(resolve, reject) {

     //BOŞ//  

     api.updateSettingAsync('scene.camera.cameraTypes.active',6)

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[0].screenshot = api.scene.getScreenshotAsync();});})

    //ÖNDEN//  

    .then(function(response) { 

    api.updateSettingAsync('scene.camera.cameraTypes.active', 3);

    zoomfunction();

    api.parameters.updateAsync({name: "front_1", value: true});

    api.parameters.updateAsync({name: "front_2", value: true});

    api.parameters.updateAsync({name: "front_3", value: true});

    api.parameters.updateAsync({name: "front_4", value: true});

    api.parameters.updateAsync({name: "top_1", value: false}); 

    api.parameters.updateAsync({name: "top_2", value: false});

    api.parameters.updateAsync({name: "top_3", value: false});

    api.parameters.updateAsync({name: "top_4", value: false});

    api.parameters.updateAsync({name: "top_5", value: false});

    api.parameters.updateAsync({name: "side_1", value: false});

    api.parameters.updateAsync({name: "side_2", value: false});

    api.parameters.updateAsync({name: "side_3", value: false});

    api.parameters.updateAsync({name: "side_4", value: false});

    })

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[1].screenshot = api.scene.getScreenshotAsync();});})

    //TEPEDEN//  

    .then(function(response) { 

    api.updateSettingAsync('scene.camera.cameraTypes.active', 1);

    zoomfunction();

    api.parameters.updateAsync({name: "top_1", value: true});

    api.parameters.updateAsync({name: "top_2", value: true});

    api.parameters.updateAsync({name: "top_3", value: true});

    api.parameters.updateAsync({name: "top_4", value: true});

    api.parameters.updateAsync({name: "top_5", value: true});

    api.parameters.updateAsync({name: "front_1", value: false});

    api.parameters.updateAsync({name: "front_2", value: false});

    api.parameters.updateAsync({name: "front_3", value: false});

    api.parameters.updateAsync({name: "front_4", value: false});

    api.parameters.updateAsync({name: "side_1", value: false});

    api.parameters.updateAsync({name: "side_2", value: false});

    api.parameters.updateAsync({name: "side_3", value: false});

    api.parameters.updateAsync({name: "side_4", value: false});

    api.parameters.updateAsync({name: "front_1", value: false});

    api.parameters.updateAsync({name: "front_2", value: false});

    api.parameters.updateAsync({name: "front_3", value: false});

    api.parameters.updateAsync({name: "front_4", value: false});

    

    })

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[2].screenshot = api.scene.getScreenshotAsync();});})

    //SAĞDAN//  

    .then(function(response) {

      api.updateSettingAsync('scene.camera.cameraTypes.active', 6);

      zoomfunction();

      api.parameters.updateAsync({name: "top_1", value: false});

      api.parameters.updateAsync({name: "top_2", value: false});

      api.parameters.updateAsync({name: "top_3", value: false});

      api.parameters.updateAsync({name: "top_4", value: false});

      api.parameters.updateAsync({name: "top_5", value: false});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      api.parameters.updateAsync({name: "side_1", value: true});

      api.parameters.updateAsync({name: "side_2", value: true});

      api.parameters.updateAsync({name: "side_3", value: true});

      api.parameters.updateAsync({name: "side_4", value: true});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      })

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[3].screenshot = api.scene.getScreenshotAsync();});})

    //PERS//  

    .then(function(response) {

      api.updateSettingAsync('scene.camera.cameraTypes.active', 0);

      zoomfunction();

      api.parameters.updateAsync({name: "top_1", value: true});

      api.parameters.updateAsync({name: "top_2", value: true});

      api.parameters.updateAsync({name: "top_3", value: true});

      api.parameters.updateAsync({name: "top_4", value: true});

      api.parameters.updateAsync({name: "top_5", value: true});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      api.parameters.updateAsync({name: "side_1", value: false});

      api.parameters.updateAsync({name: "side_2", value: false});

      api.parameters.updateAsync({name: "side_3", value: false});

      api.parameters.updateAsync({name: "side_4", value: false});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      })

      .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

      .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[4].screenshot = api.scene.getScreenshotAsync();});})

    //SUYOLU//  

      .then(function(response) {

      api.parameters.updateAsync({name: "suyolu", value: 1});

      api.parameters.updateAsync({name: "sistem_gorunumu", value: 0});

      api.updateSettingAsync('scene.camera.cameraTypes.active', 0);

      zoomfunction();

      api.parameters.updateAsync({name: "suyolu", value: 1});

      api.parameters.updateAsync({name: "top_1", value: false});

      api.parameters.updateAsync({name: "top_2", value: false});

      api.parameters.updateAsync({name: "top_3", value: false});

      api.parameters.updateAsync({name: "top_4", value: true});

      api.parameters.updateAsync({name: "top_5", value: true});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      api.parameters.updateAsync({name: "side_1", value: false});

      api.parameters.updateAsync({name: "side_2", value: false});

      api.parameters.updateAsync({name: "side_3", value: false});

      api.parameters.updateAsync({name: "side_4", value: false});

      api.parameters.updateAsync({name: "front_1", value: false});

      api.parameters.updateAsync({name: "front_2", value: false});

      api.parameters.updateAsync({name: "front_3", value: false});

      api.parameters.updateAsync({name: "front_4", value: false});

      })

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[5].screenshot = api.scene.getScreenshotAsync();});})

    //ELEKTRİK//  

    .then(function(response){

      api.parameters.updateAsync({name: "suyolu", value: 0});

      api.parameters.updateAsync({name: "ledam_gorunumu", value: 1});

      api.updateSettingAsync('scene.camera.cameraTypes.active', 1);

      zoomfunction();

      api.parameters.updateAsync({name: "top_4", value: true});

      api.parameters.updateAsync({name: "top_5", value: true});

      api.parameters.updateAsync({name: "top_led_1", value: true});

      api.parameters.updateAsync({name: "top_led_2", value: true});

      api.parameters.updateAsync({name: "top_led_3", value: true});

      api.parameters.updateAsync({name: "top_led_4", value: true});

      

      })

    .then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})

    .then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[6].screenshot = api.scene.getScreenshotAsync();});})

    .then(function(response) {resList[6].screenshot = api.scene.getScreenshot(); return promiseTimeout(100);})

      //EN SON//  

    .then(function(response) 

        {

        $sagdan   = resList[3].screenshot;  document.getElementById("sagdan").src     = $sagdan;

        $onden    = resList[1].screenshot;  document.getElementById("onden").src      = $onden;

        $tepeden  = resList[2].screenshot;  document.getElementById("tepeden").src    = $tepeden;

        $ucboyut  = resList[4].screenshot;  document.getElementById("ucboyut").src    = $ucboyut;

        $suyolu   = resList[5].screenshot;  document.getElementById("suyolu").src     = $suyolu;

        $elektrik = resList[6].screenshot;  document.getElementById("elektrik").src   = $elektrik;

        resolve(resList);

        }

)}

);

};

where is wrong with my code?

I need 5 screenshot and for each screenshot, I need to wait until screen is ready…

@mathieu1 by the way ı did what you said but nothing changed… ( or I tried to do, I dont know) please if you check my code you an see where is the mistake…

@mathieu1 please can give me a hand?

@mathieu1 please a hand?

I am afraid reviewing and debugging this code would fall outside of the free support tier. Please contact our sales department if you want to learn about advanced support options.

I am already a pro member and I have “Forum Support”…?

Actually question is easy…

I want take 5 screenshot one screen ready after other…

for example

api.parameters.updateAsync({name: “top_led_2”, value: false});
api.parameters.updateAsync({name: “top_led_3”, value: false});

wait until that 2 commants done on screen and screen is ready to take screenshot…

Be sure screen is ready and than → take screenshot … first screenshot is DONE…

and same for others…

That is what I tried after you write an answer :

.then(function(response) {
api.updateSettingAsync(‘scene.camera.cameraTypes.active’, 3);
zoomfunction();
api.parameters.updateAsync({name: “top_led_2”, value: false});
api.parameters.updateAsync({name: “top_led_3”, value: false});
})
.then(function(response) {return api.scene.camera.zoomAsync(null,transitionParameters);})
.then(function(response) {api.scene.addEventListener(api.scene.EVENTTYPE.VISIBILITY_ON, function () {resList[1].screenshot = api.scene.getScreenshotAsync();});})

I can tell you from the code above that when you call parameters.updateAsync(), you do not wait for the promise to return, therefore the screenshot is probably taken before the parameter update happens. You need to include the parameters.updateAsync() calls in your sequence of promises (parameters.updateAsync().then(), etc…).

when I change “getScreenshot” with “getScreenshotAsync” it doesnt get screenshot (deosnt work for me)

even I just change that code in here and doesnt work in here also

EVENTTYPE.VISIBILITY_ON, is only working on opening page side…

EVENTTYPE.SUBSCENE_PUBLISHED is work everywhere… I dont know why…

anyway… for 2 days working on that and I just found “EVENTTYPE.SUBSCENE_PUBLISHED”

it is ok it waits and take screen shot one by one but for all .src data only last image goes there…

I think it is about I use “getScreenshot” in spite of “getScreenshotAsync”… cause “getScreenshotAsync” doesnt respond with anyway in onclick events

after I shared your example of taken screenshot , it is now invisible… I dont know why…

for the last “getScreenshotAsync” is not working ? please can you share me a documantation about how to use “getScreenshotAsync” ?

for 3 days I am trying to take screenshot etc as I explained but there is nothing yet…

Please help “Pro users” as forum support as your company promise…

I barely get information about what I ask…

Hi Haluk,

your PRO account includes Forum support, but there are certain guidelines that need to be followed. We can’t review full code (nor Grasshopper or API-related), as this falls outside of the type of support our team can provide via this communication channel.

If you want us to review your full code, we can gladly do so, but this would be considered private support. We can discuss these options and the associated costs via email.

Best,