Adding a "custom preset" and accessing it via a "custom GCode placeholder" June 23, 2019 12:16PM |
Registered: 5 years ago Posts: 14 |
Re: Adding a "custom preset" and accessing it via a "custom GCode placeholder" July 28, 2019 08:44PM |
Registered: 4 years ago Posts: 1 |
;define placeholder values here ;>>[custom_special_delay]=1000 ;use a placeholder anywhere after its definition G4 P[custom_special_delay]
@if (@CodeSection == @Batch) @then @cscript //Nologo //E:jscript "%~f0" %* & goto :eof @end //[stackoverflow.com] //[docs.microsoft.com] var FOR_READING = 1, FOR_WRITING = 2; //get the contents of the file var filename = WScript.Arguments(0), fso = new ActiveXObject("Scripting.FileSystemObject"), file = fso.GetFile(filename), ts = file.OpenAsTextStream(FOR_READING), input = ts.ReadAll(); ts.Close(); ts = file.OpenAsTextStream(FOR_WRITING); var rxp = /;\s*>>[(custom_\w+)\]\s*=\s*([a-z0-9]+(?:\s+[a-z0-9]+)*)\s*(?=;|\r?\n|$)/i, match; //overwrite the file as placeholders are replaced while( (match = rxp.exec(input)) ){ //WScript.Echo("Definition found:", match[1], match[2]); //write/append the text before-and-including the definition ts.Write(input.slice(0, match.index + match[0].length)); //truncate the input, and replace the placeholder throughout the remainder input = input.slice(match.index + match[0].length).replace(new RegExp("\["+match[1]+"\\]", "ig"), match[2]); } //write/append anything left from the input ts.Write(input); ts.Close();
Re: Adding a "custom preset" and accessing it via a "custom GCode placeholder" August 05, 2019 06:49AM |
Registered: 5 years ago Posts: 14 |