Print at Dec 17, 2025, 7:32:10 PM

Posted by kingoftailor at Aug 13, 2022, 11:44:19 AM
Re: Sweet Home 3D JS Online
I modified the code. I omitted the planView.paintComponent line and put back the part planView.gridColor = oldGridColor from the original code. Even so, the downloaded image is perfectly fine and I don't see any changes in the floor plan after reloading the page.

The final code:


function AlaprajzMentes() {
let downloadLink = document.createElement('a');
downloadLink.setAttribute('download', 'alaprajz.jpg');

let canvas = document.getElementById('home-plan.canvas');
var planView = application.getHomeController(application.getHomes()[0]).getPlanController().getView();
var oldGridColor = planView.gridColor;
planView.gridColor = "white";
planView.repaint();
canvas.width = planView.getPreferredSize().width * 2;
canvas.height = planView.getPreferredSize().height * 2;

setTimeout(function () {
let dataURL = canvas.toDataURL('image/jpg');
let url = dataURL.replace(/^data:image\/jpg/, 'data:application/octet-stream');
downloadLink.setAttribute('href', url);
downloadLink.click();
planView.gridColor = oldGridColor;
planView.repaint();
window.location.reload();
}, 100);
}