-
Notifications
You must be signed in to change notification settings - Fork 5
Beam Studio Easy API
Dean Sung edited this page May 6, 2021
·
4 revisions
- Users can use a global class module called EasyManipulator, extending EventTarget
- The script's extension file name is .js, which runs as javascript. The script file can be executed by importing to the beam-studio.
let main = async () => {
// BVG file, which can be exported by Beam Studio
// you can use js FileReader to read string from .bvg file too.
const bvg = `
<svg id="svgcontent" width="3000" height="2100" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" data-top="-1300" data-left="-512" data-zoom="0.115" data-rotary_mode="false" data-engrave_dpi="medium">
<g data-repeat="1" data-strength="1" data-speed="20" clip-path="url(#scene_mask)" data-color="#333333" class="layer">
<title>Default</title>
<rect fill="black" vector-effect="non-scaling-stroke" fill-opacity="0" id="svg_1" stroke="#333333" height="913.57312" width="713.4571" y="196.98372" x="201.85626"/>
</g>
</svg>`;
let beamAPI = new EasyManipulator();
const onLoad = (event) => {
console.log('BVG loaded');
};
const onError = (event) => {
console.log('Error', event.detail);
};
const oldOnDone = (event) => {
console.log('Task Done', event.detail);
};
//Use addEventListener to register event
beamAPI.addEventListener('LOAD', onLoad);
beamAPI.addEventListener('DONE', oldOnDone);
beamAPI.addEventListener('ERROR', onError);
let res;
// Machine Name Here
res = await beamAPI.selectMachine('Mark');
// Click Beam Studio -> Menubar -> Help -> Debug Tool to open the console
console.log('Select result:', res);
res = await beamAPI.loadBVG(bvg);
console.log('Load BVG result:', res);
res = await beamAPI.calculate();
console.log('Calculate result:', res);
// Use removeEventListener to remove event function
beamAPI.removeEventListener('DONE', oldOnDone);
res = await beamAPI.start();
console.log('Start result:', res);
let interval = window.setInterval(() => {
console.log(beamAPI.getStatus());
}, 2000);
const newOnDone = (event) => {
console.log('(New) Task done', event.detail);
window.clearInterval(interval);
};
beamAPI.addEventListener('DONE', newOnDone);
}
main();Hooks the instance to specific machine
Returns: Boolean (Success or Failed)
Load BVG String (Similar to SVG, but with laser parameters)
Returns: Boolean (Success or Failed)
Run slicing, and returns time cost.
Returns: Object {success: Boolean, timeCost: Integer}
Upload the code to machine and start.
Returns: Boolean (Succeeded or Failed)
Resume the machine
Returns: Boolean (Succeeded or Failed)
Pause the machine
Returns: Boolean (Succeeded or Failed)
Abort the machine
Returns: Boolean (Succeeded or Failed)
Returns the machine state and progress
Status includes EasyManipulator.IDLE, EasyManipulator.READY, EasyManipulator.BUSY, EasyManipulator.WORKING, EasyManipulator.COMPLETED
Returns: {state: String, progress: Float}