I might add, my code doesn’t use any external sources… it’s simply reading value from form fields and concatenating the strings.
Here is the actual code I use:
// API Reference: Introduction - Velo API Reference - Wix.com
// “Hello, World!” Example: Velo Learning Center
var toolChangeButtonPressCode = “G0 X3 Y3 F2000 ; press the button\nG4 P400 ; dwell for .3 seconds\nG0 X-3 Y-3 ; back off the button\nG4 S2; wait for it to happen” ;
var toolChangeButtonLoop = “” ;
var toolChangeButtonFlip = false ;
var toolChangeButtonLong = “P5500” ;
var toolChangeButtonShort = “P3500” ;
var activeExtruder = “T0” ;
const regex = /T0/ ig ;
$w . onReady ( function () {
// Write your JavaScript here
// To select an element by ID use: $w("#elementID")
// Click "Preview" to run your code
});
export function button1_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
var buttonAxis = "" ;
var buttonLocation = 0 ;
var halfButton = 0 ;
var loadLength = 0 ;
var foobar = 0 ;
var loadGCode = "" ;
var unloadGCode = "" ;
var buttonGCode = "" ;
var toolChangeGCode = "" ;
var toolChangeLoadGCode = "" ;
var toolChangeUnloadGCode = "" ;
var slicerGCode = "" ;
buttonAxis = $w ( "#dropdown1" ). value ;
buttonLocation = Number ( $w ( "#input1" ). value )- 3 ;
halfButton = buttonLocation / 2 ;
loadLength = Number ( $w ( "#input2" ). value );
foobar = loadLength ;
$w ( "#slicerStartOutput" ). hide ();
$w ( "#slicerEndOutput" ). hide ();
slicerGCode = "; Auto generated 3D Chameleon Tool Change GCode for " + $w ( "#dropdown2" ). value + "\n\n" ;
if (( $w ( "#dropdown1" ). value )=== "X" )
{
buttonGCode = "G0 X" + buttonLocation . toString () + " Y" + halfButton . toString () + " F2000 " ;
}
**else**
{
buttonGCode = "G0 X" + halfButton . toString () + " Y" + buttonLocation . toString () + " F2000 " ;
}
**switch** ( $w ( "#dropdown2" ). value ) {
**case** "PrusaSlicer" :
toolChangeGCode = slicerGCode + $w ( "#PrusaTemplate" ). text ;
break ;
**case** "Simplify3D" :
toolChangeGCode = slicerGCode + $w ( "#Simplify3DTemplate" ). text ;
break ;
**case** "Cura" :
toolChangeLoadGCode = slicerGCode + "; --- Extruder #" + $w ( "#dropdown3" ). value + " Start G-Code ---\n\n" + $w ( "#CuraStartProfile" ). text ;
toolChangeUnloadGCode = slicerGCode + "; --- Extruder #" + $w ( "#dropdown3" ). value + " End G-Code ---\n\n" + $w ( "#CuraEndProfile" ). text ;
break ;
**default** :
break ;
}
**for** ( var i = 100 ; i < loadLength ; i = i + 100 ) {
unloadGCode = unloadGCode + "\nG92 E0\nG0 E-100 F2000" ;
loadGCode = loadGCode + "\nG92 E0\nG0 E100 F2000" ;
foobar = foobar - 100 ;
}
unloadGCode = unloadGCode + "\n" + "G92 E0\nG0 E-" + foobar + " F2000\nG92 E0" ;
loadGCode = loadGCode + "\n" + "G92 E0\nG0 E" + foobar + " F2000 ; <<<<<----------- EDIT THIS DISTANCE TO FINE TUNE THE FILAMENT LOADING TO STOP BLOBBING OR UNDEREXTRUSION\nG92 E0" ;
if (( $w ( "#dropdown2" ). value )=== "Cura" )
{
toolChangeLoadGCode = toolChangeLoadGCode . replace ( "{buttonLocation}" , buttonGCode );
toolChangeLoadGCode = toolChangeLoadGCode . replace ( "{loadGCode}" , loadGCode );
toolChangeLoadGCode = toolChangeLoadGCode . replace ( regex , activeExtruder );
toolChangeLoadGCode = toolChangeLoadGCode . replace ( "{buttonPressLoop}" , toolChangeButtonLoop );
if ( toolChangeButtonFlip === **false** )
{
toolChangeLoadGCode = toolChangeLoadGCode . replace ( "{buttonPressTime}" , toolChangeButtonLong );
toolChangeUnloadGCode = toolChangeUnloadGCode . replace ( "{buttonPressTime}" , toolChangeButtonShort );
}
**else**
{
toolChangeLoadGCode = toolChangeLoadGCode . replace ( "{buttonPressTime}" , toolChangeButtonShort );
toolChangeUnloadGCode = toolChangeUnloadGCode . replace ( "{buttonPressTime}" , toolChangeButtonLong );
}
toolChangeUnloadGCode = toolChangeUnloadGCode . replace ( "{buttonLocation}" , buttonGCode );
toolChangeUnloadGCode = toolChangeUnloadGCode . replace ( "{unloadGCode}" , unloadGCode );
toolChangeUnloadGCode = toolChangeUnloadGCode . replace ( regex , activeExtruder );
$w ( "#slicerOutput" ). hide ();
$w ( "#slicerStartOutput" ). show ();
$w ( "#slicerEndOutput" ). show ();
$w ( "#slicerStartOutput" ). value = toolChangeLoadGCode ;
$w ( "#slicerEndOutput" ). value = toolChangeUnloadGCode ;
}
**else**
{
$w ( "#slicerOutput" ). show ();
$w ( "#slicerStartOutput" ). hide ();
$w ( "#slicerEndOutput" ). hide ();
toolChangeGCode = toolChangeGCode . replace ( "{buttonLocation}" , buttonGCode );
toolChangeGCode = toolChangeGCode . replace ( "{unloadGCode}" , unloadGCode );
toolChangeGCode = toolChangeGCode . replace ( "{loadGCode}" , loadGCode );
$w ( "#slicerOutput" ). value = toolChangeGCode ;
}
}
export function dropdown2_change ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
if ( $w ( ‘#dropdown2’ ). value === “Cura” )
{
$w ( ‘#dropdown3’ ). enable ();
}
else
{
$w ( ‘#dropdown3’ ). disable ();
}
}
export function dropdown3_change ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
activeExtruder = “T” + ( Number (( $w ( ‘#dropdown3’ ). value ))- 1 ). toString ();
toolChangeButtonLoop = “” ;
var loop = Number (( $w ( '#dropdown3' ). value ))- 1 ;
if ( loop > 1 )
{
toolChangeButtonFlip = **true** ;
}
**else**
{
toolChangeButtonFlip = **false** ;
}
**for** ( var i = 0 ; i < loop ; i ++)
{
toolChangeButtonLoop = toolChangeButtonLoop + "\n" + toolChangeButtonPressCode + "\n" ;
}
}