Delay PDF compute until requested

I have implemented the PDF component into a definition, but as it takes a while to compute, id like to delay this until requested.

So I can set up a delay on a Boolean toggle with a stream filter, but then the end-user would need to switch the toggle and also to then need to click the export PDF button.

As such, I end up with 2 buttons and the stream filter needs to be enabled first.

How can I have the one button with the button enabling a compute of the pdf and then exporting the resultant file?

Would it be the same case using code in the API as suggested on an earlier post pasted below?..

Mathieu Huardmathieu1

May 24

We usually recommend to use boolean toggles in Grasshopper that prevent the computation of any logic that is not necessary for visualization. You can then hook any user action on your website (for example a purchase button) to a function that will first enable the boolean toggle and, once enabled, trigger the export. Something like this:

button.addEventListener("click", function(){
    api.parameters.updateAsync({name: "MyBooleanToggle"}).then(function(){
           api.exports.requestAsync({name: "MyExportAsset"});
        });
    });

Yes, that’s it. The code above will do what you need.

Thank you