├── .gitignore ├── .vscode └── settings.json ├── CamproCPV1100_TNC530 ├── CamproCPV1100iTNC530.cps ├── code.cps └── dump.cps ├── DoosanPuma3100 └── doosan mill-turn fanuc.cps ├── DuetCNC └── duetcnc.cps ├── Mazak ├── 4646.EIA ├── 9125.EIA ├── 9126.EIA ├── 9127.EIA ├── 9128.EIA ├── 9129.EIA ├── CircMill_O1001.EIA ├── CircMill_O1002.EIA ├── DiaTurn_O1001.EIA ├── DiaTurn_O1002.EIA ├── FaceTurn_O1001.EIA ├── FaceTurn_O1002.EIA ├── HMill_O1001.EIA ├── HMill_O1002.EIA ├── Integrex 300SY Adjustment.xlsx ├── VMill_O1001.EIA ├── VMill_O1002.EIA ├── code.cps ├── dump.cps └── mazak integrex 300SY.cps ├── MikronVCP1000_TNC426 ├── Mikron VCP1000 HDH426.cps ├── code.cps └── dump.cps ├── MikronWF41C_TNC355 ├── Mikron WF41C HDH355.cps ├── Mikron WF41C HDH355_spez.cps ├── code.cps └── dump.cps ├── README.md ├── Spinner_U1530 └── Spinner_U1530_HDH620.cps ├── protrak_mill ├── 24495_manual.pdf └── prototrak_mill.cps └── protrak_turning └── prototrak turning.cps /.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "lpubsppop01.autoTimeStamp.lineLimit": 50 3 | } -------------------------------------------------------------------------------- /CamproCPV1100_TNC530/code.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | FORKID {D38E0AF6-F1A7-4C6D-A0FA-C99BB29E65AE} 6 | */ 7 | 8 | description = "Export CNC file to Visual Studio Code"; 9 | vendor = "Autodesk"; 10 | vendorUrl = "http://www.autodesk.com"; 11 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 12 | certificationLevel = 2; 13 | minimumRevision = 41666; 14 | 15 | longDescription = "The post installs the CNC file for use with the Autodesk HSM Post Processor extension for Visual Studio Code."; 16 | 17 | capabilities = CAPABILITY_INTERMEDIATE; 18 | 19 | function onSection() { 20 | skipRemainingSection(); 21 | } 22 | 23 | function onClose() { 24 | var cncPath = getIntermediatePath(); 25 | var fileName = FileSystem.getFilename(cncPath); 26 | var destPath = FileSystem.getFolderPath(getOutputPath()); 27 | 28 | if (getPlatform() == "WIN32") { 29 | if (!FileSystem.isFolder(FileSystem.getTemporaryFolder())) { 30 | FileSystem.makeFolder(FileSystem.getTemporaryFolder()); 31 | } 32 | var path = FileSystem.getTemporaryFile("post"); 33 | 34 | var registryPaths = [ 35 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1", 36 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1", 37 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1", 38 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1", 39 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1", 40 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{D628A17A-9713-46BF-8D57-E671B46A741E}_is1" 41 | ]; 42 | 43 | var exePath; 44 | for (var i = 0; i < registryPaths.length; ++i) { 45 | if (hasRegistryValue(registryPaths[i], "InstallLocation")) { 46 | exePath = getRegistryString(registryPaths[i], "InstallLocation"); 47 | if (FileSystem.isFile(exePath + "\\code.exe")) { 48 | break; // found 49 | } 50 | } 51 | } 52 | 53 | if (exePath) { 54 | exePath = FileSystem.getCombinedPath(exePath, "\\bin\\code.cmd"); 55 | } else { 56 | error(localize("Visual Studio Code not found.")); 57 | return; 58 | } 59 | 60 | var a = "code --list-extensions --show-versions"; 61 | execute(exePath, a + ">" + path, false, ""); 62 | 63 | var result = {}; 64 | try { 65 | var file = new TextFile(path, false, "utf-8"); 66 | while (true) { 67 | var line = file.readln(); 68 | var index = line.indexOf("@"); 69 | if (index >= 0) { 70 | var name = line.substr(0, index); 71 | var value = line.substr(index + 1); 72 | result[name] = value; 73 | } 74 | } 75 | } catch (e) { 76 | // fail 77 | } 78 | file.close(); 79 | 80 | FileSystem.remove(path); 81 | 82 | var gotValues = false; 83 | for (var name in result) { 84 | gotValues = true; 85 | break; 86 | } 87 | 88 | var foundExtension = false; 89 | var extension; 90 | for (var name in result) { 91 | var value = result[name]; 92 | switch (name) { 93 | case "Autodesk.hsm-post-processor": 94 | extension = name + "-" + value; 95 | foundExtension = true; 96 | break; 97 | } 98 | } 99 | if (!foundExtension) { 100 | error(localize("Autodesk HSM Post Processor extension not found.")); 101 | return; 102 | } 103 | 104 | var userProfile = getEnvironmentVariable("USERPROFILE"); 105 | var extensionFolder = FileSystem.getCombinedPath(userProfile, "\\.vscode\\extensions\\" + extension); 106 | 107 | if (FileSystem.isFile(cncPath)) { 108 | if (!FileSystem.isFolder(extensionFolder)) { 109 | error(localize("Autodesk HSM Post Processor extension not found.")); 110 | return; 111 | } 112 | var customFolder = FileSystem.getCombinedPath(extensionFolder, "\\res\\CNC files\\Custom"); 113 | if (!FileSystem.isFolder(customFolder)) { 114 | FileSystem.makeFolder(customFolder); 115 | } 116 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(customFolder, fileName)); 117 | } 118 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + customFolder + "\"" + " and you can select it in VS Code."); 119 | } else { // non windows 120 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(destPath, fileName)); 121 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + destPath + "\"" + "."); 122 | writeln("You need to manually import the CNC file in VS Code by a right click into the CNC Selector panel and select 'Import CNC file...'."); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /CamproCPV1100_TNC530/dump.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2016 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | Dump configuration. 6 | 7 | $Revision: 41602 8a235290846bfe71ead6a010711f4fc730f48827 $ 8 | $Date: 2017-09-14 12:16:32 $ 9 | 10 | FORKID {4E9DFE89-DA1C-4531-98C9-7FECF672BD47} 11 | */ 12 | 13 | description = "Dumper"; 14 | vendor = "Autodesk"; 15 | vendorUrl = "http://www.autodesk.com"; 16 | legal = "Copyright (C) 2012-2016 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | 19 | longDescription = "Use this post to understand which information is available when developing a new post. The post will output the primary information for each entry function being called."; 20 | 21 | extension = "dmp"; 22 | // using user code page 23 | 24 | capabilities = CAPABILITY_INTERMEDIATE; 25 | 26 | allowMachineChangeOnSection = true; 27 | allowHelicalMoves = true; 28 | allowSpiralMoves = true; 29 | allowedCircularPlanes = undefined; // allow any circular motion 30 | maximumCircularSweep = toRad(1000000); 31 | minimumCircularRadius = spatial(0.001, MM); 32 | maximumCircularRadius = spatial(1000000, MM); 33 | 34 | // user-defined properties 35 | properties = { 36 | showState: true, // show the commonly interesting current state 37 | expandCycles: true // enable to expand cycles when supported 38 | }; 39 | 40 | // user-defined property definitions 41 | propertyDefinitions = { 42 | showState: {title:"Show state", description:"Shows the commonly interesting current state.", type:"boolean"}, 43 | expandCycles: {title:"Expand cycles", description:"If enabled, unhandled cycles are expanded.", type:"boolean"} 44 | }; 45 | 46 | 47 | var spatialFormat = createFormat({decimals:6}); 48 | var angularFormat = createFormat({decimals:6, scale:DEG}); 49 | var rpmFormat = createFormat({decimals:6}); 50 | var otherFormat = createFormat({decimals:6}); 51 | 52 | var expanding = false; 53 | 54 | function toString(value) { 55 | if (typeof value == "string") { 56 | return "'" + value + "'"; 57 | } else { 58 | return value; 59 | } 60 | } 61 | 62 | function dumpImpl(name, text) { 63 | writeln(getCurrentRecordId() + ": " + name + "(" + text + ")"); 64 | } 65 | 66 | function dump(name, _arguments) { 67 | var result = getCurrentRecordId() + ": " + (expanding ? "EXPANDED " : "") + name + "("; 68 | for (var i = 0; i < _arguments.length; ++i) { 69 | if (i > 0) { 70 | result += ", "; 71 | } 72 | if (typeof _arguments[i] == "string") { 73 | result += "'" + _arguments[i] + "'"; 74 | } else { 75 | result += _arguments[i]; 76 | } 77 | } 78 | result += ")"; 79 | writeln(result); 80 | } 81 | 82 | function onMachine() { 83 | dump("onMachine", arguments); 84 | if (machineConfiguration.getVendor()) { 85 | writeln(" " + "Vendor" + ": " + machineConfiguration.getVendor()); 86 | } 87 | if (machineConfiguration.getModel()) { 88 | writeln(" " + "Model" + ": " + machineConfiguration.getModel()); 89 | } 90 | if (machineConfiguration.getDescription()) { 91 | writeln(" " + "Description" + ": " + machineConfiguration.getDescription()); 92 | } 93 | } 94 | 95 | function onOpen() { 96 | dump("onOpen", arguments); 97 | } 98 | 99 | function onPassThrough() { 100 | dump("onPassThrough", arguments); 101 | } 102 | 103 | function onComment() { 104 | dump("onComment", arguments); 105 | } 106 | 107 | /** Write the current state. */ 108 | function dumpState() { 109 | if (!properties.showState) { 110 | return; 111 | } 112 | 113 | writeln(" STATE position=[" + spatialFormat.format(getCurrentPosition().x) + ", " + spatialFormat.format(getCurrentPosition().y) + ", " + spatialFormat.format(getCurrentPosition().z) + "]"); 114 | if ((currentSection.getType() == TYPE_MILLING) || (currentSection.getType() == TYPE_TURNING)) { 115 | writeln(" STATE spindleSpeed=" + rpmFormat.format(spindleSpeed)); 116 | } 117 | if (currentSection.getType() == TYPE_JET) { 118 | writeln(" STATE power=" + (power ? "ON" : "OFF")); 119 | } 120 | // writeln(" STATE movement=" + movement); 121 | // writeln(" STATE feedrate=" + spatialFormat.format(feedrate)); 122 | // writeln(" STATE compensationOffset=" + compensationOffset); 123 | 124 | var id; 125 | switch (radiusCompensation) { 126 | case RADIUS_COMPENSATION_OFF: 127 | id = "RADIUS_COMPENSATION_OFF"; 128 | break; 129 | case RADIUS_COMPENSATION_LEFT: 130 | id = "RADIUS_COMPENSATION_LEFT"; 131 | break; 132 | case RADIUS_COMPENSATION_RIGHT: 133 | id = "RADIUS_COMPENSATION_RIGHT"; 134 | break; 135 | } 136 | if (id != undefined) { 137 | writeln(" STATE radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 138 | } else { 139 | writeln(" STATE radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 140 | } 141 | } 142 | 143 | function onSection() { 144 | dump("onSection", arguments); 145 | 146 | var name; 147 | for (name in currentSection) { 148 | value = currentSection[name]; 149 | if (typeof value != "function") { 150 | writeln(" currentSection." + name + "=" + toString(value)); 151 | } 152 | } 153 | 154 | for (name in tool) { 155 | value = tool[name]; 156 | if (typeof value != "function") { 157 | writeln(" tool." + name + "=" + toString(value)); 158 | } 159 | } 160 | 161 | { 162 | var shaft = tool.shaft; 163 | if (shaft && shaft.hasSections()) { 164 | var n = shaft.getNumberOfSections(); 165 | for (var i = 0; i < n; ++i) { 166 | writeln(" tool.shaft[" + i + "] H=" + shaft.getLength(i) + " D=" + shaft.getDiameter(i)); 167 | } 168 | } 169 | } 170 | 171 | { 172 | var holder = tool.holder; 173 | if (holder && holder.hasSections()) { 174 | var n = holder.getNumberOfSections(); 175 | for (var i = 0; i < n; ++i) { 176 | writeln(" tool.holder[" + i + "] H=" + holder.getLength(i) + " D=" + holder.getDiameter(i)); 177 | } 178 | } 179 | } 180 | 181 | if (currentSection.isPatterned && currentSection.isPatterned()) { 182 | var patternId = currentSection.getPatternId(); 183 | var sections = []; 184 | var first = true; 185 | for (var i = 0; i < getNumberOfSections(); ++i) { 186 | var section = getSection(i); 187 | if (section.getPatternId() == patternId) { 188 | if (i < getCurrentSectionId()) { 189 | first = false; // not the first pattern instance 190 | } 191 | if (i != getCurrentSectionId()) { 192 | sections.push(section.getId()); 193 | } 194 | } 195 | } 196 | writeln(" >>> Pattern instances: " + sections); 197 | if (!first) { 198 | // writeln(" SKIPPING PATTERN INSTANCE"); 199 | // skipRemainingSection(); 200 | } 201 | } 202 | 203 | dumpState(); 204 | } 205 | 206 | function onSectionSpecialCycle() { 207 | dump("onSectionSpecialCycle", arguments); 208 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 209 | } 210 | 211 | function onPower() { 212 | dump("onPower", arguments); 213 | } 214 | 215 | function onSpindleSpeed() { 216 | dump("onSpindleSpeed", arguments); 217 | } 218 | 219 | function onParameter() { 220 | dump("onParameter", arguments); 221 | } 222 | 223 | function onDwell() { 224 | dump("onDwell", arguments); 225 | } 226 | 227 | function onCycle() { 228 | dump("onCycle", arguments); 229 | 230 | writeln(" cycleType=" + toString(cycleType)); 231 | for (var name in cycle) { 232 | value = cycle[name]; 233 | if (typeof value != "function") { 234 | writeln(" cycle." + name + "=" + toString(value)); 235 | } 236 | } 237 | } 238 | 239 | function onCyclePoint(x, y, z) { 240 | dump("onCyclePoint", arguments); 241 | 242 | if (properties.expandCycles) { 243 | 244 | switch (cycleType) { 245 | case "drilling": // G81 style 246 | case "counter-boring": // G82 style 247 | case "chip-breaking": // G73 style 248 | case "deep-drilling": // G83 style 249 | case "break-through-drilling": 250 | case "gun-drilling": 251 | case "tapping": 252 | case "left-tapping": // G74 style 253 | case "right-tapping": // G84 style 254 | case "tapping-with-chip-breaking": 255 | case "left-tapping-with-chip-breaking": 256 | case "right-tapping-with-chip-breaking": 257 | case "reaming": // G85 style 258 | case "boring": // G89 style 259 | case "stop-boring": // G86 style 260 | case "fine-boring": // G76 style 261 | case "back-boring": // G87 style 262 | case "manual-boring": 263 | case "bore-milling": 264 | case "thread-milling": 265 | case "circular-pocket-milling": 266 | expanding = true; 267 | expandCyclePoint(x, y, z); 268 | expanding = false; 269 | break; 270 | default: 271 | writeln(" CYCLE CANNOT BE EXPANDED"); 272 | } 273 | } 274 | 275 | dumpState(); 276 | } 277 | 278 | function onCycleEnd() { 279 | dump("onCycleEnd", arguments); 280 | } 281 | 282 | /** 283 | Returns the string id for the specified movement. Returns the movement id as 284 | a string if unknown. 285 | */ 286 | function getMovementStringId(movement, jet) { 287 | switch (movement) { 288 | case MOVEMENT_RAPID: 289 | return "rapid"; 290 | case MOVEMENT_LEAD_IN: 291 | return "lead in"; 292 | case MOVEMENT_CUTTING: 293 | return "cutting"; 294 | case MOVEMENT_LEAD_OUT: 295 | return "lead out"; 296 | case MOVEMENT_LINK_TRANSITION: 297 | return !jet ? "transition" : "bridging"; 298 | case MOVEMENT_LINK_DIRECT: 299 | return "direct"; 300 | case MOVEMENT_RAMP_HELIX: 301 | return !jet ? "helix ramp" : "circular pierce"; 302 | case MOVEMENT_RAMP_PROFILE: 303 | return !jet ? "profile ramp" : "profile pierce"; 304 | case MOVEMENT_RAMP_ZIG_ZAG: 305 | return !jet ? "zigzag ramp" : "linear pierce"; 306 | case MOVEMENT_RAMP: 307 | return !jet ? "ramp" : "pierce"; 308 | case MOVEMENT_PLUNGE: 309 | return !jet ? "plunge" : "pierce"; 310 | case MOVEMENT_PREDRILL: 311 | return "predrill"; 312 | case MOVEMENT_EXTENDED: 313 | return "extended"; 314 | case MOVEMENT_REDUCED: 315 | return "reduced"; 316 | case MOVEMENT_FINISH_CUTTING: 317 | return "finish cut"; 318 | case MOVEMENT_HIGH_FEED: 319 | return "high feed"; 320 | default: 321 | return String(movement); 322 | } 323 | } 324 | 325 | function onMovement(movement) { 326 | var jet = tool.isJetTool && tool.isJetTool(); 327 | var id; 328 | switch (movement) { 329 | case MOVEMENT_RAPID: 330 | id = "MOVEMENT_RAPID"; 331 | break; 332 | case MOVEMENT_LEAD_IN: 333 | id = "MOVEMENT_LEAD_IN"; 334 | break; 335 | case MOVEMENT_CUTTING: 336 | id = "MOVEMENT_CUTTING"; 337 | break; 338 | case MOVEMENT_LEAD_OUT: 339 | id = "MOVEMENT_LEAD_OUT"; 340 | break; 341 | case MOVEMENT_LINK_TRANSITION: 342 | id = jet ? "MOVEMENT_BRIDGING" : "MOVEMENT_LINK_TRANSITION"; 343 | break; 344 | case MOVEMENT_LINK_DIRECT: 345 | id = "MOVEMENT_LINK_DIRECT"; 346 | break; 347 | case MOVEMENT_RAMP_HELIX: 348 | id = jet ? "MOVEMENT_PIERCE_CIRCULAR" : "MOVEMENT_RAMP_HELIX"; 349 | break; 350 | case MOVEMENT_RAMP_PROFILE: 351 | id = jet ? "MOVEMENT_PIERCE_PROFILE" : "MOVEMENT_RAMP_PROFILE"; 352 | break; 353 | case MOVEMENT_RAMP_ZIG_ZAG: 354 | id = jet ? "MOVEMENT_PIERCE_LINEAR" : "MOVEMENT_RAMP_ZIG_ZAG"; 355 | break; 356 | case MOVEMENT_RAMP: 357 | id = "MOVEMENT_RAMP"; 358 | break; 359 | case MOVEMENT_PLUNGE: 360 | id = jet ? "MOVEMENT_PIERCE" : "MOVEMENT_PLUNGE"; 361 | break; 362 | case MOVEMENT_PREDRILL: 363 | id = "MOVEMENT_PREDRILL"; 364 | break; 365 | case MOVEMENT_EXTENDED: 366 | id = "MOVEMENT_EXTENDED"; 367 | break; 368 | case MOVEMENT_REDUCED: 369 | id = "MOVEMENT_REDUCED"; 370 | break; 371 | case MOVEMENT_HIGH_FEED: 372 | id = "MOVEMENT_HIGH_FEED"; 373 | break; 374 | } 375 | if (id != undefined) { 376 | dumpImpl("onMovement", id + " /*" + getMovementStringId(movement, jet) + "*/"); 377 | } else { 378 | dumpImpl("onMovement", movement + " /*" + getMovementStringId(movement, jet) + "*/"); 379 | } 380 | } 381 | 382 | var RADIUS_COMPENSATION_MAP = {0:"off", 1:"left", 2:"right"}; 383 | 384 | function onRadiusCompensation() { 385 | var id; 386 | switch (radiusCompensation) { 387 | case RADIUS_COMPENSATION_OFF: 388 | id = "RADIUS_COMPENSATION_OFF"; 389 | break; 390 | case RADIUS_COMPENSATION_LEFT: 391 | id = "RADIUS_COMPENSATION_LEFT"; 392 | break; 393 | case RADIUS_COMPENSATION_RIGHT: 394 | id = "RADIUS_COMPENSATION_RIGHT"; 395 | break; 396 | } 397 | dump("onRadiusCompensation", arguments); 398 | if (id != undefined) { 399 | writeln(" radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 400 | } else { 401 | writeln(" radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 402 | } 403 | } 404 | 405 | function onRapid() { 406 | dump("onRapid", arguments); 407 | } 408 | 409 | function onLinear() { 410 | dump("onLinear", arguments); 411 | } 412 | 413 | function onRapid5D() { 414 | dump("onRapid5D", arguments); 415 | } 416 | 417 | function onLinear5D() { 418 | dump("onLinear5D", arguments); 419 | } 420 | 421 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 422 | dump("onCircular", arguments); 423 | writeln(" direction: " + (clockwise ? "CW" : "CCW")); 424 | writeln(" sweep: " + angularFormat.format(getCircularSweep()) + "deg"); 425 | var n = getCircularNormal(); 426 | var plane = ""; 427 | switch (getCircularPlane()) { 428 | case PLANE_XY: 429 | plane = "(XY)"; 430 | break; 431 | case PLANE_ZX: 432 | plane = "(ZX)"; 433 | break; 434 | case PLANE_YZ: 435 | plane = "(YZ)"; 436 | break; 437 | } 438 | writeln(" normal: X=" + spatialFormat.format(n.x) + " Y=" + spatialFormat.format(n.y) + " Z=" + spatialFormat.format(n.z) + " " + plane); 439 | if (isSpiral()) { 440 | writeln(" spiral"); 441 | writeln(" start radius: " + spatialFormat.format(getCircularStartRadius())); 442 | writeln(" end radius: " + spatialFormat.format(getCircularRadius())); 443 | writeln(" delta radius: " + spatialFormat.format(getCircularRadius() - getCircularStartRadius())); 444 | } else { 445 | writeln(" radius: " + spatialFormat.format(getCircularRadius())); 446 | } 447 | if (isHelical()) { 448 | writeln(" helical pitch: " + spatialFormat.format(getHelicalPitch())); 449 | } 450 | } 451 | 452 | function onCommand(command) { 453 | if (isWellKnownCommand(command)) { 454 | dumpImpl("onCommand", getCommandStringId(command)); 455 | } else { 456 | dumpImpl("onCommand", command); 457 | } 458 | } 459 | 460 | function onSectionEnd() { 461 | dump("onSectionEnd", arguments); 462 | 463 | dumpState(); 464 | } 465 | 466 | function onSectionEndSpecialCycle() { 467 | dump("onSectionEndSpecialCycle", arguments); 468 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 469 | } 470 | 471 | function onClose() { 472 | dump("onClose", arguments); 473 | } 474 | -------------------------------------------------------------------------------- /DuetCNC/duetcnc.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | Mach3Mill post processor configuration. 6 | 7 | $Revision: 41981 b469d519b41034f7622245f52b01f620c0e5ec7e $ 8 | $Last Modified: 2023/04/12 18:30:35 9 | 10 | FORKID {A4D747BD-FEEF-4CE2-86CD-0D56966792FA} 11 | */ 12 | 13 | description = "CNC for Duet"; 14 | vendor = "CNC Router Parts"; 15 | vendorUrl = "http://www.cncrouterparts.com"; 16 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | minimumRevision = 24000; 19 | 20 | longDescription = "Router post Duet CNC"; 21 | 22 | extension = "gcode"; 23 | setCodePage("ascii"); 24 | 25 | capabilities = CAPABILITY_MILLING; 26 | tolerance = spatial(0.002, MM); 27 | 28 | minimumChordLength = spatial(0.25, MM); 29 | minimumCircularRadius = spatial(0.1, MM); 30 | maximumCircularRadius = spatial(1000, MM); 31 | minimumCircularSweep = toRad(0.1); 32 | maximumCircularSweep = toRad(180); 33 | allowHelicalMoves = true; 34 | 35 | 36 | // user-defined properties 37 | properties = { 38 | writeMachine: true, // write machine 39 | writeTools: true, // writes the tools 40 | writeVersion: true, // include version info 41 | useG28: false, // disable to avoid G28 output for safe machine retracts - when disabled you must manually ensure safe retracts 42 | useM6: false, // disable to avoid M6 output - preload is also disabled when M6 is disabled 43 | preloadTool: false, // preloads next tool on tool change if any 44 | showSequenceNumbers: false, // show sequence numbers 45 | sequenceNumberStart: 10, // first sequence number 46 | sequenceNumberIncrement: 5, // increment for sequence numbers 47 | optionalStop: true, // optional stop 48 | separateWordsWithSpace: true, // specifies that the words should be separated with a white space 49 | useRadius: true, // specifies that arcs should be output using the radius (R word) instead of the I, J, and K words. 50 | dwellInSeconds: true, // specifies the unit for dwelling: true:seconds and false:milliseconds. 51 | useDustCollector: false, // specifies if M7 and M9 are output for dust collector 52 | useRigidTapping: "whitout", // output rigid tapping block 53 | homeOnToolChange: true, //homes all axis after tool is changed and before it is potentailly probed 54 | probeToolOnChange: true, // probes a tool after changed in with by calling /macros/Tool Probe Auto 55 | manualToolChange: true //Asks for manual tool change and program is interrupted until tool change is confirmed. 56 | }; 57 | 58 | // user-defined property definitions 59 | propertyDefinitions = { 60 | writeMachine: { title: "Write machine", description: "Output the machine settings in the header of the code.", group: 0, type: "boolean" }, 61 | writeTools: { title: "Write tool list", description: "Output a tool list in the header of the code.", group: 0, type: "boolean" }, 62 | writeVersion: { title: "Write version", description: "Write the version number in the header of the code.", group: 0, type: "boolean" }, 63 | useG28: { title: "G28 Safe retracts", description: "Disable to avoid G28 output for safe machine retracts. When disabled, you must manually ensure safe retracts.", type: "boolean" }, 64 | useM6: { title: "Use M6", description: "Disable to avoid outputting M6. If disabled Preload is also disabled", group: 1, type: "boolean" }, 65 | preloadTool: { title: "Preload tool", description: "Preloads the next tool at a tool change (if any).", group: 1, type: "boolean" }, 66 | showSequenceNumbers: { title: "Use sequence numbers", description: "Use sequence numbers for each block of outputted code.", group: 1, type: "boolean" }, 67 | sequenceNumberStart: { title: "Start sequence number", description: "The number at which to start the sequence numbers.", group: 1, type: "integer" }, 68 | sequenceNumberIncrement: { title: "Sequence number increment", description: "The amount by which the sequence number is incremented by in each block.", group: 1, type: "integer" }, 69 | optionalStop: { title: "Optional stop", description: "Outputs optional stop code during when necessary in the code.", type: "boolean" }, 70 | separateWordsWithSpace: { title: "Separate words with space", description: "Adds spaces between words if 'yes' is selected.", type: "boolean" }, 71 | useRadius: { title: "Radius arcs", description: "If yes is selected, arcs are outputted using radius values rather than IJK.", type: "boolean" }, 72 | dwellInSeconds: { title: "Dwell in seconds", description: "Specifies the unit for dwelling, set to 'Yes' for seconds and 'No' for milliseconds.", type: "boolean" }, 73 | useDustCollector: { title: "Use dust collector", description: "Specifies if M7 and M9 are output for the dust collector.", type: "boolean" }, 74 | useRigidTapping: { 75 | title: "Use rigid tapping", 76 | description: "Select 'Yes' to enable, 'No' to disable, or 'Without spindle direction' to enable rigid tapping without outputting the spindle direction block.", 77 | type: "enum", 78 | values: [ 79 | { title: "Yes", id: "yes" }, 80 | { title: "No", id: "no" }, 81 | { title: "Without spindle direction", id: "without" } 82 | ] 83 | }, 84 | homeOnToolChange: { title: "Home axis on tool change", description: "Homes all axis after tool is changed and before it is potentailly probed.", type: "boolean" }, 85 | probeToolOnChange: { title: "Probe tool on tool change", description: "Probes a tool after changed in with by calling /macros/Tool Probe Auto.", type: "boolean" }, 86 | manualToolChange: { title: "Manual tool change", description: "Asks for manual tool change and program is interrupted until tool change is confirmed.", type: "boolean" } 87 | }; 88 | 89 | // samples: 90 | // throughTool: {on: 88, off: 89} 91 | // throughTool: {on: [8, 88], off: [9, 89]} 92 | var coolants = { 93 | flood: { on: 8 }, 94 | mist: { on: 7 }, 95 | throughTool: { on: 8 }, 96 | air: { on: 7 }, 97 | airThroughTool: { on: 8 }, 98 | suction: { on: 8 }, 99 | floodMist: {}, 100 | floodThroughTool: {}, 101 | off: 9 102 | }; 103 | 104 | 105 | var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-"; 106 | 107 | var nFormat = createFormat({ prefix: "N", decimals: 0 }); 108 | var gFormat = createFormat({ prefix: "G", decimals: 1 }); 109 | var mFormat = createFormat({ prefix: "M", decimals: 0 }); 110 | var hFormat = createFormat({ prefix: "H", decimals: 0 }); 111 | var pFormat = createFormat({ prefix: "P", decimals: (unit == MM ? 3 : 4), scale: 0.5 }); 112 | var xyzFormat = createFormat({ decimals: (unit == MM ? 3 : 4), forceDecimal: false }); 113 | var rFormat = xyzFormat; // radius 114 | var abcFormat = createFormat({ decimals: 3, forceDecimal: false, scale: DEG }); 115 | var feedFormat = createFormat({ decimals: (unit == MM ? 0 : 1), forceDecimal: false }); 116 | var toolFormat = createFormat({ decimals: 0 }); 117 | var rpmFormat = createFormat({ decimals: 0 }); 118 | var secFormat = createFormat({ decimals: 3, forceDecimal: false }); // seconds - range 0.001-99999.999 119 | var milliFormat = createFormat({ decimals: 0 }); // milliseconds // range 1-9999 120 | var taperFormat = createFormat({ decimals: 1, scale: DEG }); 121 | 122 | var xOutput = createVariable({ prefix: "X" }, xyzFormat); 123 | var yOutput = createVariable({ prefix: "Y" }, xyzFormat); 124 | var zOutput = createVariable({ onchange: function () { retracted = false; }, prefix: "Z" }, xyzFormat); 125 | var aOutput = createVariable({ prefix: "A" }, abcFormat); 126 | var bOutput = createVariable({ prefix: "B" }, abcFormat); 127 | var cOutput = createVariable({ prefix: "C" }, abcFormat); 128 | var feedOutput = createVariable({ prefix: "F", force: false }, feedFormat); 129 | var sOutput = createVariable({ prefix: "S", force: false }, rpmFormat); 130 | var pOutput = createVariable({}, pFormat); 131 | 132 | // circular output 133 | var iOutput = createReferenceVariable({ prefix: "I", force: false }, xyzFormat); 134 | var jOutput = createReferenceVariable({ prefix: "J", force: false }, xyzFormat); 135 | var kOutput = createReferenceVariable({ prefix: "K", force: false }, xyzFormat); 136 | 137 | var gMotionModal = createModal({ force: true }, gFormat); // modal group 1 // G0-G3, ... 138 | var gPlaneModal = createModal({ onchange: function () { gMotionModal.reset(); } }, gFormat); // modal group 2 // G17-19 139 | var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 140 | var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 141 | var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 142 | var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... 143 | var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 144 | 145 | var WARNING_WORK_OFFSET = 0; 146 | 147 | // collected state 148 | var sequenceNumber; 149 | var currentWorkOffset; 150 | var retracted = false; // specifies that the tool has been retracted to the safe plane 151 | 152 | /** 153 | Writes the specified block. 154 | */ 155 | function writeBlock() { 156 | var text = formatWords(arguments); 157 | if (!text) { 158 | return; 159 | } 160 | if (properties.showSequenceNumbers) { 161 | writeWords2(nFormat.format(sequenceNumber % 100000), arguments); 162 | sequenceNumber += properties.sequenceNumberIncrement; 163 | } else { 164 | writeWords(arguments); 165 | } 166 | } 167 | 168 | /** 169 | Output a comment. 170 | */ 171 | function writeComment(text) { 172 | writeln(";" + filterText(String(text).toUpperCase(), permittedCommentChars)); 173 | } 174 | 175 | function onOpen() { 176 | if (properties.useRadius) { 177 | maximumCircularSweep = toRad(90); // avoid potential center calculation errors for CNC 178 | } 179 | 180 | if (false) { 181 | var aAxis = createAxis({ coordinate: 0, table: true, axis: [-1, 0, 0], cyclic: true, preference: 1 }); 182 | machineConfiguration = new MachineConfiguration(aAxis); 183 | 184 | setMachineConfiguration(machineConfiguration); 185 | optimizeMachineAngles2(1); // map tip mode 186 | } 187 | 188 | if (!machineConfiguration.isMachineCoordinate(0)) { 189 | aOutput.disable(); 190 | } 191 | if (!machineConfiguration.isMachineCoordinate(1)) { 192 | bOutput.disable(); 193 | } 194 | if (!machineConfiguration.isMachineCoordinate(2)) { 195 | cOutput.disable(); 196 | } 197 | 198 | if (!properties.separateWordsWithSpace) { 199 | setWordSeparator(""); 200 | } 201 | 202 | sequenceNumber = properties.sequenceNumberStart; 203 | 204 | if (programName) { 205 | writeComment(programName); 206 | } 207 | if (programComment) { 208 | writeComment(programComment); 209 | } 210 | 211 | //write program generation date and time 212 | let current_datetime = new Date(); 213 | var date = current_datetime.getDate(); 214 | var month = current_datetime.getMonth() + 1; 215 | var year = current_datetime.getFullYear(); 216 | var hours = current_datetime.getHours(); 217 | var minutes = current_datetime.getMinutes(); 218 | var seconds = current_datetime.getSeconds(); 219 | yearFormatted = year; 220 | monthFormatted = month < 10 ? "0" + month : month; 221 | dateFormatted = date < 10 ? "0" + date : date; 222 | hoursFormatted = hours < 10 ? "0" + hours : hours; 223 | minutesFormatted = minutes < 10 ? "0" + minutes : minutes; 224 | secondsFormatted = seconds < 10 ? "0" + seconds : seconds; 225 | writeln(""); 226 | writeComment("Program created " + yearFormatted + "-" + monthFormatted + "-" + dateFormatted + " " + hoursFormatted + "-" + minutesFormatted + "-" + secondsFormatted); 227 | writeln(""); 228 | 229 | if (properties.writeVersion) { 230 | writeComment(localize("--- POST ---")); 231 | if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { 232 | writeComment(localize("post version") + ": " + getHeaderVersion()); 233 | } 234 | if ((typeof getHeaderDate == "function") && getHeaderDate()) { 235 | writeComment(localize("post modified") + ": " + getHeaderDate().replace(/:/g, "-")); 236 | } 237 | writeln(""); 238 | } 239 | 240 | // dump machine configuration 241 | var vendor = machineConfiguration.getVendor(); 242 | var model = machineConfiguration.getModel(); 243 | var description = machineConfiguration.getDescription(); 244 | 245 | if (properties.writeMachine && (vendor || model || description)) { 246 | writeComment(localize("Machine")); 247 | if (vendor) { 248 | writeComment(" " + localize("vendor") + ": " + vendor); 249 | } 250 | if (model) { 251 | writeComment(" " + localize("model") + ": " + model); 252 | } 253 | if (description) { 254 | writeComment(" " + localize("description") + ": " + description); 255 | } 256 | } 257 | 258 | // dump tool information 259 | if (properties.writeTools) { 260 | writeComment("--- Tools ---"); 261 | var zRanges = {}; 262 | if (is3D()) { 263 | var numberOfSections = getNumberOfSections(); 264 | for (var i = 0; i < numberOfSections; ++i) { 265 | var section = getSection(i); 266 | var zRange = section.getGlobalZRange(); 267 | var tool = section.getTool(); 268 | if (zRanges[tool.number]) { 269 | zRanges[tool.number].expandToRange(zRange); 270 | } else { 271 | zRanges[tool.number] = zRange; 272 | } 273 | } 274 | } 275 | 276 | var tools = getToolTable(); 277 | if (tools.getNumberOfTools() > 0) { 278 | for (var i = 0; i < tools.getNumberOfTools(); ++i) { 279 | var tool = tools.getTool(i); 280 | var comment = "T" + toolFormat.format(tool.number) + " " + 281 | "D=" + xyzFormat.format(tool.diameter) + " " + 282 | localize("CR") + "=" + xyzFormat.format(tool.cornerRadius); 283 | if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) { 284 | comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg"); 285 | } 286 | if (zRanges[tool.number]) { 287 | comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum()); 288 | } 289 | comment += " - " + getToolTypeName(tool.type); 290 | writeComment(comment); 291 | } 292 | } 293 | } 294 | 295 | if (false) { 296 | // check for duplicate tool number 297 | for (var i = 0; i < getNumberOfSections(); ++i) { 298 | var sectioni = getSection(i); 299 | var tooli = sectioni.getTool(); 300 | for (var j = i + 1; j < getNumberOfSections(); ++j) { 301 | var sectionj = getSection(j); 302 | var toolj = sectionj.getTool(); 303 | if (tooli.number == toolj.number) { 304 | if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) || 305 | xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) || 306 | abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) || 307 | (tooli.numberOfFlutes != toolj.numberOfFlutes)) { 308 | error( 309 | subst( 310 | localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."), 311 | sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)), 312 | sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1)) 313 | ) 314 | ); 315 | return; 316 | } 317 | } 318 | } 319 | } 320 | } 321 | 322 | if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { 323 | for (var i = 0; i < getNumberOfSections(); ++i) { 324 | if (getSection(i).workOffset > 0) { 325 | error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); 326 | return; 327 | } 328 | } 329 | } 330 | 331 | // absolute coordinates and feed per min 332 | writeBlock(gAbsIncModal.format(90)); 333 | 334 | switch (unit) { 335 | case IN: 336 | writeBlock(gUnitModal.format(20)); 337 | break; 338 | case MM: 339 | writeBlock(gUnitModal.format(21)); 340 | break; 341 | } 342 | 343 | // if (properties.useDustCollector) { 344 | // writeBlock(mFormat.format(7)); // turns on dust collector 345 | // } 346 | } 347 | 348 | function onComment(message) { 349 | var comments = String(message).split(";"); 350 | for (comment in comments) { 351 | writeComment(comments[comment]); 352 | } 353 | } 354 | 355 | /** Force output of X, Y, and Z. */ 356 | function forceXYZ() { 357 | xOutput.reset(); 358 | yOutput.reset(); 359 | zOutput.reset(); 360 | } 361 | 362 | /** Force output of A, B, and C. */ 363 | function forceABC() { 364 | aOutput.reset(); 365 | bOutput.reset(); 366 | cOutput.reset(); 367 | } 368 | 369 | /** Force output of X, Y, Z, A, B, C, and F on next output. */ 370 | function forceAny() { 371 | forceXYZ(); 372 | forceABC(); 373 | feedOutput.reset(); 374 | } 375 | 376 | var currentWorkPlaneABC = undefined; 377 | 378 | function forceWorkPlane() { 379 | currentWorkPlaneABC = undefined; 380 | } 381 | 382 | function setWorkPlane(abc) { 383 | if (!machineConfiguration.isMultiAxisConfiguration()) { 384 | return; // ignore 385 | } 386 | 387 | if (!((currentWorkPlaneABC == undefined) || 388 | abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || 389 | abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || 390 | abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { 391 | return; // no change 392 | } 393 | 394 | onCommand(COMMAND_UNLOCK_MULTI_AXIS); 395 | 396 | if (!retracted) { 397 | writeRetract(Z); 398 | } 399 | 400 | writeBlock( 401 | gMotionModal.format(0), 402 | conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), 403 | conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), 404 | conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) 405 | ); 406 | 407 | onCommand(COMMAND_LOCK_MULTI_AXIS); 408 | 409 | currentWorkPlaneABC = abc; 410 | } 411 | 412 | var closestABC = false; // choose closest machine angles 413 | var currentMachineABC; 414 | 415 | function getWorkPlaneMachineABC(workPlane) { 416 | var W = workPlane; // map to global frame 417 | 418 | var abc = machineConfiguration.getABC(W); 419 | if (closestABC) { 420 | if (currentMachineABC) { 421 | abc = machineConfiguration.remapToABC(abc, currentMachineABC); 422 | } else { 423 | abc = machineConfiguration.getPreferredABC(abc); 424 | } 425 | } else { 426 | abc = machineConfiguration.getPreferredABC(abc); 427 | } 428 | 429 | try { 430 | abc = machineConfiguration.remapABC(abc); 431 | currentMachineABC = abc; 432 | } catch (e) { 433 | error( 434 | localize("Machine angles not supported") + ":" 435 | + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) 436 | + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) 437 | + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) 438 | ); 439 | } 440 | 441 | var direction = machineConfiguration.getDirection(abc); 442 | if (!isSameDirection(direction, W.forward)) { 443 | error(localize("Orientation not supported.")); 444 | } 445 | 446 | if (!machineConfiguration.isABCSupported(abc)) { 447 | error( 448 | localize("Work plane is not supported") + ":" 449 | + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) 450 | + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) 451 | + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) 452 | ); 453 | } 454 | 455 | var tcp = true; 456 | if (tcp) { 457 | setRotation(W); // TCP mode 458 | } else { 459 | var O = machineConfiguration.getOrientation(abc); 460 | var R = machineConfiguration.getRemainingOrientation(abc, W); 461 | setRotation(R); 462 | } 463 | 464 | return abc; 465 | } 466 | 467 | function isProbeOperation() { 468 | return hasParameter("operation-strategy") && (getParameter("operation-strategy") == "probe"); 469 | } 470 | 471 | function onSection() { 472 | var insertToolCall = isFirstSection() || 473 | currentSection.getForceToolChange && currentSection.getForceToolChange() || 474 | (tool.number != getPreviousSection().getTool().number); 475 | 476 | retracted = false; 477 | var newWorkOffset = isFirstSection() || 478 | (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes 479 | var newWorkPlane = isFirstSection() || 480 | !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || 481 | (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && 482 | Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || 483 | (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || 484 | (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || 485 | getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations 486 | if (insertToolCall || newWorkOffset || newWorkPlane) { 487 | 488 | if (properties.useG28) { 489 | // retract to safe plane 490 | writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract 491 | writeBlock(gAbsIncModal.format(90)); 492 | zOutput.reset(); 493 | } 494 | } 495 | 496 | writeln(""); 497 | 498 | if (hasParameter("operation-comment")) { 499 | var comment = getParameter("operation-comment"); 500 | if (comment) { 501 | writeComment(comment); 502 | } 503 | } 504 | 505 | if (insertToolCall) { 506 | forceWorkPlane(); 507 | 508 | onCommand(COMMAND_STOP_SPINDLE); 509 | if (!properties.useDustCollector) { 510 | setCoolant(COOLANT_OFF); 511 | } 512 | 513 | if (!isFirstSection() && properties.optionalStop) { 514 | onCommand(COMMAND_OPTIONAL_STOP); 515 | } 516 | 517 | if (tool.number > 256) { 518 | warning(localize("Tool number exceeds maximum value.")); 519 | } 520 | 521 | if (properties.manualToolChange) { 522 | writeBlock(mFormat.format(291) + " P\"Insert Tool " + toolFormat.format(tool.number) + ", D=" + xyzFormat.format(tool.diameter) + "\" R\"Tool Change\" S2"); 523 | } 524 | 525 | if (properties.useM6) { 526 | writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); 527 | } else { 528 | writeBlock("T" + toolFormat.format(tool.number)); 529 | } 530 | 531 | if (properties.homeOnToolChange) { 532 | writeBlock(gFormat.format(28)); 533 | } 534 | 535 | if (properties.probeToolOnChange) { 536 | writeBlock(mFormat.format(98) + " P\"/macros/Tool Probe Auto\""); 537 | } 538 | 539 | if (tool.comment) { 540 | writeComment(tool.comment); 541 | } 542 | var showToolZMin = false; 543 | if (showToolZMin) { 544 | if (is3D()) { 545 | var numberOfSections = getNumberOfSections(); 546 | var zRange = currentSection.getGlobalZRange(); 547 | var number = tool.number; 548 | for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { 549 | var section = getSection(i); 550 | if (section.getTool().number != number) { 551 | break; 552 | } 553 | zRange.expandToRange(section.getGlobalZRange()); 554 | } 555 | writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); 556 | } 557 | } 558 | 559 | if (properties.preloadTool && properties.useM6) { 560 | var nextTool = getNextTool(tool.number); 561 | if (nextTool) { 562 | writeBlock("T" + toolFormat.format(nextTool.number)); 563 | } else { 564 | // preload first tool 565 | var section = getSection(0); 566 | var firstToolNumber = section.getTool().number; 567 | if (tool.number != firstToolNumber) { 568 | writeBlock("T" + toolFormat.format(firstToolNumber)); 569 | } 570 | } 571 | } 572 | } 573 | 574 | if (insertToolCall || 575 | isFirstSection() || 576 | (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) || 577 | (tool.clockwise != getPreviousSection().getTool().clockwise)) { 578 | if (tool.spindleRPM < 1) { 579 | error(localize("Spindle speed out of range.")); 580 | return; 581 | } 582 | if (tool.spindleRPM > 99999) { 583 | warning(localize("Spindle speed exceeds maximum value.")); 584 | } 585 | var tapping = hasParameter("operation:cycleType") && 586 | ((getParameter("operation:cycleType") == "tapping") || 587 | (getParameter("operation:cycleType") == "right-tapping") || 588 | (getParameter("operation:cycleType") == "left-tapping") || 589 | (getParameter("operation:cycleType") == "tapping-with-chip-breaking")); 590 | if (!tapping || (tapping && !(properties.useRigidTapping == "without"))) { 591 | writeBlock( 592 | mFormat.format(tool.clockwise ? 3 : 4), sOutput.format(tool.spindleRPM) 593 | ); 594 | writeBlock(mFormat.format(291) + " P\"Switch Router On\" S2"); 595 | 596 | } 597 | } 598 | 599 | // wcs 600 | if (insertToolCall) { // force work offset when changing tool 601 | currentWorkOffset = undefined; 602 | } 603 | var workOffset = currentSection.workOffset; 604 | if (workOffset == 0) { 605 | warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET); 606 | workOffset = 1; 607 | } 608 | if (workOffset > 0) { 609 | if (workOffset > 6) { 610 | var p = workOffset; // 1->... // G59 P1 is the same as G54 and so on 611 | if (p > 254) { 612 | error(localize("Work offset out of range.")); 613 | } else { 614 | if (workOffset != currentWorkOffset) { 615 | writeBlock(gFormat.format(59), "P" + p); // G59 P 616 | currentWorkOffset = workOffset; 617 | } 618 | } 619 | } else { 620 | if (workOffset != currentWorkOffset) { 621 | writeBlock(gFormat.format(53 + workOffset)); // G54->G59 622 | currentWorkOffset = workOffset; 623 | } 624 | } 625 | } 626 | 627 | forceXYZ(); 628 | 629 | if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode 630 | // set working plane after datum shift 631 | 632 | var abc = new Vector(0, 0, 0); 633 | if (currentSection.isMultiAxis()) { 634 | forceWorkPlane(); 635 | cancelTransformation(); 636 | } else { 637 | abc = getWorkPlaneMachineABC(currentSection.workPlane); 638 | } 639 | setWorkPlane(abc); 640 | } else { // pure 3D 641 | var remaining = currentSection.workPlane; 642 | if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { 643 | error(localize("Tool orientation is not supported.")); 644 | return; 645 | } 646 | setRotation(remaining); 647 | } 648 | 649 | // set coolant after we have positioned at Z 650 | if (!properties.useDustCollector) { 651 | setCoolant(tool.coolant); 652 | } 653 | 654 | forceAny(); 655 | gMotionModal.reset(); 656 | 657 | var initialPosition = getFramePosition(currentSection.getInitialPosition()); 658 | if (!retracted && !insertToolCall) { 659 | if (getCurrentPosition().z < initialPosition.z) { 660 | writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); 661 | } 662 | } 663 | 664 | if (insertToolCall || retracted) { 665 | var lengthOffset = tool.lengthOffset; 666 | if (lengthOffset > 256) { 667 | error(localize("Length offset out of range.")); 668 | return; 669 | } 670 | 671 | gMotionModal.reset(); 672 | //writeBlock(gPlaneModal.format(17)); 673 | 674 | if (!machineConfiguration.isHeadConfiguration()) { 675 | writeBlock( 676 | gAbsIncModal.format(90), 677 | gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y) 678 | ); 679 | writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); 680 | } else { 681 | writeBlock( 682 | gAbsIncModal.format(90), 683 | gMotionModal.format(0), 684 | gFormat.format(43), xOutput.format(initialPosition.x), 685 | yOutput.format(initialPosition.y), 686 | zOutput.format(initialPosition.z), hFormat.format(lengthOffset) 687 | ); 688 | } 689 | } else { 690 | writeBlock( 691 | gAbsIncModal.format(90), 692 | gMotionModal.format(0), 693 | xOutput.format(initialPosition.x), 694 | yOutput.format(initialPosition.y) 695 | ); 696 | } 697 | } 698 | 699 | function onDwell(seconds) { 700 | if (seconds > 99999.999) { 701 | warning(localize("Dwelling time is out of range.")); 702 | } 703 | if (properties.dwellInSeconds) { 704 | writeBlock(gFormat.format(4), "P" + secFormat.format(seconds)); 705 | } else { 706 | milliseconds = clamp(1, seconds * 1000, 99999999); 707 | writeBlock(gFormat.format(4), "P" + milliFormat.format(milliseconds)); 708 | } 709 | } 710 | 711 | function onSpindleSpeed(spindleSpeed) { 712 | writeBlock(sOutput.format(spindleSpeed)); 713 | } 714 | 715 | 716 | var pendingRadiusCompensation = -1; 717 | 718 | function onRadiusCompensation() { 719 | pendingRadiusCompensation = radiusCompensation; 720 | } 721 | 722 | function onRapid(_x, _y, _z) { 723 | var x = xOutput.format(_x); 724 | var y = yOutput.format(_y); 725 | var z = zOutput.format(_z); 726 | if (x || y || z) { 727 | if (pendingRadiusCompensation >= 0) { 728 | error(localize("Radius compensation mode cannot be changed at rapid traversal.")); 729 | return; 730 | } 731 | writeBlock(gMotionModal.format(0), x, y, z); 732 | feedOutput.reset(); 733 | } 734 | } 735 | 736 | function onLinear(_x, _y, _z, feed) { 737 | var x = xOutput.format(_x); 738 | var y = yOutput.format(_y); 739 | var z = zOutput.format(_z); 740 | var f = feedOutput.format(feed); 741 | if (x || y || z) { 742 | if (pendingRadiusCompensation >= 0) { 743 | pendingRadiusCompensation = -1; 744 | //writeBlock(gPlaneModal.format(17)); 745 | switch (radiusCompensation) { 746 | case RADIUS_COMPENSATION_LEFT: 747 | pOutput.reset(); 748 | writeBlock(gMotionModal.format(1), pOutput.format(tool.diameter), gFormat.format(41), x, y, z, f); 749 | break; 750 | case RADIUS_COMPENSATION_RIGHT: 751 | pOutput.reset(); 752 | writeBlock(gMotionModal.format(1), pOutput.format(tool.diameter), gFormat.format(42), x, y, z, f); 753 | break; 754 | default: 755 | writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f); 756 | } 757 | } else { 758 | writeBlock(gMotionModal.format(1), x, y, z, f); 759 | } 760 | } else if (f) { 761 | if (getNextRecord().isMotion()) { // try not to output feed without motion 762 | feedOutput.reset(); // force feed on next line 763 | } else { 764 | writeBlock(gMotionModal.format(1), f); 765 | } 766 | } 767 | } 768 | 769 | function onRapid5D(_x, _y, _z, _a, _b, _c) { 770 | if (!currentSection.isOptimizedForMachine()) { 771 | error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); 772 | return; 773 | } 774 | if (pendingRadiusCompensation >= 0) { 775 | error(localize("Radius compensation mode cannot be changed at rapid traversal.")); 776 | return; 777 | } 778 | var x = xOutput.format(_x); 779 | var y = yOutput.format(_y); 780 | var z = zOutput.format(_z); 781 | var a = aOutput.format(_a); 782 | var b = bOutput.format(_b); 783 | var c = cOutput.format(_c); 784 | writeBlock(gMotionModal.format(0), x, y, z, a, b, c); 785 | feedOutput.reset(); 786 | } 787 | 788 | function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { 789 | if (!currentSection.isOptimizedForMachine()) { 790 | error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); 791 | return; 792 | } 793 | if (pendingRadiusCompensation >= 0) { 794 | error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); 795 | return; 796 | } 797 | var x = xOutput.format(_x); 798 | var y = yOutput.format(_y); 799 | var z = zOutput.format(_z); 800 | var a = aOutput.format(_a); 801 | var b = bOutput.format(_b); 802 | var c = cOutput.format(_c); 803 | var f = feedOutput.format(feed); 804 | if (x || y || z || a || b || c) { 805 | writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f); 806 | } else if (f) { 807 | if (getNextRecord().isMotion()) { // try not to output feed without motion 808 | feedOutput.reset(); // force feed on next line 809 | } else { 810 | writeBlock(gMotionModal.format(1), f); 811 | } 812 | } 813 | } 814 | 815 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 816 | if (pendingRadiusCompensation >= 0) { 817 | error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); 818 | return; 819 | } 820 | 821 | var start = getCurrentPosition(); 822 | 823 | if (isFullCircle()) { 824 | if (properties.useRadius || isHelical()) { // radius mode does not support full arcs 825 | linearize(tolerance); 826 | return; 827 | } 828 | switch (getCircularPlane()) { 829 | case PLANE_XY: 830 | writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); 831 | break; 832 | // case PLANE_ZX: 833 | // writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed)); 834 | // break; 835 | // case PLANE_YZ: 836 | // writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed)); 837 | // break; 838 | default: 839 | linearize(tolerance); 840 | } 841 | } else if (!properties.useRadius) { 842 | switch (getCircularPlane()) { 843 | case PLANE_XY: 844 | writeBlock(gAbsIncModal.format(90), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed)); 845 | break; 846 | // case PLANE_ZX: 847 | // writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed)); 848 | // break; 849 | // case PLANE_YZ: 850 | // writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), feedOutput.format(feed)); 851 | // break; 852 | default: 853 | linearize(tolerance); 854 | } 855 | } else { // use radius mode 856 | var r = getCircularRadius(); 857 | if (toDeg(getCircularSweep()) > (180 + 1e-9)) { 858 | r = -r; // allow up to <360 deg arcs 859 | } 860 | switch (getCircularPlane()) { 861 | case PLANE_XY: 862 | writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); 863 | break; 864 | // case PLANE_ZX: 865 | // writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); 866 | // break; 867 | // case PLANE_YZ: 868 | // writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), feedOutput.format(feed)); 869 | // break; 870 | default: 871 | linearize(tolerance); 872 | } 873 | } 874 | } 875 | 876 | var currentCoolantMode = undefined; 877 | var coolantOff = undefined; 878 | 879 | function setCoolant(coolant) { 880 | var coolantCodes = getCoolantCodes(coolant); 881 | if (Array.isArray(coolantCodes)) { 882 | for (var c in coolantCodes) { 883 | //writeBlock(coolantCodes[c]); 884 | } 885 | return undefined; 886 | } 887 | return coolantCodes; 888 | } 889 | 890 | function getCoolantCodes(coolant) { 891 | if (!coolants) { 892 | error(localize("Coolants have not been defined.")); 893 | } 894 | if (!coolantOff) { // use the default coolant off command when an 'off' value is not specified for the previous coolant mode 895 | coolantOff = coolants.off; 896 | } 897 | 898 | if (isProbeOperation()) { // avoid coolant output for probing 899 | coolant = COOLANT_OFF; 900 | } 901 | 902 | if (coolant == currentCoolantMode) { 903 | return undefined; // coolant is already active 904 | } 905 | 906 | var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line 907 | if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF)) { 908 | multipleCoolantBlocks.push(mFormat.format(coolantOff)); 909 | } 910 | 911 | var m; 912 | if (coolant == COOLANT_OFF) { 913 | m = coolantOff; 914 | coolantOff = coolants.off; 915 | } 916 | 917 | switch (coolant) { 918 | case COOLANT_FLOOD: 919 | if (!coolants.flood) { 920 | break; 921 | } 922 | m = coolants.flood.on; 923 | coolantOff = coolants.flood.off; 924 | break; 925 | case COOLANT_THROUGH_TOOL: 926 | if (!coolants.throughTool) { 927 | break; 928 | } 929 | m = coolants.throughTool.on; 930 | coolantOff = coolants.throughTool.off; 931 | break; 932 | case COOLANT_AIR: 933 | if (!coolants.air) { 934 | break; 935 | } 936 | m = coolants.air.on; 937 | coolantOff = coolants.air.off; 938 | break; 939 | case COOLANT_AIR_THROUGH_TOOL: 940 | if (!coolants.airThroughTool) { 941 | break; 942 | } 943 | m = coolants.airThroughTool.on; 944 | coolantOff = coolants.airThroughTool.off; 945 | break; 946 | case COOLANT_FLOOD_MIST: 947 | if (!coolants.floodMist) { 948 | break; 949 | } 950 | m = coolants.floodMist.on; 951 | coolantOff = coolants.floodMist.off; 952 | break; 953 | case COOLANT_MIST: 954 | if (!coolants.mist) { 955 | break; 956 | } 957 | m = coolants.mist.on; 958 | coolantOff = coolants.mist.off; 959 | break; 960 | case COOLANT_SUCTION: 961 | if (!coolants.suction) { 962 | break; 963 | } 964 | m = coolants.suction.on; 965 | coolantOff = coolants.suction.off; 966 | break; 967 | case COOLANT_FLOOD_THROUGH_TOOL: 968 | if (!coolants.floodThroughTool) { 969 | break; 970 | } 971 | m = coolants.floodThroughTool.on; 972 | coolantOff = coolants.floodThroughTool.off; 973 | break; 974 | } 975 | 976 | if (!m) { 977 | onUnsupportedCoolant(coolant); 978 | m = 9; 979 | } 980 | 981 | if (m) { 982 | if (Array.isArray(m)) { 983 | for (var i in m) { 984 | multipleCoolantBlocks.push(mFormat.format(m[i])); 985 | } 986 | } else { 987 | multipleCoolantBlocks.push(mFormat.format(m)); 988 | } 989 | currentCoolantMode = coolant; 990 | return multipleCoolantBlocks; // return the single formatted coolant value 991 | } 992 | return undefined; 993 | } 994 | 995 | var mapCommand = { 996 | COMMAND_STOP: 0, 997 | COMMAND_OPTIONAL_STOP: 1, 998 | COMMAND_END: 2, 999 | COMMAND_SPINDLE_CLOCKWISE: 3, 1000 | COMMAND_SPINDLE_COUNTERCLOCKWISE: 4, 1001 | COMMAND_STOP_SPINDLE: 5, 1002 | COMMAND_LOAD_TOOL: 6 1003 | }; 1004 | 1005 | function onCommand(command) { 1006 | switch (command) { 1007 | case COMMAND_START_SPINDLE: 1008 | onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); 1009 | return; 1010 | case COMMAND_LOCK_MULTI_AXIS: 1011 | return; 1012 | case COMMAND_UNLOCK_MULTI_AXIS: 1013 | return; 1014 | case COMMAND_BREAK_CONTROL: 1015 | return; 1016 | case COMMAND_TOOL_MEASURE: 1017 | return; 1018 | } 1019 | 1020 | var stringId = getCommandStringId(command); 1021 | var mcode = mapCommand[stringId]; 1022 | if (mcode != undefined) { 1023 | writeBlock(mFormat.format(mcode)); 1024 | } else { 1025 | onUnsupportedCommand(command); 1026 | } 1027 | } 1028 | 1029 | function onSectionEnd() { 1030 | //writeBlock(gPlaneModal.format(17)); 1031 | 1032 | if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || 1033 | (tool.number != getNextSection().getTool().number)) { 1034 | onCommand(COMMAND_BREAK_CONTROL); 1035 | } 1036 | 1037 | forceAny(); 1038 | } 1039 | 1040 | /** Output block to do safe retract and/or move to home position. */ 1041 | function writeRetract() { 1042 | if (arguments.length == 0) { 1043 | error(localize("No axis specified for writeRetract().")); 1044 | return; 1045 | } 1046 | var words = []; // store all retracted axes in an array 1047 | for (var i = 0; i < arguments.length; ++i) { 1048 | let instances = 0; // checks for duplicate retract calls 1049 | for (var j = 0; j < arguments.length; ++j) { 1050 | if (arguments[i] == arguments[j]) { 1051 | ++instances; 1052 | } 1053 | } 1054 | if (instances > 1) { // error if there are multiple retract calls for the same axis 1055 | error(localize("Cannot retract the same axis twice in one line")); 1056 | return; 1057 | } 1058 | switch (arguments[i]) { 1059 | case X: 1060 | if (!machineConfiguration.hasHomePositionX()) { 1061 | if (properties.useG28) { 1062 | words.push("X" + xyzFormat.format(0)); 1063 | } 1064 | } else { 1065 | words.push("X" + xyzFormat.format(machineConfiguration.getHomePositionX())); 1066 | } 1067 | break; 1068 | case Y: 1069 | if (!machineConfiguration.hasHomePositionY()) { 1070 | if (properties.useG28) { 1071 | words.push("Y" + xyzFormat.format(0)); 1072 | } 1073 | } else { 1074 | words.push("Y" + xyzFormat.format(machineConfiguration.getHomePositionY())); 1075 | } 1076 | break; 1077 | case Z: 1078 | if (properties.useG28) { 1079 | writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(machineConfiguration.getRetractPlane())); 1080 | writeBlock(gAbsIncModal.format(90)); 1081 | zOutput.reset(); 1082 | } 1083 | retracted = properties.useG28; // specifies that the tool has been retracted to the safe plane 1084 | break; 1085 | default: 1086 | error(localize("Bad axis specified for writeRetract().")); 1087 | return; 1088 | } 1089 | } 1090 | if (words.length > 0) { 1091 | gMotionModal.reset(); 1092 | if (properties.useG28) { 1093 | gAbsIncModal.reset(); 1094 | writeBlock(gFormat.format(28), gAbsIncModal.format(91), words); // retract 1095 | writeBlock(gAbsIncModal.format(90)); 1096 | } else { 1097 | writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words); 1098 | } 1099 | } 1100 | } 1101 | 1102 | function onClose() { 1103 | writeln(""); 1104 | 1105 | // if (properties.useDustCollector) { 1106 | // writeBlock(mFormat.format(9)); // turns off dust collector 1107 | // } else { 1108 | // setCoolant(COOLANT_OFF); 1109 | // } 1110 | 1111 | writeRetract(Z); 1112 | 1113 | setWorkPlane(new Vector(0, 0, 0)); // reset working plane 1114 | 1115 | writeRetract(X, Y); 1116 | 1117 | onImpliedCommand(COMMAND_END); 1118 | onImpliedCommand(COMMAND_STOP_SPINDLE); 1119 | writeBlock(mFormat.format(5)); // stop program, spindle stop, coolant off 1120 | } 1121 | -------------------------------------------------------------------------------- /Mazak/4646.EIA: -------------------------------------------------------------------------------- 1 | O4646 2 | 3 | (SCRIPT TO PEEK PARAMETERS) 4 | N10 5 | #141=1 6 | #142=1 7 | #143=PEEK[11,410,1,0,0] 8 | 9 | N20 10 | #101=PEEK[#141,#142,#143,1] 11 | #102=PEEK[#141,#142,#143,2] 12 | #103=PEEK[#141,#142,#143,3] 13 | #104=PEEK[#141,#142,#143,4] 14 | #105=PEEK[#141,#142,#143,5] 15 | #106=PEEK[#141,#142,#143,6] 16 | #107=PEEK[#141,#142,#143,7] 17 | #108=PEEK[#141,#142,#143,8] 18 | #109=PEEK[#141,#142,#143,9] 19 | #110=PEEK[#141,#142,#143,10] 20 | #111=PEEK[#141,#142,#143,11] 21 | #112=PEEK[#141,#142,#143,12] 22 | #113=PEEK[#141,#142,#143,13] 23 | #114=PEEK[#141,#142,#143,14] 24 | #115=PEEK[#141,#142,#143,15] 25 | #116=PEEK[#141,#142,#143,16] 26 | #117=PEEK[#141,#142,#143,17] 27 | #118=PEEK[#141,#142,#143,18] 28 | #119=PEEK[#141,#142,#143,19] 29 | #120=PEEK[#141,#142,#143,20] 30 | #121=PEEK[#141,#142,#143,21] 31 | #122=PEEK[#141,#142,#143,22] 32 | #123=PEEK[#141,#142,#143,23] 33 | #124=PEEK[#141,#142,#143,24] 34 | #125=PEEK[#141,#142,#143,25] 35 | #126=PEEK[#141,#142,#143,26] 36 | #127=PEEK[#141,#142,#143,27] 37 | #128=PEEK[#141,#142,#143,28] 38 | #129=PEEK[#141,#142,#143,29] 39 | #130=PEEK[#141,#142,#143,30] 40 | #131=PEEK[#141,#142,#143,31] 41 | #132=PEEK[#141,#142,#143,32] 42 | N30 43 | 44 | M30 -------------------------------------------------------------------------------- /Mazak/9125.EIA: -------------------------------------------------------------------------------- 1 | O9125 2 | (G125-TILT MACRO) 3 | 4 | (FOR INTEGREX 300SY) 5 | ($Last Modified: 2023/01/27 20:55:49 6 | (NORMAL G-CODE TYPE C, P16 BIT3=1, P9 BIT2=1, P9 BIT3=1) 7 | 8 | (IN A BLOCK WITH G125 NO FURTHER G-CODES CAN BE EXECUTED) 9 | (PARAMETER K82 125 9125 OR OTHER SUITED PARAMETER) 10 | (EVERYTHING CAN BE CANCELED WITH G69.5) 11 | 12 | (FORMAT) 13 | (X - X-VALUE SHIFT FOR G68.5, optional) 14 | (Y - Y-VALUE SHIFT FOR G68.5, optional) 15 | (Z - Z-VALUE SHIFT FOR G68.5, optional) 16 | (B - POSITION B-AXIS, optional) 17 | (I1.- G68.5 WITH ROTATION I0.- G68.5 WITHOUT ROTATION) 18 | 19 | (CANCEL ANY EXISTING KOORDINATSYSTEMTRANFORMATION IF STILL ACTIVE) 20 | IF[#4016EQ69.5] GOTO 5 21 | G69.5 22 | N5 23 | 24 | G122.1 (SET RADIUS MODE) 25 | 26 | (GET THE INPUT PARAMETRS) 27 | #120=#24 (X-PARAMETER) 28 | #121=#25 (Y-PARAMETER) 29 | #122=#26 (Z-PARAMETER) 30 | #123=#2 (B-PARAMETER) 31 | #124=#4 (I-PARAMETER) 32 | 33 | (SET DEFAULTS FOR X- Y- AND Z-OFFSET) 34 | IF[#120NE#0] GOTO 10 35 | #120=0 (SET X0 IF INPUT EMPTY) 36 | N10 37 | IF[#121NE#0] GOTO 20 38 | #121=0 (SET Y0 IF INPUT EMPTY) 39 | N20 40 | IF[#122NE#0] GOTO 30 41 | #122=0 (SET Z0 IF INPUT EMPTY) 42 | N30 43 | IF[#123NE#0] GOTO 40 44 | #123=0 (SET B0 IF INPUT EMPTY) 45 | N40 46 | IF[#124NE#0] GOTO 50 47 | #124=1 (SET I1 IF INPUT EMPTY) 48 | N50 49 | 50 | IF[#124EQ0] GOTO 60 51 | IF[#124EQ1] GOTO 60 52 | N1000 #3000=70(INVALID I-VALUE) 53 | M30 (END OF PROGRAM) 54 | N60 55 | 56 | #130=SIN[#123]*#516 (CALCULATE PROJECTED TOOL LENGTH IN X-DIRECTION) 57 | #131=COS[#123]*#516-#516 (CALCULATE PROJECTED TOOL LENGTH IN Z-DIRECTION) 58 | #132=COS[#123]*#517-#517 (CALCULATE PROJECTED TOOL LENGTH IN X-DIRECTION) 59 | #133=SIN[#123]*#517 (CALCULATE PROJECTED TOOL LENGTH IN Z-DIRECTION) 60 | N70 61 | 62 | #125=#5041 (GET CURRENT X-POSITON) 63 | #126=#5044 (GET CURRENT Y-POSITON) 64 | #127=#5042 (GET CURRENT Z-POSITION) 65 | N80 66 | 67 | #134=#120-#130-#132 (TOTAL TOOL CORRECTION X) 68 | #135=#121 (TOTAL TOOL CORRECTION Y) 69 | #136=#122-#131-#133 (TOTAL TOOL CORRECTION Z) 70 | 71 | #140=#125+#134 (CORRECTED X-POSITION) 72 | #141=#126+#135 (CORRECTED Y-POSITION) 73 | #142=#127+#136 (CORRECTED Z-POSITION) 74 | 75 | N90 76 | IF [#124NE0] GOTO 100 77 | G92 X[#140] Y[#141] Z[#142] 78 | (G68.5 X0. Y0. Z0. I0 J1 K0 R0. (SET 68.5 WITHOUT ROTATION) 79 | N100 80 | IF [#124NE1] GOTO 110 (CHECK IF G68.5 HAS TO BE SET) 81 | G92 X[#140] Y[#141] Z[#142] 82 | N101 83 | G68.5 X0. Y0. Z0. I0 J1 K0 R#123. (SET G68.5 WITH ROTATION) 84 | N110 85 | 86 | (CLEAN UP) 87 | #120=#0 88 | #121=#0 89 | #122=#0 90 | #123=#0 91 | #124=#0 92 | #125=#0 93 | #126=#0 94 | #127=#0 95 | #128=#0 96 | #129=#0 97 | #130=#0 98 | #131=#0 99 | #132=#0 100 | #133=#0 101 | 102 | #140=#0 103 | #141=#0 104 | #142=#0 105 | 106 | M99 (END OF MACRO) 107 | 108 | (ALARMS) 109 | N1000 #3000=70(G125 NO TOOL SPECIFIED) 110 | M99 (END OF PROGRAM) 111 | 112 | 113 | -------------------------------------------------------------------------------- /Mazak/9126.EIA: -------------------------------------------------------------------------------- 1 | O9126 2 | (CANCEL G68.5 BUT CHECKING THAT G69.5 HAS NOT YET BEEN ISSUED AS OTHERWISE STRANGE COORDINATE SHIFTS CAN HAPPEN) 3 | 4 | (FOR INTEGREX 300SY) 5 | ($Last Modified: 2023/01/27 20:55:49 6 | (NORMAL G-CODE TYPE C, P16 BIT3=1, P9 BIT2=1, P9 BIT3=1) 7 | 8 | IF[#4016EQ69.5] GOTO 100 9 | G69.5 10 | 11 | G122.1 (SET RADIUS MODE) 12 | 13 | #125=#5041 (GET CURRENT X-POSITON) 14 | #126=#5044 (GET CURRENT Y-POSITON) 15 | #127=#5042 (GET CURRENT Z-POSITION) 16 | 17 | N10 18 | IF[#134NE#0] GOTO 20 19 | #134 = 0. 20 | N20 21 | IF[#135NE#0] GOTO 30 22 | #135 = 0. 23 | N30 24 | IF[#136NE#0] GOTO 40 25 | #136 = 0. 26 | N40 27 | 28 | G92 X[#125-#134] Y[#126-#135] Z[#127-#136] 29 | N100 30 | 31 | (CLEAN UP) 32 | #125=#0 33 | #126=#0 34 | #127=#0 35 | #134=#0 36 | #135=#0 37 | #136=#0 38 | 39 | M99 (END OF MACRO) 40 | 41 | -------------------------------------------------------------------------------- /Mazak/9127.EIA: -------------------------------------------------------------------------------- 1 | O9127 2 | (G127- CALCUlATE TOOL LENGTH FROM ROTATION CENTER AND STORE VALUE IN #516) 3 | 4 | (FOR INTEGREX 300SY) 5 | ($Last Modified: 2023/01/27 20:01:18 6 | (NORMAL G-CODE TYPE C, P16 BIT3=1, P9 BIT2=1, P9 BIT3=1) 7 | 8 | (IN A BLOCK WITH G127 NO FURTHER G-CODES CAN BE EXECUTED) 9 | (PARAMETER K82 125 9125 OR OTHER SUITED PARAMETER) 10 | (EVERYTHING CAN BE CANCELED WITH G69.5) 11 | 12 | #1=PEEK[11,410,1,0,0] (GET TOOL IN HEAD) 13 | IF[#1EQ#0] GOTO 1000 (CHECK IF TOOL_NR IS NOT EMPTY) 14 | IF[#1EQ0] GOTO 1000 (CHECK IF TOOL_NR IS NOT 0) 15 | 16 | #2=PEEK[1,1,#1,2] (GET TOOL Z-OFFSET) 17 | #3=PEEK[1,1,#1,4] (GET TOOL Z-WEAR) 18 | #4=PEEK[5,3,234] (GET PARAMETER B234) 19 | #6=PEEK[5,3,262] (GET PARAMETER B262) 20 | #7=PEEK[5,3,263] (GET PARAMETER B263) 21 | #8=PEEK[5,3,264] (GET PARAMETER B264) 22 | #9=PEEK[5,3,271] (GET PARAMETER B271) 23 | 24 | #10=#4+#8 (GET REF-OFFSET) 25 | #11=#10/1000 (GET REF-OFFSET WITH DECIMAL POINT) 26 | #12=-#8/1000 (GET B264 WITH DECIMAL POINT) 27 | #516=#2+#3+#11+#12 (TOTAL Z-TOOL LENGTH) 28 | #13=[#7-#9]/4 (PARALAX ERROR) 29 | #517=#13/1000 (PARALAX ERROR WITH DECIMAL POINT) 30 | 31 | M99 (END OF MACRO) 32 | 33 | (ALARMS) 34 | N1000 #3000=70 (G127 NO TOOL SPECIFIED) 35 | M30 (END OF PROGRAM) 36 | -------------------------------------------------------------------------------- /Mazak/9128.EIA: -------------------------------------------------------------------------------- 1 | O9128 2 | (G128- CALCUlATE TOOL LENGTH BASED ON B-ANGEL AND PARAMETER #516) 3 | 4 | (FOR INTEGREX 300SY) 5 | (MODIFIED 01/20) 6 | (NORMAL G-CODE TYPE C, P16 BIT3=1, P9 BIT2=1, P9 BIT3=1) 7 | 8 | (IN A BLOCK WITH G127 NO FURTHER G-CODES CAN BE EXECUTED) 9 | (PARAMETER K82 125 9125 OR OTHER SUITED PARAMETER) 10 | (EVERYTHING CAN BE CANCELED WITH G69.5) 11 | 12 | (FORMAT) 13 | (B - POSITION B-AXIS) 14 | 15 | #123=#2 (B-PARAMETER) 16 | #519=#516*SIN[#123] 17 | #520=-#516+#516*COS[#123] 18 | G92 X[#5041-#519+#517] Z[#5042-#520+#518] 19 | #517=#519 20 | #518=#520 21 | #519=#0 22 | #520=#0 23 | M99 (END OF MACRO) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Mazak/9129.EIA: -------------------------------------------------------------------------------- 1 | O9129 (KEYWAY SHAPING ROUTINE) 2 | 3 | (GET THE INPUT PARAMETRS) 4 | #120=#24 (X-PARAMETER, STARTPOINT) 5 | #121=#25 (Y-PARAMETER, STARTPOINT) 6 | #122=#26 (Z-PARAMETER, STARTPOINT) 7 | #123=#21 (U-PARAMETER, DEPTH RELATIVE) 8 | #124=#23 (W-PARAMETER, Z-TRAVEL RELATIVE) 9 | #125=#17 (Q-PARAMETER, CUTTING DEPTH) 10 | #126=#9 (F-PARAMETER, FEED) 11 | #127=#3 (C-PARAMETER, SPINDLE ORIENTATION) 12 | 13 | IF[#120NE#0] GOTO 10 14 | #120=0 (SET X0 IF INPUT EMPTY) 15 | N10 16 | IF[#121NE#0] GOTO 20 17 | #121=0 (SET Y0 IF INPUT EMPTY) 18 | N20 19 | IF[#122NE#0] GOTO 30 20 | #122=0 (SET Z0 IF INPUT EMPTY) 21 | N30 22 | IF[#123NE#0] GOTO 40 23 | #3000=70(DEPTH U NOT SPECIFIED) 24 | N40 25 | IF[#124NE#0] GOTO 50 26 | #3000=70(LENGTH W NOT SPECIFIED) 27 | N50 28 | IF[#125NE#0] GOTO 60 29 | #3000=70(CUTTING DEPTH Q NOT SPECIFIED) 30 | N60 31 | IF[#126NE#0] GOTO 70 32 | #3000=70(FEED F NOT SPECIFIED) 33 | N70 34 | IF[#127NE#0] GOTO 80 35 | #127=0 (SET C0 IF INPUT EMPTY) 36 | N80 37 | 38 | 39 | #130=ROUND[#123/#125] (NUMBER OF CUTS) 40 | #128=#123/#130 (CALCULATE DEPTH OF INDIVIDUAL CUT TO MEET FINAL DEPTH) 41 | #131=0 (ITERATOR) 42 | 43 | N100 44 | M200 (MILLING MODE MAIN SPINDLE) 45 | M212 (UNCLAMP MAIN SPINDLE) 46 | G0 C#127 47 | M210 (CLAMP MAIN SPINDLE) 48 | N110 49 | G0 X#120 Y#121 50 | Z#122 51 | 52 | N120 53 | G91 54 | G122.1 (RADIUS MODE) 55 | 56 | #129=0 57 | WHILE[#131LT#130] DO1 58 | #129=#129+#128 59 | G0 X#129 60 | G1 Z-#124 F#126 61 | G0 X-#129 62 | Z#124 63 | #131=#131+1 64 | END1 65 | 66 | G123.1 (DIAMETER MODE) 67 | G90 68 | 69 | M99 (END OF MACRO) 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /Mazak/CircMill_O1001.EIA: -------------------------------------------------------------------------------- 1 | O1001 2 | 3 | G122.1 4 | 5 | #101=27.3 (Radius) 6 | #102=10. (MillDia) 7 | #103=-5. (Z-Position) 8 | #104=[#101-#102]/2 9 | 10 | T2500.0000 11 | 12 | M200 13 | M203 S3000 14 | 15 | G0 C0. 16 | G17 17 | G0 Z50. 18 | G0 X0. Y#104 Z50. 19 | G0 Z2. 20 | M8 21 | G3 X#104 Y0. Z#103. J[-#104] P3 F200 22 | G3 X0. Y#104 I[-#104] P2 23 | G3 X#104 Y0. Z2. J[-#104] P3 24 | 25 | M205 26 | M9 27 | 28 | G53 Y0. 29 | G53 Z0. 30 | G53 X0. 31 | 32 | M30 33 | % 34 | -------------------------------------------------------------------------------- /Mazak/CircMill_O1002.EIA: -------------------------------------------------------------------------------- 1 | O1002 2 | 3 | G122.1 4 | 5 | #101=19.2 (Radius) 6 | #102=10. (MillDia) 7 | #103=5. (Z-Position) 8 | #104=[#101-#102]/2 9 | 10 | T2502.1100 11 | 12 | M300 13 | G112 M200 14 | G112 M203 G112 S3000 15 | 16 | G110 C2 17 | G0 C0. 18 | G17 19 | G0 X0. Y#104 Z-50. 20 | G0 Z-2. 21 | M8 22 | G2 X#104 Y0. Z#103. J[-#104] P3 F200 23 | G2 X0. Y#104 I[-#104] P2 24 | G2 X#104 Y0. Z-2. J[-#104] P3 25 | 26 | M205 27 | M9 28 | 29 | G53 Y0. 30 | G53 Z0. 31 | G53 X0. 32 | 33 | M30 34 | % 35 | -------------------------------------------------------------------------------- /Mazak/DiaTurn_O1001.EIA: -------------------------------------------------------------------------------- 1 | O1001 2 | 3 | M302 4 | T1701.1302 5 | 6 | G95 7 | G97 S1500 M4 8 | 9 | #101=47.8 (Diameter) 10 | #102=-15. (depth) 11 | 12 | G0 X#101 Z2. 13 | M8 14 | G1 Z#102 F0.04 15 | G1 Z2. 16 | M5 17 | M9 18 | 19 | M30 20 | % -------------------------------------------------------------------------------- /Mazak/DiaTurn_O1002.EIA: -------------------------------------------------------------------------------- 1 | O1002 2 | 3 | M300 4 | T1702.1102 5 | 6 | G95 7 | G97 G112 S1500 M3 8 | 9 | #101=49.2 (Diameter) 10 | #102=15. (depth) 11 | 12 | G0 X#101 Z-2. 13 | M8 14 | G1 Z#102 F0.04 15 | G1 Z-2. 16 | G112 M5 17 | M9 18 | 19 | M30 20 | % -------------------------------------------------------------------------------- /Mazak/FaceTurn_O1001.EIA: -------------------------------------------------------------------------------- 1 | O1001 2 | 3 | M302 4 | T1701.1302 5 | 6 | G95 7 | G97 S1500 M4 8 | 9 | #101=60 (Diameter) 10 | #102=0. (depth) 11 | 12 | G0 X#101 Z2. 13 | M8 14 | G1 Z#102 F0.04 15 | G1 X0. 16 | G1 X#101 17 | G1 Z2. 18 | M5 19 | M9 20 | 21 | M30 22 | % -------------------------------------------------------------------------------- /Mazak/FaceTurn_O1002.EIA: -------------------------------------------------------------------------------- 1 | O1002 2 | 3 | M300 4 | T1701.1102 5 | 6 | G95 7 | G97 G112 S1500 M3 8 | 9 | #101=60 (Diameter) 10 | #102=0. (depth) 11 | 12 | G0 X#101 Z-2. 13 | M8 14 | G1 Z#102 F0.04 15 | G1 X0. 16 | G1 X#101 17 | G1 Z-2. 18 | G112 M5 19 | M9 20 | 21 | M30 22 | % -------------------------------------------------------------------------------- /Mazak/HMill_O1001.EIA: -------------------------------------------------------------------------------- 1 | O1001 2 | 3 | (Milling flats HD1) 4 | 5 | G122.1 6 | 7 | #101=23.4 (X-Height) 8 | #102=37. (Y-Width) 9 | #103=-15. (Z-Position) 10 | #104=16 (Mill diameter) 11 | 12 | T6400.0002 13 | G127 14 | 15 | M200 16 | M203 S3000 17 | 18 | G0 Z50. 19 | G0 X[-#102] Y[#101+#104/2] 20 | G0 Z#103 21 | M8 22 | G1 X[#101+#104/2] F200 23 | G1 Y[-#102] 24 | M9 25 | 26 | M205 27 | 28 | G53 Z0. 29 | G53 Y0. 30 | G53 X0. 31 | 32 | M30 33 | % 34 | -------------------------------------------------------------------------------- /Mazak/HMill_O1002.EIA: -------------------------------------------------------------------------------- 1 | O1002 2 | 3 | (Milling flats HD2) 4 | 5 | G122.1 6 | 7 | #101=25. (X-Height) 8 | #102=37. (Y-Width) 9 | #103=15. (Z-Position) 10 | #104=16 (Mill diameter) 11 | 12 | T6400.1102 13 | 14 | M300 15 | G112 M200 16 | G112 M203 G112 S3000 17 | 18 | G0 Z-50. 19 | G0 X[-#102] Y[-#101-#104/2] 20 | G0 Z#103 21 | M8 22 | G1 X[#101+#104/2] 23 | G1 Y[#102] F200 24 | M9 25 | 26 | G112 M205 27 | 28 | G53 Z0. 29 | G53 Y0. 30 | G53 X0. 31 | 32 | M30 33 | % 34 | -------------------------------------------------------------------------------- /Mazak/Integrex 300SY Adjustment.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mwinterm/fusion_post/bae0f13f943f4df1ae6ff116707d32f5ef036bc9/Mazak/Integrex 300SY Adjustment.xlsx -------------------------------------------------------------------------------- /Mazak/VMill_O1001.EIA: -------------------------------------------------------------------------------- 1 | O1001 2 | 3 | (Milling flat HD1) 4 | 5 | G122.1 6 | 7 | #101=24. (Center Distance) 8 | #102=50. (Y-Width) 9 | #103=-12. (Z-Position) 10 | #104=16 (Mill diameter) 11 | 12 | T6400.0102 13 | 14 | M302 15 | M200 16 | M203 S3000 17 | 18 | G0 X#101 19 | G0 Y[-#102/2] 20 | G0 Z[#103+#104/2] 21 | M8 22 | G1 Y[#102/2] F200 23 | M9 24 | G0 Z50. 25 | G0 Y-50. X-10. 26 | G0 Z#103 27 | M8 28 | G1 Y[-#104/2-#101] F200 29 | G1 Z10. 30 | M9 31 | 32 | M205 33 | 34 | G53 X0. 35 | G53 Y0. 36 | G53 Z0. 37 | 38 | M30 39 | % 40 | -------------------------------------------------------------------------------- /Mazak/VMill_O1002.EIA: -------------------------------------------------------------------------------- 1 | O1002 2 | 3 | (Milling flat HD2) 4 | 5 | G122.1 6 | 7 | #101=24. (Center Distance) 8 | #102=50. (Y-Width) 9 | #103=10. (Z-Position) 10 | #104=16 (Mill diameter) 11 | 12 | T6400.0102 13 | 14 | M300 15 | G112 M200 16 | G112 M203 G112 S3000 17 | 18 | G0 X#101 19 | G0 Y[#102/2] 20 | G0 Z[#103-#104/2] 21 | M8 22 | G1 Y[-#102/2] F200 23 | M9 24 | G0 Z-10. 25 | G0 Y[-#104/2-#101] 26 | G0 X-10. 27 | M8 28 | G1 Z#103 F200 29 | G1 Y-50. 30 | G0 Z-10. 31 | M9 32 | 33 | G112 M205 34 | 35 | G53 X0. 36 | G53 Y0. 37 | G53 Z0. 38 | 39 | M30 40 | % 41 | -------------------------------------------------------------------------------- /Mazak/code.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | FORKID {D38E0AF6-F1A7-4C6D-A0FA-C99BB29E65AE} 6 | */ 7 | 8 | description = "Export CNC file to Visual Studio Code"; 9 | vendor = "Autodesk"; 10 | vendorUrl = "http://www.autodesk.com"; 11 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 12 | certificationLevel = 2; 13 | minimumRevision = 41666; 14 | 15 | longDescription = "The post installs the CNC file for use with the Autodesk HSM Post Processor extension for Visual Studio Code."; 16 | 17 | capabilities = CAPABILITY_INTERMEDIATE; 18 | 19 | function onSection() { 20 | skipRemainingSection(); 21 | } 22 | 23 | function onClose() { 24 | var cncPath = getIntermediatePath(); 25 | var fileName = FileSystem.getFilename(cncPath); 26 | var destPath = FileSystem.getFolderPath(getOutputPath()); 27 | 28 | if (getPlatform() == "WIN32") { 29 | if (!FileSystem.isFolder(FileSystem.getTemporaryFolder())) { 30 | FileSystem.makeFolder(FileSystem.getTemporaryFolder()); 31 | } 32 | var path = FileSystem.getTemporaryFile("post"); 33 | 34 | var registryPaths = [ 35 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1", 36 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1", 37 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1", 38 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1", 39 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1", 40 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{D628A17A-9713-46BF-8D57-E671B46A741E}_is1" 41 | ]; 42 | 43 | var exePath; 44 | for (var i = 0; i < registryPaths.length; ++i) { 45 | if (hasRegistryValue(registryPaths[i], "InstallLocation")) { 46 | exePath = getRegistryString(registryPaths[i], "InstallLocation"); 47 | if (FileSystem.isFile(exePath + "\\code.exe")) { 48 | break; // found 49 | } 50 | } 51 | } 52 | 53 | if (exePath) { 54 | exePath = FileSystem.getCombinedPath(exePath, "\\bin\\code.cmd"); 55 | } else { 56 | error(localize("Visual Studio Code not found.")); 57 | return; 58 | } 59 | 60 | var a = "code --list-extensions --show-versions"; 61 | execute(exePath, a + ">" + path, false, ""); 62 | 63 | var result = {}; 64 | try { 65 | var file = new TextFile(path, false, "utf-8"); 66 | while (true) { 67 | var line = file.readln(); 68 | var index = line.indexOf("@"); 69 | if (index >= 0) { 70 | var name = line.substr(0, index); 71 | var value = line.substr(index + 1); 72 | result[name] = value; 73 | } 74 | } 75 | } catch (e) { 76 | // fail 77 | } 78 | file.close(); 79 | 80 | FileSystem.remove(path); 81 | 82 | var gotValues = false; 83 | for (var name in result) { 84 | gotValues = true; 85 | break; 86 | } 87 | 88 | var foundExtension = false; 89 | var extension; 90 | for (var name in result) { 91 | var value = result[name]; 92 | switch (name) { 93 | case "Autodesk.hsm-post-processor": 94 | extension = name + "-" + value; 95 | foundExtension = true; 96 | break; 97 | } 98 | } 99 | if (!foundExtension) { 100 | error(localize("Autodesk HSM Post Processor extension not found.")); 101 | return; 102 | } 103 | 104 | var userProfile = getEnvironmentVariable("USERPROFILE"); 105 | var extensionFolder = FileSystem.getCombinedPath(userProfile, "\\.vscode\\extensions\\" + extension); 106 | 107 | if (FileSystem.isFile(cncPath)) { 108 | if (!FileSystem.isFolder(extensionFolder)) { 109 | error(localize("Autodesk HSM Post Processor extension not found.")); 110 | return; 111 | } 112 | var customFolder = FileSystem.getCombinedPath(extensionFolder, "\\res\\CNC files\\Custom"); 113 | if (!FileSystem.isFolder(customFolder)) { 114 | FileSystem.makeFolder(customFolder); 115 | } 116 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(customFolder, fileName)); 117 | } 118 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + customFolder + "\"" + " and you can select it in VS Code."); 119 | } else { // non windows 120 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(destPath, fileName)); 121 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + destPath + "\"" + "."); 122 | writeln("You need to manually import the CNC file in VS Code by a right click into the CNC Selector panel and select 'Import CNC file...'."); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Mazak/dump.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2016 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | Dump configuration. 6 | 7 | $Revision: 41602 8a235290846bfe71ead6a010711f4fc730f48827 $ 8 | $Date: 2017-09-14 12:16:32 $ 9 | 10 | FORKID {4E9DFE89-DA1C-4531-98C9-7FECF672BD47} 11 | */ 12 | 13 | description = "Dumper"; 14 | vendor = "Autodesk"; 15 | vendorUrl = "http://www.autodesk.com"; 16 | legal = "Copyright (C) 2012-2016 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | 19 | longDescription = "Use this post to understand which information is available when developing a new post. The post will output the primary information for each entry function being called."; 20 | 21 | extension = "dmp"; 22 | // using user code page 23 | 24 | capabilities = CAPABILITY_INTERMEDIATE; 25 | 26 | allowMachineChangeOnSection = true; 27 | allowHelicalMoves = true; 28 | allowSpiralMoves = true; 29 | allowedCircularPlanes = undefined; // allow any circular motion 30 | maximumCircularSweep = toRad(1000000); 31 | minimumCircularRadius = spatial(0.001, MM); 32 | maximumCircularRadius = spatial(1000000, MM); 33 | mapWorkOrigin = false; 34 | 35 | // user-defined properties 36 | properties = { 37 | showState: true, // show the commonly interesting current state 38 | expandCycles: true // enable to expand cycles when supported 39 | }; 40 | 41 | // user-defined property definitions 42 | propertyDefinitions = { 43 | showState: {title:"Show state", description:"Shows the commonly interesting current state.", type:"boolean"}, 44 | expandCycles: {title:"Expand cycles", description:"If enabled, unhandled cycles are expanded.", type:"boolean"} 45 | }; 46 | 47 | 48 | var spatialFormat = createFormat({decimals:6}); 49 | var angularFormat = createFormat({decimals:6, scale:DEG}); 50 | var rpmFormat = createFormat({decimals:6}); 51 | var otherFormat = createFormat({decimals:6}); 52 | 53 | var expanding = false; 54 | 55 | function toString(value) { 56 | if (typeof value == "string") { 57 | return "'" + value + "'"; 58 | } else { 59 | return value; 60 | } 61 | } 62 | 63 | function dumpImpl(name, text) { 64 | writeln(getCurrentRecordId() + ": " + name + "(" + text + ")"); 65 | } 66 | 67 | function dump(name, _arguments) { 68 | var result = getCurrentRecordId() + ": " + (expanding ? "EXPANDED " : "") + name + "("; 69 | for (var i = 0; i < _arguments.length; ++i) { 70 | if (i > 0) { 71 | result += ", "; 72 | } 73 | if (typeof _arguments[i] == "string") { 74 | result += "'" + _arguments[i] + "'"; 75 | } else { 76 | result += _arguments[i]; 77 | } 78 | } 79 | result += ")"; 80 | writeln(result); 81 | } 82 | 83 | function onMachine() { 84 | dump("onMachine", arguments); 85 | if (machineConfiguration.getVendor()) { 86 | writeln(" " + "Vendor" + ": " + machineConfiguration.getVendor()); 87 | } 88 | if (machineConfiguration.getModel()) { 89 | writeln(" " + "Model" + ": " + machineConfiguration.getModel()); 90 | } 91 | if (machineConfiguration.getDescription()) { 92 | writeln(" " + "Description" + ": " + machineConfiguration.getDescription()); 93 | } 94 | } 95 | 96 | function onOpen() { 97 | dump("onOpen", arguments); 98 | } 99 | 100 | function onPassThrough() { 101 | dump("onPassThrough", arguments); 102 | } 103 | 104 | function onComment() { 105 | dump("onComment", arguments); 106 | } 107 | 108 | /** Write the current state. */ 109 | function dumpState() { 110 | if (!properties.showState) { 111 | return; 112 | } 113 | 114 | writeln(" STATE position=[" + spatialFormat.format(getCurrentPosition().x) + ", " + spatialFormat.format(getCurrentPosition().y) + ", " + spatialFormat.format(getCurrentPosition().z) + "]"); 115 | if ((currentSection.getType() == TYPE_MILLING) || (currentSection.getType() == TYPE_TURNING)) { 116 | writeln(" STATE spindleSpeed=" + rpmFormat.format(spindleSpeed)); 117 | } 118 | if (currentSection.getType() == TYPE_JET) { 119 | writeln(" STATE power=" + (power ? "ON" : "OFF")); 120 | } 121 | // writeln(" STATE movement=" + movement); 122 | // writeln(" STATE feedrate=" + spatialFormat.format(feedrate)); 123 | // writeln(" STATE compensationOffset=" + compensationOffset); 124 | 125 | var id; 126 | switch (radiusCompensation) { 127 | case RADIUS_COMPENSATION_OFF: 128 | id = "RADIUS_COMPENSATION_OFF"; 129 | break; 130 | case RADIUS_COMPENSATION_LEFT: 131 | id = "RADIUS_COMPENSATION_LEFT"; 132 | break; 133 | case RADIUS_COMPENSATION_RIGHT: 134 | id = "RADIUS_COMPENSATION_RIGHT"; 135 | break; 136 | } 137 | if (id != undefined) { 138 | writeln(" STATE radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 139 | } else { 140 | writeln(" STATE radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 141 | } 142 | } 143 | 144 | function onSection() { 145 | dump("onSection", arguments); 146 | 147 | var name; 148 | for (name in currentSection) { 149 | value = currentSection[name]; 150 | if (typeof value != "function") { 151 | writeln(" currentSection." + name + "=" + toString(value)); 152 | } 153 | } 154 | 155 | for (name in tool) { 156 | value = tool[name]; 157 | if (typeof value != "function") { 158 | writeln(" tool." + name + "=" + toString(value)); 159 | } 160 | } 161 | 162 | { 163 | var shaft = tool.shaft; 164 | if (shaft && shaft.hasSections()) { 165 | var n = shaft.getNumberOfSections(); 166 | for (var i = 0; i < n; ++i) { 167 | writeln(" tool.shaft[" + i + "] H=" + shaft.getLength(i) + " D=" + shaft.getDiameter(i)); 168 | } 169 | } 170 | } 171 | 172 | { 173 | var holder = tool.holder; 174 | if (holder && holder.hasSections()) { 175 | var n = holder.getNumberOfSections(); 176 | for (var i = 0; i < n; ++i) { 177 | writeln(" tool.holder[" + i + "] H=" + holder.getLength(i) + " D=" + holder.getDiameter(i)); 178 | } 179 | } 180 | } 181 | 182 | if (currentSection.isPatterned && currentSection.isPatterned()) { 183 | var patternId = currentSection.getPatternId(); 184 | var sections = []; 185 | var first = true; 186 | for (var i = 0; i < getNumberOfSections(); ++i) { 187 | var section = getSection(i); 188 | if (section.getPatternId() == patternId) { 189 | if (i < getCurrentSectionId()) { 190 | first = false; // not the first pattern instance 191 | } 192 | if (i != getCurrentSectionId()) { 193 | sections.push(section.getId()); 194 | } 195 | } 196 | } 197 | writeln(" >>> Pattern instances: " + sections); 198 | if (!first) { 199 | // writeln(" SKIPPING PATTERN INSTANCE"); 200 | // skipRemainingSection(); 201 | } 202 | } 203 | 204 | dumpState(); 205 | } 206 | 207 | function onSectionSpecialCycle() { 208 | dump("onSectionSpecialCycle", arguments); 209 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 210 | } 211 | 212 | function onPower() { 213 | dump("onPower", arguments); 214 | } 215 | 216 | function onSpindleSpeed() { 217 | dump("onSpindleSpeed", arguments); 218 | } 219 | 220 | function onParameter() { 221 | dump("onParameter", arguments); 222 | } 223 | 224 | function onDwell() { 225 | dump("onDwell", arguments); 226 | } 227 | 228 | function onCycle() { 229 | dump("onCycle", arguments); 230 | 231 | writeln(" cycleType=" + toString(cycleType)); 232 | for (var name in cycle) { 233 | value = cycle[name]; 234 | if (typeof value != "function") { 235 | writeln(" cycle." + name + "=" + toString(value)); 236 | } 237 | } 238 | } 239 | 240 | function onCyclePoint(x, y, z) { 241 | dump("onCyclePoint", arguments); 242 | 243 | if (properties.expandCycles) { 244 | 245 | switch (cycleType) { 246 | case "drilling": // G81 style 247 | case "counter-boring": // G82 style 248 | case "chip-breaking": // G73 style 249 | case "deep-drilling": // G83 style 250 | case "break-through-drilling": 251 | case "gun-drilling": 252 | case "tapping": 253 | case "left-tapping": // G74 style 254 | case "right-tapping": // G84 style 255 | case "tapping-with-chip-breaking": 256 | case "left-tapping-with-chip-breaking": 257 | case "right-tapping-with-chip-breaking": 258 | case "reaming": // G85 style 259 | case "boring": // G89 style 260 | case "stop-boring": // G86 style 261 | case "fine-boring": // G76 style 262 | case "back-boring": // G87 style 263 | case "manual-boring": 264 | case "bore-milling": 265 | case "thread-milling": 266 | case "circular-pocket-milling": 267 | expanding = true; 268 | expandCyclePoint(x, y, z); 269 | expanding = false; 270 | break; 271 | default: 272 | writeln(" CYCLE CANNOT BE EXPANDED"); 273 | } 274 | } 275 | 276 | dumpState(); 277 | } 278 | 279 | function onCycleEnd() { 280 | dump("onCycleEnd", arguments); 281 | } 282 | 283 | /** 284 | Returns the string id for the specified movement. Returns the movement id as 285 | a string if unknown. 286 | */ 287 | function getMovementStringId(movement, jet) { 288 | switch (movement) { 289 | case MOVEMENT_RAPID: 290 | return "rapid"; 291 | case MOVEMENT_LEAD_IN: 292 | return "lead in"; 293 | case MOVEMENT_CUTTING: 294 | return "cutting"; 295 | case MOVEMENT_LEAD_OUT: 296 | return "lead out"; 297 | case MOVEMENT_LINK_TRANSITION: 298 | return !jet ? "transition" : "bridging"; 299 | case MOVEMENT_LINK_DIRECT: 300 | return "direct"; 301 | case MOVEMENT_RAMP_HELIX: 302 | return !jet ? "helix ramp" : "circular pierce"; 303 | case MOVEMENT_RAMP_PROFILE: 304 | return !jet ? "profile ramp" : "profile pierce"; 305 | case MOVEMENT_RAMP_ZIG_ZAG: 306 | return !jet ? "zigzag ramp" : "linear pierce"; 307 | case MOVEMENT_RAMP: 308 | return !jet ? "ramp" : "pierce"; 309 | case MOVEMENT_PLUNGE: 310 | return !jet ? "plunge" : "pierce"; 311 | case MOVEMENT_PREDRILL: 312 | return "predrill"; 313 | case MOVEMENT_EXTENDED: 314 | return "extended"; 315 | case MOVEMENT_REDUCED: 316 | return "reduced"; 317 | case MOVEMENT_FINISH_CUTTING: 318 | return "finish cut"; 319 | case MOVEMENT_HIGH_FEED: 320 | return "high feed"; 321 | default: 322 | return String(movement); 323 | } 324 | } 325 | 326 | function onMovement(movement) { 327 | var jet = tool.isJetTool && tool.isJetTool(); 328 | var id; 329 | switch (movement) { 330 | case MOVEMENT_RAPID: 331 | id = "MOVEMENT_RAPID"; 332 | break; 333 | case MOVEMENT_LEAD_IN: 334 | id = "MOVEMENT_LEAD_IN"; 335 | break; 336 | case MOVEMENT_CUTTING: 337 | id = "MOVEMENT_CUTTING"; 338 | break; 339 | case MOVEMENT_LEAD_OUT: 340 | id = "MOVEMENT_LEAD_OUT"; 341 | break; 342 | case MOVEMENT_LINK_TRANSITION: 343 | id = jet ? "MOVEMENT_BRIDGING" : "MOVEMENT_LINK_TRANSITION"; 344 | break; 345 | case MOVEMENT_LINK_DIRECT: 346 | id = "MOVEMENT_LINK_DIRECT"; 347 | break; 348 | case MOVEMENT_RAMP_HELIX: 349 | id = jet ? "MOVEMENT_PIERCE_CIRCULAR" : "MOVEMENT_RAMP_HELIX"; 350 | break; 351 | case MOVEMENT_RAMP_PROFILE: 352 | id = jet ? "MOVEMENT_PIERCE_PROFILE" : "MOVEMENT_RAMP_PROFILE"; 353 | break; 354 | case MOVEMENT_RAMP_ZIG_ZAG: 355 | id = jet ? "MOVEMENT_PIERCE_LINEAR" : "MOVEMENT_RAMP_ZIG_ZAG"; 356 | break; 357 | case MOVEMENT_RAMP: 358 | id = "MOVEMENT_RAMP"; 359 | break; 360 | case MOVEMENT_PLUNGE: 361 | id = jet ? "MOVEMENT_PIERCE" : "MOVEMENT_PLUNGE"; 362 | break; 363 | case MOVEMENT_PREDRILL: 364 | id = "MOVEMENT_PREDRILL"; 365 | break; 366 | case MOVEMENT_EXTENDED: 367 | id = "MOVEMENT_EXTENDED"; 368 | break; 369 | case MOVEMENT_REDUCED: 370 | id = "MOVEMENT_REDUCED"; 371 | break; 372 | case MOVEMENT_HIGH_FEED: 373 | id = "MOVEMENT_HIGH_FEED"; 374 | break; 375 | } 376 | if (id != undefined) { 377 | dumpImpl("onMovement", id + " /*" + getMovementStringId(movement, jet) + "*/"); 378 | } else { 379 | dumpImpl("onMovement", movement + " /*" + getMovementStringId(movement, jet) + "*/"); 380 | } 381 | } 382 | 383 | var RADIUS_COMPENSATION_MAP = {0:"off", 1:"left", 2:"right"}; 384 | 385 | function onRadiusCompensation() { 386 | var id; 387 | switch (radiusCompensation) { 388 | case RADIUS_COMPENSATION_OFF: 389 | id = "RADIUS_COMPENSATION_OFF"; 390 | break; 391 | case RADIUS_COMPENSATION_LEFT: 392 | id = "RADIUS_COMPENSATION_LEFT"; 393 | break; 394 | case RADIUS_COMPENSATION_RIGHT: 395 | id = "RADIUS_COMPENSATION_RIGHT"; 396 | break; 397 | } 398 | dump("onRadiusCompensation", arguments); 399 | if (id != undefined) { 400 | writeln(" radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 401 | } else { 402 | writeln(" radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 403 | } 404 | } 405 | 406 | function onRapid() { 407 | dump("onRapid", arguments); 408 | } 409 | 410 | function onLinear() { 411 | dump("onLinear", arguments); 412 | } 413 | 414 | function onRapid5D() { 415 | dump("onRapid5D", arguments); 416 | } 417 | 418 | function onLinear5D() { 419 | dump("onLinear5D", arguments); 420 | } 421 | 422 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 423 | dump("onCircular", arguments); 424 | writeln(" direction: " + (clockwise ? "CW" : "CCW")); 425 | writeln(" sweep: " + angularFormat.format(getCircularSweep()) + "deg"); 426 | var n = getCircularNormal(); 427 | var plane = ""; 428 | switch (getCircularPlane()) { 429 | case PLANE_XY: 430 | plane = "(XY)"; 431 | break; 432 | case PLANE_ZX: 433 | plane = "(ZX)"; 434 | break; 435 | case PLANE_YZ: 436 | plane = "(YZ)"; 437 | break; 438 | } 439 | writeln(" normal: X=" + spatialFormat.format(n.x) + " Y=" + spatialFormat.format(n.y) + " Z=" + spatialFormat.format(n.z) + " " + plane); 440 | if (isSpiral()) { 441 | writeln(" spiral"); 442 | writeln(" start radius: " + spatialFormat.format(getCircularStartRadius())); 443 | writeln(" end radius: " + spatialFormat.format(getCircularRadius())); 444 | writeln(" delta radius: " + spatialFormat.format(getCircularRadius() - getCircularStartRadius())); 445 | } else { 446 | writeln(" radius: " + spatialFormat.format(getCircularRadius())); 447 | } 448 | if (isHelical()) { 449 | writeln(" helical pitch: " + spatialFormat.format(getHelicalPitch())); 450 | } 451 | } 452 | 453 | function onCommand(command) { 454 | if (isWellKnownCommand(command)) { 455 | dumpImpl("onCommand", getCommandStringId(command)); 456 | } else { 457 | dumpImpl("onCommand", command); 458 | } 459 | } 460 | 461 | function onSectionEnd() { 462 | dump("onSectionEnd", arguments); 463 | 464 | dumpState(); 465 | } 466 | 467 | function onSectionEndSpecialCycle() { 468 | dump("onSectionEndSpecialCycle", arguments); 469 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 470 | } 471 | 472 | function onClose() { 473 | dump("onClose", arguments); 474 | } 475 | -------------------------------------------------------------------------------- /MikronVCP1000_TNC426/code.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | FORKID {D38E0AF6-F1A7-4C6D-A0FA-C99BB29E65AE} 6 | */ 7 | 8 | description = "Export CNC file to Visual Studio Code"; 9 | vendor = "Autodesk"; 10 | vendorUrl = "http://www.autodesk.com"; 11 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 12 | certificationLevel = 2; 13 | minimumRevision = 41666; 14 | 15 | longDescription = "The post installs the CNC file for use with the Autodesk HSM Post Processor extension for Visual Studio Code."; 16 | 17 | capabilities = CAPABILITY_INTERMEDIATE; 18 | 19 | function onSection() { 20 | skipRemainingSection(); 21 | } 22 | 23 | function onClose() { 24 | var cncPath = getIntermediatePath(); 25 | var fileName = FileSystem.getFilename(cncPath); 26 | var destPath = FileSystem.getFolderPath(getOutputPath()); 27 | 28 | if (getPlatform() == "WIN32") { 29 | if (!FileSystem.isFolder(FileSystem.getTemporaryFolder())) { 30 | FileSystem.makeFolder(FileSystem.getTemporaryFolder()); 31 | } 32 | var path = FileSystem.getTemporaryFile("post"); 33 | 34 | var registryPaths = [ 35 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1", 36 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1", 37 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1", 38 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1", 39 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1", 40 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{D628A17A-9713-46BF-8D57-E671B46A741E}_is1" 41 | ]; 42 | 43 | var exePath; 44 | for (var i = 0; i < registryPaths.length; ++i) { 45 | if (hasRegistryValue(registryPaths[i], "InstallLocation")) { 46 | exePath = getRegistryString(registryPaths[i], "InstallLocation"); 47 | if (FileSystem.isFile(exePath + "\\code.exe")) { 48 | break; // found 49 | } 50 | } 51 | } 52 | 53 | if (exePath) { 54 | exePath = FileSystem.getCombinedPath(exePath, "\\bin\\code.cmd"); 55 | } else { 56 | error(localize("Visual Studio Code not found.")); 57 | return; 58 | } 59 | 60 | var a = "code --list-extensions --show-versions"; 61 | execute(exePath, a + ">" + path, false, ""); 62 | 63 | var result = {}; 64 | try { 65 | var file = new TextFile(path, false, "utf-8"); 66 | while (true) { 67 | var line = file.readln(); 68 | var index = line.indexOf("@"); 69 | if (index >= 0) { 70 | var name = line.substr(0, index); 71 | var value = line.substr(index + 1); 72 | result[name] = value; 73 | } 74 | } 75 | } catch (e) { 76 | // fail 77 | } 78 | file.close(); 79 | 80 | FileSystem.remove(path); 81 | 82 | var gotValues = false; 83 | for (var name in result) { 84 | gotValues = true; 85 | break; 86 | } 87 | 88 | var foundExtension = false; 89 | var extension; 90 | for (var name in result) { 91 | var value = result[name]; 92 | switch (name) { 93 | case "Autodesk.hsm-post-processor": 94 | extension = name + "-" + value; 95 | foundExtension = true; 96 | break; 97 | } 98 | } 99 | if (!foundExtension) { 100 | error(localize("Autodesk HSM Post Processor extension not found.")); 101 | return; 102 | } 103 | 104 | var userProfile = getEnvironmentVariable("USERPROFILE"); 105 | var extensionFolder = FileSystem.getCombinedPath(userProfile, "\\.vscode\\extensions\\" + extension); 106 | 107 | if (FileSystem.isFile(cncPath)) { 108 | if (!FileSystem.isFolder(extensionFolder)) { 109 | error(localize("Autodesk HSM Post Processor extension not found.")); 110 | return; 111 | } 112 | var customFolder = FileSystem.getCombinedPath(extensionFolder, "\\res\\CNC files\\Custom"); 113 | if (!FileSystem.isFolder(customFolder)) { 114 | FileSystem.makeFolder(customFolder); 115 | } 116 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(customFolder, fileName)); 117 | } 118 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + customFolder + "\"" + " and you can select it in VS Code."); 119 | } else { // non windows 120 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(destPath, fileName)); 121 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + destPath + "\"" + "."); 122 | writeln("You need to manually import the CNC file in VS Code by a right click into the CNC Selector panel and select 'Import CNC file...'."); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /MikronVCP1000_TNC426/dump.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2016 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | Dump configuration. 6 | 7 | $Revision: 41602 8a235290846bfe71ead6a010711f4fc730f48827 $ 8 | $Date: 2017-09-14 12:16:32 $ 9 | 10 | FORKID {4E9DFE89-DA1C-4531-98C9-7FECF672BD47} 11 | */ 12 | 13 | description = "Dumper"; 14 | vendor = "Autodesk"; 15 | vendorUrl = "http://www.autodesk.com"; 16 | legal = "Copyright (C) 2012-2016 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | 19 | longDescription = "Use this post to understand which information is available when developing a new post. The post will output the primary information for each entry function being called."; 20 | 21 | extension = "dmp"; 22 | // using user code page 23 | 24 | capabilities = CAPABILITY_INTERMEDIATE; 25 | 26 | allowMachineChangeOnSection = true; 27 | allowHelicalMoves = true; 28 | allowSpiralMoves = true; 29 | allowedCircularPlanes = undefined; // allow any circular motion 30 | maximumCircularSweep = toRad(1000000); 31 | minimumCircularRadius = spatial(0.001, MM); 32 | maximumCircularRadius = spatial(1000000, MM); 33 | 34 | // user-defined properties 35 | properties = { 36 | showState: true, // show the commonly interesting current state 37 | expandCycles: true // enable to expand cycles when supported 38 | }; 39 | 40 | // user-defined property definitions 41 | propertyDefinitions = { 42 | showState: {title:"Show state", description:"Shows the commonly interesting current state.", type:"boolean"}, 43 | expandCycles: {title:"Expand cycles", description:"If enabled, unhandled cycles are expanded.", type:"boolean"} 44 | }; 45 | 46 | 47 | var spatialFormat = createFormat({decimals:6}); 48 | var angularFormat = createFormat({decimals:6, scale:DEG}); 49 | var rpmFormat = createFormat({decimals:6}); 50 | var otherFormat = createFormat({decimals:6}); 51 | 52 | var expanding = false; 53 | 54 | function toString(value) { 55 | if (typeof value == "string") { 56 | return "'" + value + "'"; 57 | } else { 58 | return value; 59 | } 60 | } 61 | 62 | function dumpImpl(name, text) { 63 | writeln(getCurrentRecordId() + ": " + name + "(" + text + ")"); 64 | } 65 | 66 | function dump(name, _arguments) { 67 | var result = getCurrentRecordId() + ": " + (expanding ? "EXPANDED " : "") + name + "("; 68 | for (var i = 0; i < _arguments.length; ++i) { 69 | if (i > 0) { 70 | result += ", "; 71 | } 72 | if (typeof _arguments[i] == "string") { 73 | result += "'" + _arguments[i] + "'"; 74 | } else { 75 | result += _arguments[i]; 76 | } 77 | } 78 | result += ")"; 79 | writeln(result); 80 | } 81 | 82 | function onMachine() { 83 | dump("onMachine", arguments); 84 | if (machineConfiguration.getVendor()) { 85 | writeln(" " + "Vendor" + ": " + machineConfiguration.getVendor()); 86 | } 87 | if (machineConfiguration.getModel()) { 88 | writeln(" " + "Model" + ": " + machineConfiguration.getModel()); 89 | } 90 | if (machineConfiguration.getDescription()) { 91 | writeln(" " + "Description" + ": " + machineConfiguration.getDescription()); 92 | } 93 | } 94 | 95 | function onOpen() { 96 | dump("onOpen", arguments); 97 | } 98 | 99 | function onPassThrough() { 100 | dump("onPassThrough", arguments); 101 | } 102 | 103 | function onComment() { 104 | dump("onComment", arguments); 105 | } 106 | 107 | /** Write the current state. */ 108 | function dumpState() { 109 | if (!properties.showState) { 110 | return; 111 | } 112 | 113 | writeln(" STATE position=[" + spatialFormat.format(getCurrentPosition().x) + ", " + spatialFormat.format(getCurrentPosition().y) + ", " + spatialFormat.format(getCurrentPosition().z) + "]"); 114 | if ((currentSection.getType() == TYPE_MILLING) || (currentSection.getType() == TYPE_TURNING)) { 115 | writeln(" STATE spindleSpeed=" + rpmFormat.format(spindleSpeed)); 116 | } 117 | if (currentSection.getType() == TYPE_JET) { 118 | writeln(" STATE power=" + (power ? "ON" : "OFF")); 119 | } 120 | // writeln(" STATE movement=" + movement); 121 | // writeln(" STATE feedrate=" + spatialFormat.format(feedrate)); 122 | // writeln(" STATE compensationOffset=" + compensationOffset); 123 | 124 | var id; 125 | switch (radiusCompensation) { 126 | case RADIUS_COMPENSATION_OFF: 127 | id = "RADIUS_COMPENSATION_OFF"; 128 | break; 129 | case RADIUS_COMPENSATION_LEFT: 130 | id = "RADIUS_COMPENSATION_LEFT"; 131 | break; 132 | case RADIUS_COMPENSATION_RIGHT: 133 | id = "RADIUS_COMPENSATION_RIGHT"; 134 | break; 135 | } 136 | if (id != undefined) { 137 | writeln(" STATE radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 138 | } else { 139 | writeln(" STATE radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 140 | } 141 | } 142 | 143 | function onSection() { 144 | dump("onSection", arguments); 145 | 146 | var name; 147 | for (name in currentSection) { 148 | value = currentSection[name]; 149 | if (typeof value != "function") { 150 | writeln(" currentSection." + name + "=" + toString(value)); 151 | } 152 | } 153 | 154 | for (name in tool) { 155 | value = tool[name]; 156 | if (typeof value != "function") { 157 | writeln(" tool." + name + "=" + toString(value)); 158 | } 159 | } 160 | 161 | { 162 | var shaft = tool.shaft; 163 | if (shaft && shaft.hasSections()) { 164 | var n = shaft.getNumberOfSections(); 165 | for (var i = 0; i < n; ++i) { 166 | writeln(" tool.shaft[" + i + "] H=" + shaft.getLength(i) + " D=" + shaft.getDiameter(i)); 167 | } 168 | } 169 | } 170 | 171 | { 172 | var holder = tool.holder; 173 | if (holder && holder.hasSections()) { 174 | var n = holder.getNumberOfSections(); 175 | for (var i = 0; i < n; ++i) { 176 | writeln(" tool.holder[" + i + "] H=" + holder.getLength(i) + " D=" + holder.getDiameter(i)); 177 | } 178 | } 179 | } 180 | 181 | if (currentSection.isPatterned && currentSection.isPatterned()) { 182 | var patternId = currentSection.getPatternId(); 183 | var sections = []; 184 | var first = true; 185 | for (var i = 0; i < getNumberOfSections(); ++i) { 186 | var section = getSection(i); 187 | if (section.getPatternId() == patternId) { 188 | if (i < getCurrentSectionId()) { 189 | first = false; // not the first pattern instance 190 | } 191 | if (i != getCurrentSectionId()) { 192 | sections.push(section.getId()); 193 | } 194 | } 195 | } 196 | writeln(" >>> Pattern instances: " + sections); 197 | if (!first) { 198 | // writeln(" SKIPPING PATTERN INSTANCE"); 199 | // skipRemainingSection(); 200 | } 201 | } 202 | 203 | dumpState(); 204 | } 205 | 206 | function onSectionSpecialCycle() { 207 | dump("onSectionSpecialCycle", arguments); 208 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 209 | } 210 | 211 | function onPower() { 212 | dump("onPower", arguments); 213 | } 214 | 215 | function onSpindleSpeed() { 216 | dump("onSpindleSpeed", arguments); 217 | } 218 | 219 | function onParameter() { 220 | dump("onParameter", arguments); 221 | } 222 | 223 | function onDwell() { 224 | dump("onDwell", arguments); 225 | } 226 | 227 | function onCycle() { 228 | dump("onCycle", arguments); 229 | 230 | writeln(" cycleType=" + toString(cycleType)); 231 | for (var name in cycle) { 232 | value = cycle[name]; 233 | if (typeof value != "function") { 234 | writeln(" cycle." + name + "=" + toString(value)); 235 | } 236 | } 237 | } 238 | 239 | function onCyclePoint(x, y, z) { 240 | dump("onCyclePoint", arguments); 241 | 242 | if (properties.expandCycles) { 243 | 244 | switch (cycleType) { 245 | case "drilling": // G81 style 246 | case "counter-boring": // G82 style 247 | case "chip-breaking": // G73 style 248 | case "deep-drilling": // G83 style 249 | case "break-through-drilling": 250 | case "gun-drilling": 251 | case "tapping": 252 | case "left-tapping": // G74 style 253 | case "right-tapping": // G84 style 254 | case "tapping-with-chip-breaking": 255 | case "left-tapping-with-chip-breaking": 256 | case "right-tapping-with-chip-breaking": 257 | case "reaming": // G85 style 258 | case "boring": // G89 style 259 | case "stop-boring": // G86 style 260 | case "fine-boring": // G76 style 261 | case "back-boring": // G87 style 262 | case "manual-boring": 263 | case "bore-milling": 264 | case "thread-milling": 265 | case "circular-pocket-milling": 266 | expanding = true; 267 | expandCyclePoint(x, y, z); 268 | expanding = false; 269 | break; 270 | default: 271 | writeln(" CYCLE CANNOT BE EXPANDED"); 272 | } 273 | } 274 | 275 | dumpState(); 276 | } 277 | 278 | function onCycleEnd() { 279 | dump("onCycleEnd", arguments); 280 | } 281 | 282 | /** 283 | Returns the string id for the specified movement. Returns the movement id as 284 | a string if unknown. 285 | */ 286 | function getMovementStringId(movement, jet) { 287 | switch (movement) { 288 | case MOVEMENT_RAPID: 289 | return "rapid"; 290 | case MOVEMENT_LEAD_IN: 291 | return "lead in"; 292 | case MOVEMENT_CUTTING: 293 | return "cutting"; 294 | case MOVEMENT_LEAD_OUT: 295 | return "lead out"; 296 | case MOVEMENT_LINK_TRANSITION: 297 | return !jet ? "transition" : "bridging"; 298 | case MOVEMENT_LINK_DIRECT: 299 | return "direct"; 300 | case MOVEMENT_RAMP_HELIX: 301 | return !jet ? "helix ramp" : "circular pierce"; 302 | case MOVEMENT_RAMP_PROFILE: 303 | return !jet ? "profile ramp" : "profile pierce"; 304 | case MOVEMENT_RAMP_ZIG_ZAG: 305 | return !jet ? "zigzag ramp" : "linear pierce"; 306 | case MOVEMENT_RAMP: 307 | return !jet ? "ramp" : "pierce"; 308 | case MOVEMENT_PLUNGE: 309 | return !jet ? "plunge" : "pierce"; 310 | case MOVEMENT_PREDRILL: 311 | return "predrill"; 312 | case MOVEMENT_EXTENDED: 313 | return "extended"; 314 | case MOVEMENT_REDUCED: 315 | return "reduced"; 316 | case MOVEMENT_FINISH_CUTTING: 317 | return "finish cut"; 318 | case MOVEMENT_HIGH_FEED: 319 | return "high feed"; 320 | default: 321 | return String(movement); 322 | } 323 | } 324 | 325 | function onMovement(movement) { 326 | var jet = tool.isJetTool && tool.isJetTool(); 327 | var id; 328 | switch (movement) { 329 | case MOVEMENT_RAPID: 330 | id = "MOVEMENT_RAPID"; 331 | break; 332 | case MOVEMENT_LEAD_IN: 333 | id = "MOVEMENT_LEAD_IN"; 334 | break; 335 | case MOVEMENT_CUTTING: 336 | id = "MOVEMENT_CUTTING"; 337 | break; 338 | case MOVEMENT_LEAD_OUT: 339 | id = "MOVEMENT_LEAD_OUT"; 340 | break; 341 | case MOVEMENT_LINK_TRANSITION: 342 | id = jet ? "MOVEMENT_BRIDGING" : "MOVEMENT_LINK_TRANSITION"; 343 | break; 344 | case MOVEMENT_LINK_DIRECT: 345 | id = "MOVEMENT_LINK_DIRECT"; 346 | break; 347 | case MOVEMENT_RAMP_HELIX: 348 | id = jet ? "MOVEMENT_PIERCE_CIRCULAR" : "MOVEMENT_RAMP_HELIX"; 349 | break; 350 | case MOVEMENT_RAMP_PROFILE: 351 | id = jet ? "MOVEMENT_PIERCE_PROFILE" : "MOVEMENT_RAMP_PROFILE"; 352 | break; 353 | case MOVEMENT_RAMP_ZIG_ZAG: 354 | id = jet ? "MOVEMENT_PIERCE_LINEAR" : "MOVEMENT_RAMP_ZIG_ZAG"; 355 | break; 356 | case MOVEMENT_RAMP: 357 | id = "MOVEMENT_RAMP"; 358 | break; 359 | case MOVEMENT_PLUNGE: 360 | id = jet ? "MOVEMENT_PIERCE" : "MOVEMENT_PLUNGE"; 361 | break; 362 | case MOVEMENT_PREDRILL: 363 | id = "MOVEMENT_PREDRILL"; 364 | break; 365 | case MOVEMENT_EXTENDED: 366 | id = "MOVEMENT_EXTENDED"; 367 | break; 368 | case MOVEMENT_REDUCED: 369 | id = "MOVEMENT_REDUCED"; 370 | break; 371 | case MOVEMENT_HIGH_FEED: 372 | id = "MOVEMENT_HIGH_FEED"; 373 | break; 374 | } 375 | if (id != undefined) { 376 | dumpImpl("onMovement", id + " /*" + getMovementStringId(movement, jet) + "*/"); 377 | } else { 378 | dumpImpl("onMovement", movement + " /*" + getMovementStringId(movement, jet) + "*/"); 379 | } 380 | } 381 | 382 | var RADIUS_COMPENSATION_MAP = {0:"off", 1:"left", 2:"right"}; 383 | 384 | function onRadiusCompensation() { 385 | var id; 386 | switch (radiusCompensation) { 387 | case RADIUS_COMPENSATION_OFF: 388 | id = "RADIUS_COMPENSATION_OFF"; 389 | break; 390 | case RADIUS_COMPENSATION_LEFT: 391 | id = "RADIUS_COMPENSATION_LEFT"; 392 | break; 393 | case RADIUS_COMPENSATION_RIGHT: 394 | id = "RADIUS_COMPENSATION_RIGHT"; 395 | break; 396 | } 397 | dump("onRadiusCompensation", arguments); 398 | if (id != undefined) { 399 | writeln(" radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 400 | } else { 401 | writeln(" radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 402 | } 403 | } 404 | 405 | function onRapid() { 406 | dump("onRapid", arguments); 407 | } 408 | 409 | function onLinear() { 410 | dump("onLinear", arguments); 411 | } 412 | 413 | function onRapid5D() { 414 | dump("onRapid5D", arguments); 415 | } 416 | 417 | function onLinear5D() { 418 | dump("onLinear5D", arguments); 419 | } 420 | 421 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 422 | dump("onCircular", arguments); 423 | writeln(" direction: " + (clockwise ? "CW" : "CCW")); 424 | writeln(" sweep: " + angularFormat.format(getCircularSweep()) + "deg"); 425 | var n = getCircularNormal(); 426 | var plane = ""; 427 | switch (getCircularPlane()) { 428 | case PLANE_XY: 429 | plane = "(XY)"; 430 | break; 431 | case PLANE_ZX: 432 | plane = "(ZX)"; 433 | break; 434 | case PLANE_YZ: 435 | plane = "(YZ)"; 436 | break; 437 | } 438 | writeln(" normal: X=" + spatialFormat.format(n.x) + " Y=" + spatialFormat.format(n.y) + " Z=" + spatialFormat.format(n.z) + " " + plane); 439 | if (isSpiral()) { 440 | writeln(" spiral"); 441 | writeln(" start radius: " + spatialFormat.format(getCircularStartRadius())); 442 | writeln(" end radius: " + spatialFormat.format(getCircularRadius())); 443 | writeln(" delta radius: " + spatialFormat.format(getCircularRadius() - getCircularStartRadius())); 444 | } else { 445 | writeln(" radius: " + spatialFormat.format(getCircularRadius())); 446 | } 447 | if (isHelical()) { 448 | writeln(" helical pitch: " + spatialFormat.format(getHelicalPitch())); 449 | } 450 | } 451 | 452 | function onCommand(command) { 453 | if (isWellKnownCommand(command)) { 454 | dumpImpl("onCommand", getCommandStringId(command)); 455 | } else { 456 | dumpImpl("onCommand", command); 457 | } 458 | } 459 | 460 | function onSectionEnd() { 461 | dump("onSectionEnd", arguments); 462 | 463 | dumpState(); 464 | } 465 | 466 | function onSectionEndSpecialCycle() { 467 | dump("onSectionEndSpecialCycle", arguments); 468 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 469 | } 470 | 471 | function onClose() { 472 | dump("onClose", arguments); 473 | } 474 | -------------------------------------------------------------------------------- /MikronWF41C_TNC355/code.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | FORKID {D38E0AF6-F1A7-4C6D-A0FA-C99BB29E65AE} 6 | */ 7 | 8 | description = "Export CNC file to Visual Studio Code"; 9 | vendor = "Autodesk"; 10 | vendorUrl = "http://www.autodesk.com"; 11 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 12 | certificationLevel = 2; 13 | minimumRevision = 41666; 14 | 15 | longDescription = "The post installs the CNC file for use with the Autodesk HSM Post Processor extension for Visual Studio Code."; 16 | 17 | capabilities = CAPABILITY_INTERMEDIATE; 18 | 19 | function onSection() { 20 | skipRemainingSection(); 21 | } 22 | 23 | function onClose() { 24 | var cncPath = getIntermediatePath(); 25 | var fileName = FileSystem.getFilename(cncPath); 26 | var destPath = FileSystem.getFolderPath(getOutputPath()); 27 | 28 | if (getPlatform() == "WIN32") { 29 | if (!FileSystem.isFolder(FileSystem.getTemporaryFolder())) { 30 | FileSystem.makeFolder(FileSystem.getTemporaryFolder()); 31 | } 32 | var path = FileSystem.getTemporaryFile("post"); 33 | 34 | var registryPaths = [ 35 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1", 36 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1", 37 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1", 38 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1", 39 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1", 40 | "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{D628A17A-9713-46BF-8D57-E671B46A741E}_is1" 41 | ]; 42 | 43 | var exePath; 44 | for (var i = 0; i < registryPaths.length; ++i) { 45 | if (hasRegistryValue(registryPaths[i], "InstallLocation")) { 46 | exePath = getRegistryString(registryPaths[i], "InstallLocation"); 47 | if (FileSystem.isFile(exePath + "\\code.exe")) { 48 | break; // found 49 | } 50 | } 51 | } 52 | 53 | if (exePath) { 54 | exePath = FileSystem.getCombinedPath(exePath, "\\bin\\code.cmd"); 55 | } else { 56 | error(localize("Visual Studio Code not found.")); 57 | return; 58 | } 59 | 60 | var a = "code --list-extensions --show-versions"; 61 | execute(exePath, a + ">" + path, false, ""); 62 | 63 | var result = {}; 64 | try { 65 | var file = new TextFile(path, false, "utf-8"); 66 | while (true) { 67 | var line = file.readln(); 68 | var index = line.indexOf("@"); 69 | if (index >= 0) { 70 | var name = line.substr(0, index); 71 | var value = line.substr(index + 1); 72 | result[name] = value; 73 | } 74 | } 75 | } catch (e) { 76 | // fail 77 | } 78 | file.close(); 79 | 80 | FileSystem.remove(path); 81 | 82 | var gotValues = false; 83 | for (var name in result) { 84 | gotValues = true; 85 | break; 86 | } 87 | 88 | var foundExtension = false; 89 | var extension; 90 | for (var name in result) { 91 | var value = result[name]; 92 | switch (name) { 93 | case "Autodesk.hsm-post-processor": 94 | extension = name + "-" + value; 95 | foundExtension = true; 96 | break; 97 | } 98 | } 99 | if (!foundExtension) { 100 | error(localize("Autodesk HSM Post Processor extension not found.")); 101 | return; 102 | } 103 | 104 | var userProfile = getEnvironmentVariable("USERPROFILE"); 105 | var extensionFolder = FileSystem.getCombinedPath(userProfile, "\\.vscode\\extensions\\" + extension); 106 | 107 | if (FileSystem.isFile(cncPath)) { 108 | if (!FileSystem.isFolder(extensionFolder)) { 109 | error(localize("Autodesk HSM Post Processor extension not found.")); 110 | return; 111 | } 112 | var customFolder = FileSystem.getCombinedPath(extensionFolder, "\\res\\CNC files\\Custom"); 113 | if (!FileSystem.isFolder(customFolder)) { 114 | FileSystem.makeFolder(customFolder); 115 | } 116 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(customFolder, fileName)); 117 | } 118 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + customFolder + "\"" + " and you can select it in VS Code."); 119 | } else { // non windows 120 | FileSystem.copyFile(cncPath, FileSystem.getCombinedPath(destPath, fileName)); 121 | writeln("Success, your CNC file " + "\"" + fileName + "\"" + " is now located in " + "\"" + destPath + "\"" + "."); 122 | writeln("You need to manually import the CNC file in VS Code by a right click into the CNC Selector panel and select 'Import CNC file...'."); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /MikronWF41C_TNC355/dump.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2016 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | Dump configuration. 6 | 7 | $Revision: 41602 8a235290846bfe71ead6a010711f4fc730f48827 $ 8 | $Date: 2017-09-14 12:16:32 $ 9 | 10 | FORKID {4E9DFE89-DA1C-4531-98C9-7FECF672BD47} 11 | */ 12 | 13 | description = "Dumper"; 14 | vendor = "Autodesk"; 15 | vendorUrl = "http://www.autodesk.com"; 16 | legal = "Copyright (C) 2012-2016 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | 19 | longDescription = "Use this post to understand which information is available when developing a new post. The post will output the primary information for each entry function being called."; 20 | 21 | extension = "dmp"; 22 | // using user code page 23 | 24 | capabilities = CAPABILITY_INTERMEDIATE; 25 | 26 | allowMachineChangeOnSection = true; 27 | allowHelicalMoves = true; 28 | allowSpiralMoves = true; 29 | allowedCircularPlanes = undefined; // allow any circular motion 30 | maximumCircularSweep = toRad(1000000); 31 | minimumCircularRadius = spatial(0.001, MM); 32 | maximumCircularRadius = spatial(1000000, MM); 33 | 34 | // user-defined properties 35 | properties = { 36 | showState: true, // show the commonly interesting current state 37 | expandCycles: true // enable to expand cycles when supported 38 | }; 39 | 40 | // user-defined property definitions 41 | propertyDefinitions = { 42 | showState: {title:"Show state", description:"Shows the commonly interesting current state.", type:"boolean"}, 43 | expandCycles: {title:"Expand cycles", description:"If enabled, unhandled cycles are expanded.", type:"boolean"} 44 | }; 45 | 46 | 47 | var spatialFormat = createFormat({decimals:6}); 48 | var angularFormat = createFormat({decimals:6, scale:DEG}); 49 | var rpmFormat = createFormat({decimals:6}); 50 | var otherFormat = createFormat({decimals:6}); 51 | 52 | var expanding = false; 53 | 54 | function toString(value) { 55 | if (typeof value == "string") { 56 | return "'" + value + "'"; 57 | } else { 58 | return value; 59 | } 60 | } 61 | 62 | function dumpImpl(name, text) { 63 | writeln(getCurrentRecordId() + ": " + name + "(" + text + ")"); 64 | } 65 | 66 | function dump(name, _arguments) { 67 | var result = getCurrentRecordId() + ": " + (expanding ? "EXPANDED " : "") + name + "("; 68 | for (var i = 0; i < _arguments.length; ++i) { 69 | if (i > 0) { 70 | result += ", "; 71 | } 72 | if (typeof _arguments[i] == "string") { 73 | result += "'" + _arguments[i] + "'"; 74 | } else { 75 | result += _arguments[i]; 76 | } 77 | } 78 | result += ")"; 79 | writeln(result); 80 | } 81 | 82 | function onMachine() { 83 | dump("onMachine", arguments); 84 | if (machineConfiguration.getVendor()) { 85 | writeln(" " + "Vendor" + ": " + machineConfiguration.getVendor()); 86 | } 87 | if (machineConfiguration.getModel()) { 88 | writeln(" " + "Model" + ": " + machineConfiguration.getModel()); 89 | } 90 | if (machineConfiguration.getDescription()) { 91 | writeln(" " + "Description" + ": " + machineConfiguration.getDescription()); 92 | } 93 | } 94 | 95 | function onOpen() { 96 | dump("onOpen", arguments); 97 | } 98 | 99 | function onPassThrough() { 100 | dump("onPassThrough", arguments); 101 | } 102 | 103 | function onComment() { 104 | dump("onComment", arguments); 105 | } 106 | 107 | /** Write the current state. */ 108 | function dumpState() { 109 | if (!properties.showState) { 110 | return; 111 | } 112 | 113 | writeln(" STATE position=[" + spatialFormat.format(getCurrentPosition().x) + ", " + spatialFormat.format(getCurrentPosition().y) + ", " + spatialFormat.format(getCurrentPosition().z) + "]"); 114 | if ((currentSection.getType() == TYPE_MILLING) || (currentSection.getType() == TYPE_TURNING)) { 115 | writeln(" STATE spindleSpeed=" + rpmFormat.format(spindleSpeed)); 116 | } 117 | if (currentSection.getType() == TYPE_JET) { 118 | writeln(" STATE power=" + (power ? "ON" : "OFF")); 119 | } 120 | // writeln(" STATE movement=" + movement); 121 | // writeln(" STATE feedrate=" + spatialFormat.format(feedrate)); 122 | // writeln(" STATE compensationOffset=" + compensationOffset); 123 | 124 | var id; 125 | switch (radiusCompensation) { 126 | case RADIUS_COMPENSATION_OFF: 127 | id = "RADIUS_COMPENSATION_OFF"; 128 | break; 129 | case RADIUS_COMPENSATION_LEFT: 130 | id = "RADIUS_COMPENSATION_LEFT"; 131 | break; 132 | case RADIUS_COMPENSATION_RIGHT: 133 | id = "RADIUS_COMPENSATION_RIGHT"; 134 | break; 135 | } 136 | if (id != undefined) { 137 | writeln(" STATE radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 138 | } else { 139 | writeln(" STATE radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 140 | } 141 | } 142 | 143 | function onSection() { 144 | dump("onSection", arguments); 145 | 146 | var name; 147 | for (name in currentSection) { 148 | value = currentSection[name]; 149 | if (typeof value != "function") { 150 | writeln(" currentSection." + name + "=" + toString(value)); 151 | } 152 | } 153 | 154 | for (name in tool) { 155 | value = tool[name]; 156 | if (typeof value != "function") { 157 | writeln(" tool." + name + "=" + toString(value)); 158 | } 159 | } 160 | 161 | { 162 | var shaft = tool.shaft; 163 | if (shaft && shaft.hasSections()) { 164 | var n = shaft.getNumberOfSections(); 165 | for (var i = 0; i < n; ++i) { 166 | writeln(" tool.shaft[" + i + "] H=" + shaft.getLength(i) + " D=" + shaft.getDiameter(i)); 167 | } 168 | } 169 | } 170 | 171 | { 172 | var holder = tool.holder; 173 | if (holder && holder.hasSections()) { 174 | var n = holder.getNumberOfSections(); 175 | for (var i = 0; i < n; ++i) { 176 | writeln(" tool.holder[" + i + "] H=" + holder.getLength(i) + " D=" + holder.getDiameter(i)); 177 | } 178 | } 179 | } 180 | 181 | if (currentSection.isPatterned && currentSection.isPatterned()) { 182 | var patternId = currentSection.getPatternId(); 183 | var sections = []; 184 | var first = true; 185 | for (var i = 0; i < getNumberOfSections(); ++i) { 186 | var section = getSection(i); 187 | if (section.getPatternId() == patternId) { 188 | if (i < getCurrentSectionId()) { 189 | first = false; // not the first pattern instance 190 | } 191 | if (i != getCurrentSectionId()) { 192 | sections.push(section.getId()); 193 | } 194 | } 195 | } 196 | writeln(" >>> Pattern instances: " + sections); 197 | if (!first) { 198 | // writeln(" SKIPPING PATTERN INSTANCE"); 199 | // skipRemainingSection(); 200 | } 201 | } 202 | 203 | dumpState(); 204 | } 205 | 206 | function onSectionSpecialCycle() { 207 | dump("onSectionSpecialCycle", arguments); 208 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 209 | } 210 | 211 | function onPower() { 212 | dump("onPower", arguments); 213 | } 214 | 215 | function onSpindleSpeed() { 216 | dump("onSpindleSpeed", arguments); 217 | } 218 | 219 | function onParameter() { 220 | dump("onParameter", arguments); 221 | } 222 | 223 | function onDwell() { 224 | dump("onDwell", arguments); 225 | } 226 | 227 | function onCycle() { 228 | dump("onCycle", arguments); 229 | 230 | writeln(" cycleType=" + toString(cycleType)); 231 | for (var name in cycle) { 232 | value = cycle[name]; 233 | if (typeof value != "function") { 234 | writeln(" cycle." + name + "=" + toString(value)); 235 | } 236 | } 237 | } 238 | 239 | function onCyclePoint(x, y, z) { 240 | dump("onCyclePoint", arguments); 241 | 242 | if (properties.expandCycles) { 243 | 244 | switch (cycleType) { 245 | case "drilling": // G81 style 246 | case "counter-boring": // G82 style 247 | case "chip-breaking": // G73 style 248 | case "deep-drilling": // G83 style 249 | case "break-through-drilling": 250 | case "gun-drilling": 251 | case "tapping": 252 | case "left-tapping": // G74 style 253 | case "right-tapping": // G84 style 254 | case "tapping-with-chip-breaking": 255 | case "left-tapping-with-chip-breaking": 256 | case "right-tapping-with-chip-breaking": 257 | case "reaming": // G85 style 258 | case "boring": // G89 style 259 | case "stop-boring": // G86 style 260 | case "fine-boring": // G76 style 261 | case "back-boring": // G87 style 262 | case "manual-boring": 263 | case "bore-milling": 264 | case "thread-milling": 265 | case "circular-pocket-milling": 266 | expanding = true; 267 | expandCyclePoint(x, y, z); 268 | expanding = false; 269 | break; 270 | default: 271 | writeln(" CYCLE CANNOT BE EXPANDED"); 272 | } 273 | } 274 | 275 | dumpState(); 276 | } 277 | 278 | function onCycleEnd() { 279 | dump("onCycleEnd", arguments); 280 | } 281 | 282 | /** 283 | Returns the string id for the specified movement. Returns the movement id as 284 | a string if unknown. 285 | */ 286 | function getMovementStringId(movement, jet) { 287 | switch (movement) { 288 | case MOVEMENT_RAPID: 289 | return "rapid"; 290 | case MOVEMENT_LEAD_IN: 291 | return "lead in"; 292 | case MOVEMENT_CUTTING: 293 | return "cutting"; 294 | case MOVEMENT_LEAD_OUT: 295 | return "lead out"; 296 | case MOVEMENT_LINK_TRANSITION: 297 | return !jet ? "transition" : "bridging"; 298 | case MOVEMENT_LINK_DIRECT: 299 | return "direct"; 300 | case MOVEMENT_RAMP_HELIX: 301 | return !jet ? "helix ramp" : "circular pierce"; 302 | case MOVEMENT_RAMP_PROFILE: 303 | return !jet ? "profile ramp" : "profile pierce"; 304 | case MOVEMENT_RAMP_ZIG_ZAG: 305 | return !jet ? "zigzag ramp" : "linear pierce"; 306 | case MOVEMENT_RAMP: 307 | return !jet ? "ramp" : "pierce"; 308 | case MOVEMENT_PLUNGE: 309 | return !jet ? "plunge" : "pierce"; 310 | case MOVEMENT_PREDRILL: 311 | return "predrill"; 312 | case MOVEMENT_EXTENDED: 313 | return "extended"; 314 | case MOVEMENT_REDUCED: 315 | return "reduced"; 316 | case MOVEMENT_FINISH_CUTTING: 317 | return "finish cut"; 318 | case MOVEMENT_HIGH_FEED: 319 | return "high feed"; 320 | default: 321 | return String(movement); 322 | } 323 | } 324 | 325 | function onMovement(movement) { 326 | var jet = tool.isJetTool && tool.isJetTool(); 327 | var id; 328 | switch (movement) { 329 | case MOVEMENT_RAPID: 330 | id = "MOVEMENT_RAPID"; 331 | break; 332 | case MOVEMENT_LEAD_IN: 333 | id = "MOVEMENT_LEAD_IN"; 334 | break; 335 | case MOVEMENT_CUTTING: 336 | id = "MOVEMENT_CUTTING"; 337 | break; 338 | case MOVEMENT_LEAD_OUT: 339 | id = "MOVEMENT_LEAD_OUT"; 340 | break; 341 | case MOVEMENT_LINK_TRANSITION: 342 | id = jet ? "MOVEMENT_BRIDGING" : "MOVEMENT_LINK_TRANSITION"; 343 | break; 344 | case MOVEMENT_LINK_DIRECT: 345 | id = "MOVEMENT_LINK_DIRECT"; 346 | break; 347 | case MOVEMENT_RAMP_HELIX: 348 | id = jet ? "MOVEMENT_PIERCE_CIRCULAR" : "MOVEMENT_RAMP_HELIX"; 349 | break; 350 | case MOVEMENT_RAMP_PROFILE: 351 | id = jet ? "MOVEMENT_PIERCE_PROFILE" : "MOVEMENT_RAMP_PROFILE"; 352 | break; 353 | case MOVEMENT_RAMP_ZIG_ZAG: 354 | id = jet ? "MOVEMENT_PIERCE_LINEAR" : "MOVEMENT_RAMP_ZIG_ZAG"; 355 | break; 356 | case MOVEMENT_RAMP: 357 | id = "MOVEMENT_RAMP"; 358 | break; 359 | case MOVEMENT_PLUNGE: 360 | id = jet ? "MOVEMENT_PIERCE" : "MOVEMENT_PLUNGE"; 361 | break; 362 | case MOVEMENT_PREDRILL: 363 | id = "MOVEMENT_PREDRILL"; 364 | break; 365 | case MOVEMENT_EXTENDED: 366 | id = "MOVEMENT_EXTENDED"; 367 | break; 368 | case MOVEMENT_REDUCED: 369 | id = "MOVEMENT_REDUCED"; 370 | break; 371 | case MOVEMENT_HIGH_FEED: 372 | id = "MOVEMENT_HIGH_FEED"; 373 | break; 374 | } 375 | if (id != undefined) { 376 | dumpImpl("onMovement", id + " /*" + getMovementStringId(movement, jet) + "*/"); 377 | } else { 378 | dumpImpl("onMovement", movement + " /*" + getMovementStringId(movement, jet) + "*/"); 379 | } 380 | } 381 | 382 | var RADIUS_COMPENSATION_MAP = {0:"off", 1:"left", 2:"right"}; 383 | 384 | function onRadiusCompensation() { 385 | var id; 386 | switch (radiusCompensation) { 387 | case RADIUS_COMPENSATION_OFF: 388 | id = "RADIUS_COMPENSATION_OFF"; 389 | break; 390 | case RADIUS_COMPENSATION_LEFT: 391 | id = "RADIUS_COMPENSATION_LEFT"; 392 | break; 393 | case RADIUS_COMPENSATION_RIGHT: 394 | id = "RADIUS_COMPENSATION_RIGHT"; 395 | break; 396 | } 397 | dump("onRadiusCompensation", arguments); 398 | if (id != undefined) { 399 | writeln(" radiusCompensation=" + id + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 400 | } else { 401 | writeln(" radiusCompensation=" + radiusCompensation + " // " + RADIUS_COMPENSATION_MAP[radiusCompensation]); 402 | } 403 | } 404 | 405 | function onRapid() { 406 | dump("onRapid", arguments); 407 | } 408 | 409 | function onLinear() { 410 | dump("onLinear", arguments); 411 | } 412 | 413 | function onRapid5D() { 414 | dump("onRapid5D", arguments); 415 | } 416 | 417 | function onLinear5D() { 418 | dump("onLinear5D", arguments); 419 | } 420 | 421 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 422 | dump("onCircular", arguments); 423 | writeln(" direction: " + (clockwise ? "CW" : "CCW")); 424 | writeln(" sweep: " + angularFormat.format(getCircularSweep()) + "deg"); 425 | var n = getCircularNormal(); 426 | var plane = ""; 427 | switch (getCircularPlane()) { 428 | case PLANE_XY: 429 | plane = "(XY)"; 430 | break; 431 | case PLANE_ZX: 432 | plane = "(ZX)"; 433 | break; 434 | case PLANE_YZ: 435 | plane = "(YZ)"; 436 | break; 437 | } 438 | writeln(" normal: X=" + spatialFormat.format(n.x) + " Y=" + spatialFormat.format(n.y) + " Z=" + spatialFormat.format(n.z) + " " + plane); 439 | if (isSpiral()) { 440 | writeln(" spiral"); 441 | writeln(" start radius: " + spatialFormat.format(getCircularStartRadius())); 442 | writeln(" end radius: " + spatialFormat.format(getCircularRadius())); 443 | writeln(" delta radius: " + spatialFormat.format(getCircularRadius() - getCircularStartRadius())); 444 | } else { 445 | writeln(" radius: " + spatialFormat.format(getCircularRadius())); 446 | } 447 | if (isHelical()) { 448 | writeln(" helical pitch: " + spatialFormat.format(getHelicalPitch())); 449 | } 450 | } 451 | 452 | function onCommand(command) { 453 | if (isWellKnownCommand(command)) { 454 | dumpImpl("onCommand", getCommandStringId(command)); 455 | } else { 456 | dumpImpl("onCommand", command); 457 | } 458 | } 459 | 460 | function onSectionEnd() { 461 | dump("onSectionEnd", arguments); 462 | 463 | dumpState(); 464 | } 465 | 466 | function onSectionEndSpecialCycle() { 467 | dump("onSectionEndSpecialCycle", arguments); 468 | writeln(" cycle: " + toString(currentSection.getFirstCycle())); 469 | } 470 | 471 | function onClose() { 472 | dump("onClose", arguments); 473 | } 474 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fusion_post 2 | modified post-processors for fusion 360 3 | -------------------------------------------------------------------------------- /protrak_mill/24495_manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mwinterm/fusion_post/bae0f13f943f4df1ae6ff116707d32f5ef036bc9/protrak_mill/24495_manual.pdf -------------------------------------------------------------------------------- /protrak_mill/prototrak_mill.cps: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright (C) 2012-2018 by Autodesk, Inc. 3 | All rights reserved. 4 | 5 | ProtoTRAK GCD post processor configuration. 6 | 7 | $Revision: 42049 24365c4692af9ba58117d1ab4b45705fca82c227 $ 8 | $Date: 2020-06-03 20:11:22 $ 9 | 10 | FORKID {065403A3-A589-43ef-B345-90B5274EE274} 11 | */ 12 | 13 | description = "ProtoTRAK GCD"; 14 | vendor = "Southwestern Industries"; 15 | vendorUrl = "http://www.southwesternindustries.com"; 16 | legal = "Copyright (C) 2012-2018 by Autodesk, Inc."; 17 | certificationLevel = 2; 18 | minimumRevision = 40783; 19 | 20 | longDescription = "Generic milling post for ProtoTRAK GCD format."; 21 | 22 | extension = "gcd"; // use "cam" for some controls 23 | programNameIsInteger = true; 24 | setCodePage("ascii"); 25 | 26 | capabilities = CAPABILITY_MILLING; 27 | tolerance = spatial(0.002, MM); 28 | 29 | minimumChordLength = spatial(0.25, MM); 30 | minimumCircularRadius = spatial(0.01, MM); 31 | maximumCircularRadius = spatial(1000, MM); 32 | minimumCircularSweep = toRad(0.01); 33 | maximumCircularSweep = toRad(90); 34 | allowHelicalMoves = true; 35 | allowedCircularPlanes = undefined; // allow any circular motion 36 | 37 | 38 | 39 | // user-defined properties 40 | properties = { 41 | writeMachine: true, // write machine 42 | writeTools: true, // writes the tools 43 | writeVersion: true, // include version info 44 | preloadTool: true, // preloads next tool on tool change if any 45 | showSequenceNumbers: true, // show sequence numbers 46 | sequenceNumberStart: 10, // first sequence number 47 | sequenceNumberIncrement: 5, // increment for sequence numbers 48 | optionalStop: true, // optional stop 49 | separateWordsWithSpace: true, // specifies that the words should be separated with a white space 50 | useRigidTapping: "yes", // output rigid tapping block 51 | circularOutsideXY: false // circular in YZ and ZX planes 52 | }; 53 | 54 | // user-defined property definitions 55 | propertyDefinitions = { 56 | writeMachine: { title: "Write machine", description: "Output the machine settings in the header of the code.", group: 0, type: "boolean" }, 57 | writeTools: { title: "Write tool list", description: "Output a tool list in the header of the code.", group: 0, type: "boolean" }, 58 | writeVersion: { title: "Write version", description: "Write the version number in the header of the code.", group: 0, type: "boolean" }, 59 | preloadTool: { title: "Preload tool", description: "Preloads the next tool at a tool change (if any).", group: 1, type: "boolean" }, 60 | showSequenceNumbers: { title: "Use sequence numbers", description: "Use sequence numbers for each block of outputted code.", group: 1, type: "boolean" }, 61 | sequenceNumberStart: { title: "Start sequence number", description: "The number at which to start the sequence numbers.", group: 1, type: "integer" }, 62 | sequenceNumberIncrement: { title: "Sequence number increment", description: "The amount by which the sequence number is incremented by in each block.", group: 1, type: "integer" }, 63 | optionalStop: { title: "Optional stop", description: "Outputs optional stop code during when necessary in the code.", type: "boolean" }, 64 | separateWordsWithSpace: { title: "Separate words with space", description: "Adds spaces between words if 'yes' is selected.", type: "boolean" }, 65 | useRigidTapping: { 66 | title: "Use rigid tapping", 67 | description: "Select 'Yes' to enable, 'No' to disable, or 'Without spindle direction' to enable rigid tapping without outputting the spindle direction block.", 68 | type: "enum", 69 | values: [ 70 | { title: "Yes", id: "yes" }, 71 | { title: "No", id: "no" }, 72 | { title: "Without spindle direction", id: "without" } 73 | ] 74 | }, 75 | circularOutsideXY: { title: "Allow circular outside of XY-plane", description: "Allow circular interpolation to be output in the YZ and ZX planes.", group: 0, type: "boolean" } 76 | }; 77 | 78 | var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-"; 79 | 80 | // samples: 81 | // throughTool: {on: 88, off: 89} 82 | // throughTool: {on: [8, 88], off: [9, 89]} 83 | var coolants = { 84 | flood: { on: 8 }, 85 | mist: { on: 7 }, 86 | throughTool: {}, 87 | air: {}, 88 | airThroughTool: {}, 89 | suction: {}, 90 | floodMist: {}, 91 | floodThroughTool: {}, 92 | off: 9 93 | }; 94 | 95 | var gFormat = createFormat({ prefix: "G", width: 2, zeropad: true, decimals: 0 }); 96 | var mFormat = createFormat({ prefix: "M", width: 2, zeropad: true, decimals: 0 }); 97 | var hFormat = createFormat({ prefix: "H", width: 2, zeropad: true, decimals: 0 }); 98 | var dFormat = createFormat({ prefix: "D", width: 2, zeropad: true, decimals: 0 }); 99 | var nFormat = createFormat({ prefix: "N", width: 4, zeropad: true, decimals: 0 }); 100 | 101 | var xyzFormat = createFormat({ decimals: (unit == MM ? 4 : 4), forceDecimal: true }); 102 | var rFormat = xyzFormat; // radius 103 | var abcFormat = createFormat({ decimals: 3, forceDecimal: true }); 104 | var feedFormat = createFormat({ decimals: (unit == MM ? 0 : 1), forceDecimal: true }); 105 | var toolFormat = createFormat({ width: 2, zeropad: true, decimals: 0 }); 106 | var rpmFormat = createFormat({ decimals: 0 }); 107 | var secFormat = createFormat({ decimals: 3, forceDecimal: true }); // seconds - range 0.001-99999.999 108 | var milliFormat = createFormat({ decimals: 0 }); // milliseconds // range 1-9999 109 | var taperFormat = createFormat({ decimals: 1, scale: DEG }); 110 | 111 | var xOutput = createVariable({ prefix: "X" }, xyzFormat); 112 | var yOutput = createVariable({ prefix: "Y" }, xyzFormat); 113 | var zOutput = createVariable({ onchange: function () { retracted = false; }, prefix: "Z" }, xyzFormat); 114 | var aOutput = createVariable({ prefix: "A" }, abcFormat); 115 | var bOutput = createVariable({ prefix: "B" }, abcFormat); 116 | var cOutput = createVariable({ prefix: "C" }, abcFormat); 117 | var feedOutput = createVariable({ prefix: "F" }, feedFormat); 118 | var sOutput = createVariable({ prefix: "S", force: true }, rpmFormat); 119 | var dOutput = createVariable({}, dFormat); 120 | 121 | // circular output 122 | var iOutput = createReferenceVariable({ prefix: "I", force: true }, xyzFormat); 123 | var jOutput = createReferenceVariable({ prefix: "J", force: true }, xyzFormat); 124 | var kOutput = createReferenceVariable({ prefix: "K", force: true }, xyzFormat); 125 | 126 | var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ... 127 | var gPlaneModal = createModal({ onchange: function () { gMotionModal.reset(); } }, gFormat); // modal group 2 // G17-19 128 | var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91 129 | var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94 130 | var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21 131 | var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ... 132 | var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99 133 | 134 | var WARNING_WORK_OFFSET = 0; 135 | 136 | // collected state 137 | var sequenceNumber; 138 | var currentWorkOffset; 139 | var retracted = false; // specifies that the tool has been retracted to the safe plane 140 | 141 | /** 142 | Writes the specified block. 143 | */ 144 | function writeBlock() { 145 | if (!formatWords(arguments)) { 146 | return; 147 | } 148 | if (properties.showSequenceNumbers) { 149 | writeWords2(nFormat.format(sequenceNumber % 100000), arguments); 150 | sequenceNumber += properties.sequenceNumberIncrement; 151 | } else { 152 | writeWords(arguments); 153 | } 154 | } 155 | 156 | /** 157 | Defines a machine. 158 | */ 159 | function defineMachine() { 160 | machineConfiguration.setVendor(vendor); 161 | machineConfiguration.setModel("ProtoTrak"); 162 | machineConfiguration.setDescription("3-axis mill"); 163 | } 164 | 165 | /** 166 | Output a comment. 167 | */ 168 | function writeComment(text) { 169 | writeln("(" + filterText(String(text).toUpperCase(), permittedCommentChars) + ")"); 170 | } 171 | 172 | function onOpen() { 173 | if (!properties.circularOutsideXY) { 174 | allowedCircularPlanes = (1 << PLANE_XY); // allow XY-plane circular motion 175 | } 176 | 177 | if (!machineConfiguration.isMachineCoordinate(0)) { 178 | aOutput.disable(); 179 | } 180 | if (!machineConfiguration.isMachineCoordinate(1)) { 181 | bOutput.disable(); 182 | } 183 | if (!machineConfiguration.isMachineCoordinate(2)) { 184 | cOutput.disable(); 185 | } 186 | 187 | if (!properties.separateWordsWithSpace) { 188 | setWordSeparator(""); 189 | } 190 | 191 | sequenceNumber = properties.sequenceNumberStart; 192 | 193 | if (programName) { 194 | writeComment(programName); 195 | } 196 | if (programComment) { 197 | writeComment(programComment); 198 | } 199 | 200 | //write program generation date and time 201 | let current_datetime = new Date(); 202 | var date = current_datetime.getDate(); 203 | var month = current_datetime.getMonth() + 1; 204 | var year = current_datetime.getFullYear(); 205 | var hours = current_datetime.getHours(); 206 | var minutes = current_datetime.getMinutes(); 207 | var seconds = current_datetime.getSeconds(); 208 | yearFormatted = year; 209 | monthFormatted = month < 10 ? "0" + month : month; 210 | dateFormatted = date < 10 ? "0" + date : date; 211 | hoursFormatted = hours < 10 ? "0" + hours : hours; 212 | minutesFormatted = minutes < 10 ? "0" + minutes : minutes; 213 | secondsFormatted = seconds < 10 ? "0" + seconds : seconds; 214 | writeln(""); 215 | writeComment("Program created " + yearFormatted + "-" + monthFormatted + "-" + dateFormatted + " " + hoursFormatted + "-" + minutesFormatted + "-" + secondsFormatted); 216 | writeln(""); 217 | 218 | if (properties.writeVersion) { 219 | writeComment(localize("--- POST ---")); 220 | if ((typeof getHeaderVersion == "function") && getHeaderVersion()) { 221 | writeComment(localize("post version") + ": " + getHeaderVersion()); 222 | } 223 | if ((typeof getHeaderDate == "function") && getHeaderDate()) { 224 | writeComment(localize("post modified") + ": " + getHeaderDate().replace(/:/g, "-")); 225 | } 226 | writeln(""); 227 | } 228 | 229 | // dump machine configuration 230 | defineMachine(); 231 | var vendor = machineConfiguration.getVendor(); 232 | var model = machineConfiguration.getModel(); 233 | var description = machineConfiguration.getDescription(); 234 | 235 | if (properties.writeMachine && (vendor || model || description)) { 236 | writeComment(localize("--- Machine ---")); 237 | if (vendor) { 238 | writeComment(" " + localize("vendor") + ": " + vendor); 239 | } 240 | if (model) { 241 | writeComment(" " + localize("model") + ": " + model); 242 | } 243 | if (description) { 244 | writeComment(" " + localize("description") + ": " + description); 245 | } 246 | writeln(""); 247 | } 248 | 249 | // dump tool information 250 | if (properties.writeTools) { 251 | writeComment("--- Tools ---"); 252 | 253 | var zRanges = {}; 254 | if (is3D()) { 255 | var numberOfSections = getNumberOfSections(); 256 | for (var i = 0; i < numberOfSections; ++i) { 257 | var section = getSection(i); 258 | var zRange = section.getGlobalZRange(); 259 | var tool = section.getTool(); 260 | if (zRanges[tool.number]) { 261 | zRanges[tool.number].expandToRange(zRange); 262 | } else { 263 | zRanges[tool.number] = zRange; 264 | } 265 | } 266 | } 267 | 268 | var tools = getToolTable(); 269 | if (tools.getNumberOfTools() > 0) { 270 | for (var i = 0; i < tools.getNumberOfTools(); ++i) { 271 | var tool = tools.getTool(i); 272 | var comment = "T" + toolFormat.format(tool.number) + " " + 273 | "D=" + xyzFormat.format(tool.diameter) + " " + 274 | localize("CR") + "=" + xyzFormat.format(tool.cornerRadius); 275 | if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) { 276 | comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg"); 277 | } 278 | if (zRanges[tool.number]) { 279 | comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum()); 280 | } 281 | comment += " - " + getToolTypeName(tool.type); 282 | writeComment(comment); 283 | } 284 | } 285 | writeln(""); 286 | } 287 | 288 | 289 | if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) { 290 | for (var i = 0; i < getNumberOfSections(); ++i) { 291 | if (getSection(i).workOffset > 0) { 292 | error(localize("Using multiple work offsets is not possible if the initial work offset is 0.")); 293 | return; 294 | } 295 | } 296 | } 297 | 298 | // absolute coordinates and feed per min 299 | writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17)); 300 | 301 | switch (unit) { 302 | case IN: 303 | writeBlock(gUnitModal.format(20)); 304 | break; 305 | case MM: 306 | writeBlock(gUnitModal.format(21)); 307 | break; 308 | } 309 | } 310 | 311 | function onComment(message) { 312 | writeComment(message); 313 | } 314 | 315 | /** Force output of X, Y, and Z. */ 316 | function forceXYZ() { 317 | xOutput.reset(); 318 | yOutput.reset(); 319 | zOutput.reset(); 320 | } 321 | 322 | /** Force output of A, B, and C. */ 323 | function forceABC() { 324 | aOutput.reset(); 325 | bOutput.reset(); 326 | cOutput.reset(); 327 | } 328 | 329 | /** Force output of X, Y, Z, A, B, C, and F on next output. */ 330 | function forceAny() { 331 | forceXYZ(); 332 | forceABC(); 333 | feedOutput.reset(); 334 | } 335 | 336 | var currentWorkPlaneABC = undefined; 337 | 338 | function forceWorkPlane() { 339 | currentWorkPlaneABC = undefined; 340 | } 341 | 342 | function setWorkPlane(abc) { 343 | if (!machineConfiguration.isMultiAxisConfiguration()) { 344 | return; // ignore 345 | } 346 | 347 | if (!((currentWorkPlaneABC == undefined) || 348 | abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) || 349 | abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) || 350 | abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) { 351 | return; // no change 352 | } 353 | 354 | onCommand(COMMAND_UNLOCK_MULTI_AXIS); 355 | 356 | // NOTE: add retract here 357 | 358 | writeBlock( 359 | gMotionModal.format(0), 360 | conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)), 361 | conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)), 362 | conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z)) 363 | ); 364 | 365 | onCommand(COMMAND_LOCK_MULTI_AXIS); 366 | 367 | currentWorkPlaneABC = abc; 368 | } 369 | 370 | var closestABC = false; // choose closest machine angles 371 | var currentMachineABC; 372 | 373 | function getWorkPlaneMachineABC(workPlane) { 374 | var W = workPlane; // map to global frame 375 | 376 | var abc = machineConfiguration.getABC(W); 377 | if (closestABC) { 378 | if (currentMachineABC) { 379 | abc = machineConfiguration.remapToABC(abc, currentMachineABC); 380 | } else { 381 | abc = machineConfiguration.getPreferredABC(abc); 382 | } 383 | } else { 384 | abc = machineConfiguration.getPreferredABC(abc); 385 | } 386 | 387 | try { 388 | abc = machineConfiguration.remapABC(abc); 389 | currentMachineABC = abc; 390 | } catch (e) { 391 | error( 392 | localize("Machine angles not supported") + ":" 393 | + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) 394 | + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) 395 | + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) 396 | ); 397 | return abc; 398 | } 399 | 400 | var direction = machineConfiguration.getDirection(abc); 401 | if (!isSameDirection(direction, W.forward)) { 402 | error(localize("Orientation not supported.")); 403 | return abc; 404 | } 405 | 406 | if (!machineConfiguration.isABCSupported(abc)) { 407 | error( 408 | localize("Work plane is not supported") + ":" 409 | + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x)) 410 | + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y)) 411 | + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z)) 412 | ); 413 | return abc; 414 | } 415 | 416 | var tcp = false; 417 | if (tcp) { 418 | setRotation(W); // TCP mode 419 | } else { 420 | var O = machineConfiguration.getOrientation(abc); 421 | var R = machineConfiguration.getRemainingOrientation(abc, W); 422 | setRotation(R); 423 | } 424 | 425 | return abc; 426 | } 427 | 428 | function isProbeOperation() { 429 | return (hasParameter("operation-strategy") && 430 | getParameter("operation-strategy") == "probe"); 431 | } 432 | 433 | function onSection() { 434 | var insertToolCall = isFirstSection() || 435 | currentSection.getForceToolChange && currentSection.getForceToolChange() || 436 | (tool.number != getPreviousSection().getTool().number); 437 | 438 | retracted = false; // specifies that the tool has been retracted to the safe plane 439 | var newWorkOffset = isFirstSection() || 440 | (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes 441 | var newWorkPlane = isFirstSection() || 442 | !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis()) || 443 | (currentSection.isOptimizedForMachine() && getPreviousSection().isOptimizedForMachine() && 444 | Vector.diff(getPreviousSection().getFinalToolAxisABC(), currentSection.getInitialToolAxisABC()).length > 1e-4) || 445 | (!machineConfiguration.isMultiAxisConfiguration() && currentSection.isMultiAxis()) || 446 | (!getPreviousSection().isMultiAxis() && currentSection.isMultiAxis() || 447 | getPreviousSection().isMultiAxis() && !currentSection.isMultiAxis()); // force newWorkPlane between indexing and simultaneous operations 448 | 449 | if (hasParameter("operation-comment")) { 450 | var comment = getParameter("operation-comment"); 451 | if (comment) { 452 | writeln(""); 453 | writeComment(comment); 454 | } 455 | } 456 | 457 | if (insertToolCall) { 458 | forceWorkPlane(); 459 | 460 | setCoolant(COOLANT_OFF); 461 | 462 | if (!isFirstSection() && properties.optionalStop) { 463 | onCommand(COMMAND_OPTIONAL_STOP); 464 | } 465 | 466 | if (tool.number > 99) { 467 | warning(localize("Tool number exceeds maximum value.")); 468 | } 469 | 470 | writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); 471 | if (tool.comment) { 472 | writeComment(tool.comment); 473 | } 474 | var showToolZMin = false; 475 | if (showToolZMin) { 476 | if (is3D()) { 477 | var numberOfSections = getNumberOfSections(); 478 | var zRange = currentSection.getGlobalZRange(); 479 | var number = tool.number; 480 | for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) { 481 | var section = getSection(i); 482 | if (section.getTool().number != number) { 483 | break; 484 | } 485 | zRange.expandToRange(section.getGlobalZRange()); 486 | } 487 | writeComment(localize("ZMIN") + "=" + zRange.getMinimum()); 488 | } 489 | } 490 | 491 | if (properties.preloadTool) { 492 | var nextTool = getNextTool(tool.number); 493 | if (nextTool) { 494 | writeBlock("T" + toolFormat.format(nextTool.number)); 495 | } else { 496 | // preload first tool 497 | var section = getSection(0); 498 | var firstToolNumber = section.getTool().number; 499 | if (tool.number != firstToolNumber) { 500 | writeBlock("T" + toolFormat.format(firstToolNumber)); 501 | } 502 | } 503 | } 504 | } 505 | 506 | if (insertToolCall || 507 | isFirstSection() || 508 | (rpmFormat.areDifferent(spindleSpeed, sOutput.getCurrent())) || 509 | (tool.clockwise != getPreviousSection().getTool().clockwise)) { 510 | if (spindleSpeed < 1) { 511 | error(localize("Spindle speed out of range.")); 512 | return; 513 | } 514 | if (spindleSpeed > 99999) { 515 | warning(localize("Spindle speed exceeds maximum value.")); 516 | } 517 | var tapping = hasParameter("operation:cycleType") && 518 | ((getParameter("operation:cycleType") == "tapping") || 519 | (getParameter("operation:cycleType") == "right-tapping") || 520 | (getParameter("operation:cycleType") == "left-tapping") || 521 | (getParameter("operation:cycleType") == "tapping-with-chip-breaking")); 522 | if (!tapping || (tapping && !(properties.useRigidTapping == "without"))) { 523 | writeBlock( 524 | sOutput.format(spindleSpeed), mFormat.format(tool.clockwise ? 3 : 4) 525 | ); 526 | } 527 | } 528 | 529 | // wcs 530 | if (insertToolCall) { // force work offset when changing tool 531 | currentWorkOffset = undefined; 532 | } 533 | var workOffset = currentSection.workOffset; 534 | if (workOffset == 0) { 535 | warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET); 536 | workOffset = 1; 537 | } 538 | if (workOffset > 0) { 539 | if (workOffset > 6) { 540 | error(localize("Work offset out of range.")); 541 | return; 542 | } else { 543 | if (workOffset != currentWorkOffset) { 544 | writeBlock(gFormat.format(53 + workOffset)); // G54->G59 545 | currentWorkOffset = workOffset; 546 | } 547 | } 548 | } 549 | 550 | forceXYZ(); 551 | 552 | if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode 553 | // set working plane after datum shift 554 | 555 | var abc = new Vector(0, 0, 0); 556 | if (currentSection.isMultiAxis()) { 557 | forceWorkPlane(); 558 | cancelTransformation(); 559 | } else { 560 | abc = getWorkPlaneMachineABC(currentSection.workPlane); 561 | } 562 | setWorkPlane(abc); 563 | } else { // pure 3D 564 | var remaining = currentSection.workPlane; 565 | if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) { 566 | error(localize("Tool orientation is not supported.")); 567 | return; 568 | } 569 | setRotation(remaining); 570 | } 571 | 572 | // set coolant after we have positioned at Z 573 | setCoolant(tool.coolant); 574 | 575 | forceAny(); 576 | gMotionModal.reset(); 577 | 578 | var initialPosition = getFramePosition(currentSection.getInitialPosition()); 579 | if (!retracted && !insertToolCall) { 580 | if (getCurrentPosition().z < initialPosition.z) { 581 | writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); 582 | } 583 | } 584 | 585 | if (insertToolCall || retracted) { 586 | var lengthOffset = tool.lengthOffset; 587 | if (lengthOffset > 99) { 588 | error(localize("Length offset out of range.")); 589 | return; 590 | } 591 | 592 | gMotionModal.reset(); 593 | writeBlock(gPlaneModal.format(17)); 594 | 595 | if (!machineConfiguration.isHeadConfiguration()) { 596 | writeBlock( 597 | gAbsIncModal.format(90), 598 | gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y) 599 | ); 600 | writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z)); 601 | } else { 602 | writeBlock( 603 | gAbsIncModal.format(90), 604 | gMotionModal.format(0), 605 | xOutput.format(initialPosition.x), 606 | yOutput.format(initialPosition.y), 607 | zOutput.format(initialPosition.z) 608 | ); 609 | } 610 | 611 | gMotionModal.reset(); 612 | } else { 613 | writeBlock( 614 | gAbsIncModal.format(90), 615 | gMotionModal.format(0), 616 | xOutput.format(initialPosition.x), 617 | yOutput.format(initialPosition.y) 618 | ); 619 | } 620 | } 621 | 622 | function onDwell(seconds) { 623 | if (seconds > 99999.999) { 624 | warning(localize("Dwelling time is out of range.")); 625 | } 626 | milliseconds = clamp(1, seconds * 1000, 99999999); 627 | writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + milliFormat.format(milliseconds)); 628 | } 629 | 630 | function onSpindleSpeed(spindleSpeed) { 631 | writeBlock(sOutput.format(spindleSpeed)); 632 | } 633 | 634 | function onCycle() { 635 | writeBlock(gPlaneModal.format(17)); 636 | } 637 | 638 | function getCommonCycle(x, y, z, r) { 639 | forceXYZ(); // force xyz on first drill hole of any cycle 640 | return [xOutput.format(x), yOutput.format(y), 641 | zOutput.format(z), 642 | "R" + xyzFormat.format(r)]; 643 | } 644 | 645 | function onCyclePoint(x, y, z) { 646 | if (isFirstCyclePoint()) { 647 | repositionToCycleClearance(cycle, x, y, z); 648 | 649 | // return to initial Z which is clearance plane and set absolute mode 650 | 651 | var F = cycle.feedrate; 652 | var P = !cycle.dwell ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds 653 | 654 | switch (cycleType) { 655 | case "drilling": 656 | writeBlock( 657 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), 658 | getCommonCycle(x, y, z, cycle.retract), 659 | feedOutput.format(F) 660 | ); 661 | break; 662 | case "counter-boring": 663 | if (P > 0) { 664 | writeBlock( 665 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82), 666 | getCommonCycle(x, y, z, cycle.retract), 667 | "P" + milliFormat.format(P), 668 | feedOutput.format(F) 669 | ); 670 | } else { 671 | writeBlock( 672 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81), 673 | getCommonCycle(x, y, z, cycle.retract), 674 | feedOutput.format(F) 675 | ); 676 | } 677 | break; 678 | case "chip-breaking": 679 | expandCyclePoint(x, y, z); 680 | break; 681 | case "deep-drilling": 682 | if (P > 0) { 683 | expandCyclePoint(x, y, z); 684 | } else { 685 | writeBlock( 686 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83), 687 | getCommonCycle(x, y, z, cycle.retract), 688 | "Q" + xyzFormat.format(cycle.incrementalDepth), 689 | // conditional(P > 0, "P" + milliFormat.format(P)), 690 | feedOutput.format(F) 691 | ); 692 | } 693 | break; 694 | case "tapping": 695 | F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); 696 | if (properties.useRigidTapping != "no") { 697 | writeBlock(mFormat.format(29), sOutput.format(spindleSpeed)); 698 | } 699 | writeBlock( 700 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 74 : 84), 701 | getCommonCycle(x, y, z, cycle.retract), 702 | "P" + milliFormat.format(P), 703 | feedOutput.format(F) 704 | ); 705 | break; 706 | case "left-tapping": 707 | F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); 708 | if (properties.useRigidTapping != "no") { 709 | writeBlock(mFormat.format(29), sOutput.format(spindleSpeed)); 710 | } 711 | writeBlock( 712 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(74), 713 | getCommonCycle(x, y, z, cycle.retract), 714 | "P" + milliFormat.format(P), 715 | feedOutput.format(F) 716 | ); 717 | break; 718 | case "right-tapping": 719 | F = tool.getThreadPitch() * rpmFormat.getResultingValue(spindleSpeed); 720 | if (properties.useRigidTapping != "no") { 721 | writeBlock(mFormat.format(29), sOutput.format(spindleSpeed)); 722 | } 723 | writeBlock( 724 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(84), 725 | getCommonCycle(x, y, z, cycle.retract), 726 | "P" + milliFormat.format(P), 727 | feedOutput.format(F) 728 | ); 729 | break; 730 | case "reaming": 731 | if (P > 0) { 732 | writeBlock( 733 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), 734 | getCommonCycle(x, y, z, cycle.retract), 735 | "P" + milliFormat.format(P), 736 | feedOutput.format(F) 737 | ); 738 | } else { 739 | writeBlock( 740 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), 741 | getCommonCycle(x, y, z, cycle.retract), 742 | feedOutput.format(F) 743 | ); 744 | } 745 | break; 746 | case "boring": 747 | if (P > 0) { 748 | writeBlock( 749 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89), 750 | getCommonCycle(x, y, z, cycle.retract), 751 | "P" + milliFormat.format(P), // not optional 752 | feedOutput.format(F) 753 | ); 754 | } else { 755 | writeBlock( 756 | gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85), 757 | getCommonCycle(x, y, z, cycle.retract), 758 | feedOutput.format(F) 759 | ); 760 | } 761 | break; 762 | default: 763 | expandCyclePoint(x, y, z); 764 | } 765 | } else { 766 | if (cycleExpanded) { 767 | expandCyclePoint(x, y, z); 768 | } else { 769 | writeBlock(xOutput.format(x), yOutput.format(y)); 770 | } 771 | } 772 | } 773 | 774 | function onCycleEnd() { 775 | if (!cycleExpanded) { 776 | writeBlock(gCycleModal.format(80)); 777 | zOutput.reset(); 778 | } 779 | } 780 | 781 | var pendingRadiusCompensation = -1; 782 | 783 | function onRadiusCompensation() { 784 | if (hasParameter("operation:compensationType") && (getParameter("operation:compensationType") == "control") && 785 | (radiusCompensation != RADIUS_COMPENSATION_OFF)) { 786 | error(localize("Radius compensation 'In control' is not supported. Use 'Wear' instead.")); 787 | } 788 | pendingRadiusCompensation = radiusCompensation; 789 | } 790 | 791 | function onRapid(_x, _y, _z) { 792 | var x = xOutput.format(_x); 793 | var y = yOutput.format(_y); 794 | var z = zOutput.format(_z); 795 | if (x || y || z) { 796 | if (pendingRadiusCompensation >= 0) { 797 | error(localize("Radius compensation mode cannot be changed at rapid traversal.")); 798 | return; 799 | } 800 | writeBlock(gMotionModal.format(0), x, y, z); 801 | feedOutput.reset(); 802 | } 803 | } 804 | 805 | function onLinear(_x, _y, _z, feed) { 806 | var x = xOutput.format(_x); 807 | var y = yOutput.format(_y); 808 | var z = zOutput.format(_z); 809 | var f = feedOutput.format(feed); 810 | if (x || y || z) { 811 | if (pendingRadiusCompensation >= 0) { 812 | pendingRadiusCompensation = -1; 813 | writeBlock(gPlaneModal.format(17)); 814 | switch (radiusCompensation) { 815 | case RADIUS_COMPENSATION_LEFT: 816 | dOutput.reset(); 817 | writeBlock(gFormat.format(41)); 818 | writeBlock(gMotionModal.format(1), x, y, z, f); 819 | break; 820 | case RADIUS_COMPENSATION_RIGHT: 821 | dOutput.reset(); 822 | writeBlock(gFormat.format(42)); 823 | writeBlock(gMotionModal.format(1), x, y, z, f); 824 | break; 825 | default: 826 | writeBlock(gFormat.format(40)); 827 | writeBlock(gMotionModal.format(1), x, y, z, f); 828 | } 829 | } else { 830 | writeBlock(gMotionModal.format(1), x, y, z, f); 831 | } 832 | } else if (f) { 833 | if (getNextRecord().isMotion()) { // try not to output feed without motion 834 | feedOutput.reset(); // force feed on next line 835 | } else { 836 | writeBlock(gMotionModal.format(1), f); 837 | } 838 | } 839 | } 840 | 841 | function onRapid5D(_x, _y, _z, _a, _b, _c) { 842 | if (!currentSection.isOptimizedForMachine()) { 843 | error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); 844 | return; 845 | } 846 | if (pendingRadiusCompensation >= 0) { 847 | error(localize("Radius compensation mode cannot be changed at rapid traversal.")); 848 | return; 849 | } 850 | var x = xOutput.format(_x); 851 | var y = yOutput.format(_y); 852 | var z = zOutput.format(_z); 853 | var a = aOutput.format(_a); 854 | var b = bOutput.format(_b); 855 | var c = cOutput.format(_c); 856 | writeBlock(gMotionModal.format(0), x, y, z, a, b, c); 857 | feedOutput.reset(); 858 | } 859 | 860 | function onLinear5D(_x, _y, _z, _a, _b, _c, feed) { 861 | if (!currentSection.isOptimizedForMachine()) { 862 | error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath.")); 863 | return; 864 | } 865 | if (pendingRadiusCompensation >= 0) { 866 | error(localize("Radius compensation cannot be activated/deactivated for 5-axis move.")); 867 | return; 868 | } 869 | var x = xOutput.format(_x); 870 | var y = yOutput.format(_y); 871 | var z = zOutput.format(_z); 872 | var a = aOutput.format(_a); 873 | var b = bOutput.format(_b); 874 | var c = cOutput.format(_c); 875 | var f = feedOutput.format(feed); 876 | if (x || y || z || a || b || c) { 877 | writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f); 878 | } else if (f) { 879 | if (getNextRecord().isMotion()) { // try not to output feed without motion 880 | feedOutput.reset(); // force feed on next line 881 | } else { 882 | writeBlock(gMotionModal.format(1), f); 883 | } 884 | } 885 | } 886 | 887 | /** Adjust final point to lie exactly on circle. */ 888 | function CircularData(_plane, _center, _end) { 889 | // use Output variables, since last point could have been adjusted if previous move was circular 890 | var start = new Vector(xOutput.getCurrent(), yOutput.getCurrent(), zOutput.getCurrent()); 891 | var saveStart = new Vector(start.x, start.y, start.z); 892 | var center = new Vector( 893 | xyzFormat.getResultingValue(_center.x), 894 | xyzFormat.getResultingValue(_center.y), 895 | xyzFormat.getResultingValue(_center.z) 896 | ); 897 | var end = new Vector(_end.x, _end.y, _end.z); 898 | switch (_plane) { 899 | case PLANE_XY: 900 | start.setZ(center.z); 901 | end.setZ(center.z); 902 | break; 903 | case PLANE_ZX: 904 | start.setY(center.y); 905 | end.setY(center.y); 906 | break; 907 | case PLANE_YZ: 908 | start.setX(center.x); 909 | end.setX(center.x); 910 | break; 911 | default: 912 | this.center = new Vector(_center.x, _center.y, _center.z); 913 | this.start = new Vector(start.x, start.y, start.z); 914 | this.end = new Vector(_end.x, _end.y, _end.z); 915 | this.offset = Vector.diff(center, start); 916 | this.radius = this.offset.length; 917 | break; 918 | } 919 | this.start = new Vector( 920 | xyzFormat.getResultingValue(start.x), 921 | xyzFormat.getResultingValue(start.y), 922 | xyzFormat.getResultingValue(start.z) 923 | ); 924 | var temp = Vector.diff(center, start); 925 | this.offset = new Vector( 926 | xyzFormat.getResultingValue(temp.x), 927 | xyzFormat.getResultingValue(temp.y), 928 | xyzFormat.getResultingValue(temp.z) 929 | ); 930 | this.center = Vector.sum(this.start, this.offset); 931 | this.radius = this.offset.length; 932 | 933 | temp = Vector.diff(end, center).normalized; 934 | this.end = new Vector( 935 | xyzFormat.getResultingValue(this.center.x + temp.x * this.radius), 936 | xyzFormat.getResultingValue(this.center.y + temp.y * this.radius), 937 | xyzFormat.getResultingValue(this.center.z + temp.z * this.radius) 938 | ); 939 | 940 | switch (_plane) { 941 | case PLANE_XY: 942 | this.start.setZ(saveStart.z); 943 | this.end.setZ(_end.z); 944 | this.offset.setZ(0); 945 | break; 946 | case PLANE_ZX: 947 | this.start.setY(saveStart.y); 948 | this.end.setY(_end.y); 949 | this.offset.setY(0); 950 | break; 951 | case PLANE_YZ: 952 | this.start.setX(saveStart.x); 953 | this.end.setX(_end.x); 954 | this.offset.setX(0); 955 | break; 956 | } 957 | } 958 | 959 | function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { 960 | // use G6/G7 for helices 961 | 962 | if (isSpiral()) { 963 | linearize(tolerance); 964 | return; 965 | } 966 | if (isHelical()) { 967 | var t = tolerance; 968 | if (hasParameter("operation:tolerance")) { 969 | t = getParameter("operation:tolerance"); 970 | } 971 | linearize(t); 972 | return; 973 | } 974 | 975 | if (pendingRadiusCompensation >= 0) { 976 | error(localize("Radius compensation cannot be activated/deactivated for a circular move.")); 977 | return; 978 | } 979 | 980 | var circle = new CircularData(getCircularPlane(), new Vector(cx, cy, cz), new Vector(x, y, z)); 981 | 982 | if (isFullCircle()) { 983 | if (isHelical()) { // radius mode does not support full arcs 984 | var t = tolerance; 985 | if (hasParameter("operation:tolerance")) { 986 | t = getParameter("operation:tolerance"); 987 | } 988 | linearize(t); 989 | return; 990 | } 991 | switch (getCircularPlane()) { 992 | case PLANE_XY: 993 | writeBlock( 994 | gAbsIncModal.format(90), gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), 995 | iOutput.format(circle.offset.x, 0), jOutput.format(circle.offset.y, 0), feedOutput.format(feed) 996 | ); 997 | break; 998 | case PLANE_ZX: 999 | writeBlock( 1000 | gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), 1001 | iOutput.format(circle.offset.x, 0), kOutput.format(circle.offset.z, 0), feedOutput.format(feed) 1002 | ); 1003 | break; 1004 | case PLANE_YZ: 1005 | writeBlock( 1006 | gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), 1007 | jOutput.format(circle.offset.y, 0), kOutput.format(circle.offset.z, 0), feedOutput.format(feed) 1008 | ); 1009 | break; 1010 | default: 1011 | var t = tolerance; 1012 | if (hasParameter("operation:tolerance")) { 1013 | t = getParameter("operation:tolerance"); 1014 | } 1015 | linearize(t); 1016 | } 1017 | } else { 1018 | switch (getCircularPlane()) { 1019 | case PLANE_XY: 1020 | writeBlock( 1021 | gAbsIncModal.format(90), gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), 1022 | xOutput.format(circle.end.x), yOutput.format(circle.end.y), zOutput.format(circle.end.z), 1023 | iOutput.format(circle.offset.x, 0), jOutput.format(circle.offset.y, 0), feedOutput.format(feed) 1024 | ); 1025 | break; 1026 | case PLANE_ZX: 1027 | writeBlock( 1028 | gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), 1029 | xOutput.format(circle.end.x), yOutput.format(circle.end.y), zOutput.format(circle.end.z), 1030 | iOutput.format(circle.offset.x, 0), kOutput.format(circle.offset.z, 0), feedOutput.format(feed) 1031 | ); 1032 | break; 1033 | case PLANE_YZ: 1034 | writeBlock( 1035 | gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), 1036 | xOutput.format(circle.end.x), yOutput.format(circle.end.y), zOutput.format(circle.end.z), 1037 | jOutput.format(circle.offset.y, 0), kOutput.format(circle.offset.z, 0), feedOutput.format(feed) 1038 | ); 1039 | break; 1040 | default: 1041 | var t = tolerance; 1042 | if (hasParameter("operation:tolerance")) { 1043 | t = getParameter("operation:tolerance"); 1044 | } 1045 | linearize(t); 1046 | } 1047 | } 1048 | } 1049 | 1050 | var currentCoolantMode = undefined; 1051 | var coolantOff = undefined; 1052 | 1053 | function setCoolant(coolant) { 1054 | var coolantCodes = getCoolantCodes(coolant); 1055 | if (Array.isArray(coolantCodes)) { 1056 | for (var c in coolantCodes) { 1057 | writeBlock(coolantCodes[c]); 1058 | } 1059 | return undefined; 1060 | } 1061 | return coolantCodes; 1062 | } 1063 | 1064 | function getCoolantCodes(coolant) { 1065 | if (!coolants) { 1066 | error(localize("Coolants have not been defined.")); 1067 | } 1068 | if (!coolantOff) { // use the default coolant off command when an 'off' value is not specified for the previous coolant mode 1069 | coolantOff = coolants.off; 1070 | } 1071 | 1072 | if (isProbeOperation()) { // avoid coolant output for probing 1073 | coolant = COOLANT_OFF; 1074 | } 1075 | 1076 | if (coolant == currentCoolantMode) { 1077 | return undefined; // coolant is already active 1078 | } 1079 | 1080 | var multipleCoolantBlocks = new Array(); // create a formatted array to be passed into the outputted line 1081 | if ((coolant != COOLANT_OFF) && (currentCoolantMode != COOLANT_OFF)) { 1082 | multipleCoolantBlocks.push(mFormat.format(coolantOff)); 1083 | } 1084 | 1085 | var m; 1086 | if (coolant == COOLANT_OFF) { 1087 | m = coolantOff; 1088 | coolantOff = coolants.off; 1089 | } 1090 | 1091 | switch (coolant) { 1092 | case COOLANT_FLOOD: 1093 | if (!coolants.flood) { 1094 | break; 1095 | } 1096 | m = coolants.flood.on; 1097 | coolantOff = coolants.flood.off; 1098 | break; 1099 | case COOLANT_THROUGH_TOOL: 1100 | if (!coolants.throughTool) { 1101 | break; 1102 | } 1103 | m = coolants.throughTool.on; 1104 | coolantOff = coolants.throughTool.off; 1105 | break; 1106 | case COOLANT_AIR: 1107 | if (!coolants.air) { 1108 | break; 1109 | } 1110 | m = coolants.air.on; 1111 | coolantOff = coolants.air.off; 1112 | break; 1113 | case COOLANT_AIR_THROUGH_TOOL: 1114 | if (!coolants.airThroughTool) { 1115 | break; 1116 | } 1117 | m = coolants.airThroughTool.on; 1118 | coolantOff = coolants.airThroughTool.off; 1119 | break; 1120 | case COOLANT_FLOOD_MIST: 1121 | if (!coolants.floodMist) { 1122 | break; 1123 | } 1124 | m = coolants.floodMist.on; 1125 | coolantOff = coolants.floodMist.off; 1126 | break; 1127 | case COOLANT_MIST: 1128 | if (!coolants.mist) { 1129 | break; 1130 | } 1131 | m = coolants.mist.on; 1132 | coolantOff = coolants.mist.off; 1133 | break; 1134 | case COOLANT_SUCTION: 1135 | if (!coolants.suction) { 1136 | break; 1137 | } 1138 | m = coolants.suction.on; 1139 | coolantOff = coolants.suction.off; 1140 | break; 1141 | case COOLANT_FLOOD_THROUGH_TOOL: 1142 | if (!coolants.floodThroughTool) { 1143 | break; 1144 | } 1145 | m = coolants.floodThroughTool.on; 1146 | coolantOff = coolants.floodThroughTool.off; 1147 | break; 1148 | } 1149 | 1150 | if (!m) { 1151 | onUnsupportedCoolant(coolant); 1152 | m = 9; 1153 | } 1154 | 1155 | if (m) { 1156 | if (Array.isArray(m)) { 1157 | for (var i in m) { 1158 | multipleCoolantBlocks.push(mFormat.format(m[i])); 1159 | } 1160 | } else { 1161 | multipleCoolantBlocks.push(mFormat.format(m)); 1162 | } 1163 | currentCoolantMode = coolant; 1164 | return multipleCoolantBlocks; // return the single formatted coolant value 1165 | } 1166 | return undefined; 1167 | } 1168 | 1169 | var mapCommand = { 1170 | COMMAND_STOP: 0, 1171 | COMMAND_OPTIONAL_STOP: 1, 1172 | COMMAND_END: 2, 1173 | COMMAND_SPINDLE_CLOCKWISE: 3, 1174 | COMMAND_SPINDLE_COUNTERCLOCKWISE: 4, 1175 | COMMAND_STOP_SPINDLE: 5, 1176 | COMMAND_LOAD_TOOL: 6 1177 | }; 1178 | 1179 | function onCommand(command) { 1180 | switch (command) { 1181 | case COMMAND_START_SPINDLE: 1182 | onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE); 1183 | return; 1184 | case COMMAND_LOCK_MULTI_AXIS: 1185 | return; 1186 | case COMMAND_UNLOCK_MULTI_AXIS: 1187 | return; 1188 | case COMMAND_BREAK_CONTROL: 1189 | return; 1190 | case COMMAND_TOOL_MEASURE: 1191 | return; 1192 | } 1193 | 1194 | var stringId = getCommandStringId(command); 1195 | var mcode = mapCommand[stringId]; 1196 | if (mcode != undefined) { 1197 | writeBlock(mFormat.format(mcode)); 1198 | } else { 1199 | onUnsupportedCommand(command); 1200 | } 1201 | } 1202 | 1203 | function onSectionEnd() { 1204 | writeBlock(gPlaneModal.format(17)); 1205 | 1206 | if (((getCurrentSectionId() + 1) >= getNumberOfSections()) || 1207 | (tool.number != getNextSection().getTool().number)) { 1208 | onCommand(COMMAND_BREAK_CONTROL); 1209 | } 1210 | 1211 | forceAny(); 1212 | } 1213 | 1214 | function onClose() { 1215 | setCoolant(COOLANT_OFF); 1216 | 1217 | setWorkPlane(new Vector(0, 0, 0)); // reset working plane 1218 | 1219 | onImpliedCommand(COMMAND_END); 1220 | onImpliedCommand(COMMAND_STOP_SPINDLE); 1221 | writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off 1222 | writeln("%"); 1223 | } 1224 | --------------------------------------------------------------------------------