/** Copyright (C) 2012-2025 by Autodesk, Inc. All rights reserved. $Revision: 45583 10f6400eaf1c75a27c852ee82b57479e7a9134c0 $ $Date: 2025-08-21 13:23:15 $ FORKID {B9E0E4D8-D548-421b-8F97-CCACF8B1F09F} */ description = "XML Cutter Location Data"; vendor = "Autodesk"; vendorUrl = "http://www.autodesk.com"; legal = "Copyright (C) 2012-2025 by Autodesk, Inc."; certificationLevel = 2; longDescription = "Example post illustrating how to convert the toolpath into XML."; capabilities = CAPABILITY_INTERMEDIATE; extension = "xml"; setCodePage("utf-8"); allowHelicalMoves = true; allowedCircularPlanes = undefined; // allow any circular motion properties = { useTimeStamp: { title : "Time stamp", description: "Specifies whether to output a time stamp.", group : "preferences", type : "boolean", value : false, scope : "post" }, highAccuracy: { title : "High accuracy", description: "Specifies short (no) or long (yes) numeric format.", group : "preferences", type : "boolean", value : true, scope : "post" } }; var mainFormat = createFormat({decimals:6, forceDecimal:false}); var ijkFormat = createFormat({decimals:9, forceDecimal:false}); var feedOutput = createVariable({format:mainFormat}); var mapRCTable = new Table( [" compensation='off'", " compensation='left'", "", " compensation='right'"], {initial:RADIUS_COMPENSATION_OFF}, "Invalid radius compensation" ); function toPos(x, y, z) { return mainFormat.format(x) + " " + mainFormat.format(y) + " " + mainFormat.format(z); } function toVec(x, y, z) { return ijkFormat.format(x) + " " + ijkFormat.format(y) + " " + ijkFormat.format(z); } function toFeed(feed) { var f = feedOutput.format(feed); return f ? (" feed='" + f + "'") : ""; } function toRC(radiusCompensation) { return mapRCTable.lookup(radiusCompensation); /* switch (radiusCompensation) { case RADIUS_COMPENSATION_OFF: return " compensation='off'"; case RADIUS_COMPENSATION_LEFT: return " compensation='left'"; case RADIUS_COMPENSATION_RIGHT: return " compensation='right'"; } return ""; */ } function escapeChar(c) { switch (c) { case "<": return "<"; case ">": return ">"; case "&": return "&"; case "'": return "'"; case "\"": return """; } return c; // should never happen } function escapeXML(unescaped) { return unescaped.replace(/[<>&'"]/g, escapeChar); } function makeValue(value) { if (typeof value == "string") { return escapeXML(value); // we use type attribute to tell that it is a string } else { return mainFormat.format(value); // integer/float - no need to escape } } function onOpen() { writeln(""); writeln(""); writeln(""); if (getProperty("useTimeStamp")) { var d = new Date(); writeln(""); } if (!getProperty("highAccuracy")) { mainFormat = createFormat({decimals:4, forceDecimal:true}); ijkFormat = createFormat({decimals:7, forceDecimal:true}); feedOutput = createVariable({format:mainFormat}); } } function onComment(text) { writeln("" + escapeXML(text) + ""); } function attr(name, value) { return name + "='" + value + "'"; } function onSection() { var u = (unit == IN) ? "inches" : "millimeters"; var o = toPos(currentSection.workOrigin.x, currentSection.workOrigin.y, currentSection.workOrigin.z); var p = []; for (var i = 0; i < 9; ++i) { p.push(currentSection.workPlane.getElement(i / 3, i % 3)); } writeln(""); var type = "unspecified"; // TAG: fixme var n = tool.number; var d = mainFormat.format(tool.diameter); var cr = mainFormat.format(tool.cornerRadius); var ta = mainFormat.format(tool.taperAngle); var fl = mainFormat.format(tool.fluteLength); var sl = mainFormat.format(tool.shoulderLength); var sd = mainFormat.format(tool.shaftDiameter); var bl = mainFormat.format(tool.bodyLength); var tp = mainFormat.format(tool.threadPitch); var _do = mainFormat.format(tool.diameterOffset); var lo = mainFormat.format(tool.lengthOffset); var sr = mainFormat.format(tool.spindleRPM); var COOLANT_NAMES = ["disabled", "flood", "mist", "tool", "air", "air through tool"]; var coolant = COOLANT_NAMES[tool.coolant]; writeln(""); var holder = tool.holder; if (holder) { writeln(""); for (var i = 0; i < holder.getNumberOfSections(); ++i) { var d = mainFormat.format(holder.getDiameter(i)); var l = mainFormat.format(holder.getLength(i)); writeln("
"); } writeln(""); } writeln(""); writeln("
"); feedOutput.reset(); } function onParameter(name, value) { var type = "float"; if (typeof value == "string") { type = "string"; } else if ((value % 1) == 0) { type = "integer"; } writeln(""); } function onDwell(seconds) { writeln(""); } function onCycle() { writeln(""); for (var name in cycle) { var value = cycle[name]; var type = "float"; if (typeof value == "string") { type = "string"; } else if ((value % 1) == 0) { type = "integer"; } writeln(""); } } function onCyclePoint(x, y, z) { writeln(""); } function onCycleEnd() { writeln(""); } function onRapid(x, y, z) { writeln(""); feedOutput.reset(); } function onLinear(x, y, z, feed) { writeln(""); } function onRapid5D(x, y, z, dx, dy, dz) { writeln(""); previousFeed = undefined; } function onLinear5D(x, y, z, dx, dy, dz, feed) { writeln(""); } function onCircular(clockwise, cx, cy, cz, x, y, z, feed) { var n = getCircularNormal(); var block = ""; var big = getCircularSweep() > Math.PI; if (big) { block += "circular"; } else { block += isClockwise() ? "arc-cw" : "arc-ccw"; } block += " to='" + toPos(x, y, z) + "'"; block += " center='" + toPos(cx, cy, cz) + "'"; if ((n.x != 0) || (n.y != 0) || (n.z != 1)) { block += " normal='" + toVec(n.x, n.y, n.z) + "'"; } if (big) { block += " sweep='" + mainFormat.format(getCircularSweep()) + "'"; } block += toFeed(feed); block += toRC(radiusCompensation); writeln("<" + block + "/>"); } function onCommand() { writeln(""); } function onSectionEnd() { writeln("
"); } function onClose() { writeln(""); } function setProperty(property, value) { properties[property].current = value; }