function getDateString() {
const today = new Date();
const date = `${today.getDate()}/${today.getMonth() + 1}/${today.getFullYear()}`;
const time = `${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}`;
return `Date: ${date}, Time: ${time}`;
}
function sendInfoToFusion() {
const args = {
arg1: document.getElementById("sampleData").value,
arg2: getDateString()
};
// Send the data to Fusion as a JSON string. The return value is a Promise.
adsk.fusionSendData("messageFromPalette", JSON.stringify(args)).then((result) =>
document.getElementById("returnValue").innerHTML = `${result}`
);
}
function updateMessage(messageString) {
// Message is sent from the add-in as a JSON string.
const messageData = JSON.parse(messageString);
// Update a paragraph with the data passed in.
document.getElementById("fusionMessage").innerHTML =
`Your text: ${messageData.myText}
` +
`Your expression: ${messageData.myExpression}
` +
`Your value: ${messageData.myValue}`;
}
window.fusionJavaScriptHandler = {
handle: function (action, data) {
try {
if (action === "updateMessage") {
updateMessage(data);
} else if (action === "debugger") {
debugger;
} else {
return `Unexpected command type: ${action}`;
}
} catch (e) {
console.log(e);
console.log(`Exception caught with command: ${action}, data: ${data}`);
}
return "OK";
},
};