LaserScript - t-oster/VisiCut GitHub Wiki
Besides reading design files like eps, svg etc. VisiCut can now also read and execute a javascript like language from a .ls file. This gives people a very flexible way to make lots of variation in things like speed and power.
You can open a .ls file just like you do other files. For mapping you can select the Everything cut profile. You could position and/or resize it. Press execute.
If the order in which parts are lasercutted is important you can alter the cut profile's Optimization setting from NEAREST to file. You can find this under:
Edit > Settings > Manage Laserprofiles... > cut.
You could also add a new Line Profile for this.
move(x,y);
Move to a x, y coordinate.
line(x,y);
Lasercut a line from the previous position (set with line or move) to a new x,y coordinate.
set(property, value);
Use for setting properties like speed and power e.g.:
set("power",50);
set("speed",50);
Which settings are available depends on the lasercutter. If you are using a LAOS driver, you can set power,speed,focus,ventilation and purge, where power and speed are in % but you can e.g. use 55.3, whereas in the epilog driver, you can only use power,speed,frequency and focus, where the values are integers in %, meaning you can only use values like 50 and 33, but not 33.3.
This gives you full control of the driver, but of cause makes the scripts somewhat not portable between devices. If laser-drivers are added, the properties like power,speed,frequency and focus, if available, will always called like that. They should be kept in percentages and mm (focus is in mm), but if a e.g nitting or a milling machine is added, they will have totally different properties.
You can check which values you can set, if you look at the "Laser Settings" panel while the right laser-cutter is selected and a vector-profile (like cut) is selected. (E.g. the epilog does not have a frequency setting in engrave mode, but right now laser-script is always working in vector/cut-mode)
get(property);
You can also retrieve the power set in VisiCut using the lasersettings, e.g.:
get("power");
get("speed");
echo(message);
Create a alert like message for debugging purposes. E.g.:
echo("somevalue: "+somevalue);
To ask for user input, use prompt(question, defaultAnswer)
. For numbers, there is a corresponding promptFloat(question, defaultAnswer)
function.
myString = prompt("What's your name", "<your name>");
myNumber = promptFloat("What's your favourite number", 123.45);
The default value will be used if the user clicks "cancel" or, for promptFloat
enters something which is not a number.
- If you execute a job, all prompts will be asked again.
-
promptFloat
is not locale-aware: Numbers always need to be entered with.
as separator, even if e.g.1.2
would in German be written as1,2
.
For security reasons you can only use a subset of JavaScript. The Math class is accessible, so you do for example:
var five = Math.abs(-5);
It's possible to disable this limit in preferences.
var space = 5;
var lineHeight = 5;
var numLines = 5;
var x = 0;
var speedStep = 100/(numLines-1);
set("power",100);
for (var i = 0; i < numLines; i++)
{
set("speed",i*speedStep);
line(x,lineHeight);
move(x+=space,0);
}
Go at it! Pull requests and suggestions are welcome!
Keep an eye on the issue queue for further developments.