Community
HSM Post Processor Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Machining Time, Document Name, Stock Information in NC program

4 REPLIES 4
Reply
Message 1 of 5
boopathi.sivakumar
520 Views, 4 Replies

Machining Time, Document Name, Stock Information in NC program

Hi 
Since I have seen some common requests on how to add machning time, document name, stock information, user name and nc generated time in the NC programs, So I have came up with this thread and a common places which answers this question.

var infoSettings = {
  toolChangeTime : 15,         // Default tool change time in seconds.
  rapidFeedRate  : 10000,      // Default Machine rapid feedrate in mm/min.
  durationFormat : "HH:MM:SS", // Supported Formats are "HH:MM:SS", "MM:SS" and "SS".
  dateFormat     : "LOCAL_DATE_TIME", // Supported Formats are "GMT", "LOCAL", "LOCAL_DATE_TIME"
  formatSeperator: ": ",       // Use this to seperate words.
  stockMode      : "MILLING",  // Outputs the stock information supported formats are "MILLING", "TURNING" and "CUTTING"
  headerInfo     : {           // writes the header information by calling writeHeaderInfos() function, following are the supported information. set false to not output the Information.
    documentName   : true,
    programmerName : true,
    ncGeneratedTime: true,
    stockInfo      : true,
    machiningTime  : true
  }
};

function writeHeaderInfo() {
  var headerInfo = infoSettings.headerInfo;
  if (headerInfo.documentName) {
    writeComment("Document Name     " + sep + getDocumentName());
  }
  if (headerInfo.programmerName) {
    writeComment("Programmer Name   " + sep + getUserName());
  }
  if (headerInfo.ncGeneratedTime) {
    writeComment("Generated At      " + sep + getNCGeneratedTime());
  }
  if (headerInfo.stockInfo) {
    writeComment("Stock Information " + sep + getStockInformation());
  }
  if (headerInfo.machiningTime) {
    writeComment("Machning Time     " + sep + getMachiningTime());
  }
}

function getMachiningTime() {
  var rapidDistance = 0;
  var cycleTime = infoSettings.toolChangeTime;
  var numberOfSections = getNumberOfSections();
  for (var i = 0; i < numberOfSections; ++i) {
    var section = getSection(i);
    cycleTime += section.getCycleTime();
    rapidDistance += (unit == MM ? section.getRapidDistance() : 25.4 * section.getRapidDistance());

    if (i != 0 && isToolChangeNeeded(section, "number")) {
      cycleTime += infoSettings.toolChangeTime;
    }
  }
  if (infoSettings.rapidFeedRate > 0) {
    cycleTime += rapidDistance / infoSettings.rapidFeedRate * 60;
  }
  return (convertToTimeFormat(cycleTime));

}

function convertToTimeFormat(cycleTime) {
  var format = infoSettings.durationFormat.split(":")[0];
  var hours, minutes, result, seconds;

  if (format == "HH" || format == "MM") {
    hours = Math.floor(cycleTime / 3600);
    cycleTime -= (format == "HH") ? hours * 3600 : 0;

    minutes = Math.floor(cycleTime / 60);
    cycleTime -= minutes * 60;
  }

  seconds = cycleTime.toFixed(1);

  if (format == "HH") {
    result = hours + "Hrs " + minutes + "Min " + seconds + "Sec";
  } else if (format == "MM") {
    result = minutes + "Min " + seconds + "Sec";
  } else {
    result = seconds + "Sec";
  }

  return result;
}

function getDocumentName() {
  return getGlobalParameter("document-path", "");
}

function getUserName() {
  return getGlobalParameter("username", "");
}

function getNCGeneratedTime() {
  var date = new Date(getGlobalParameter("generated-at", ""));
  if (infoSettings.dateFormat == "GMT") {
    return date.toUTCString();
  } else if (infoSettings.dateFormat == "LOCAL_DATE_TIME") {
    return (date.toLocaleDateString() + "-" + date.toLocaleTimeString());
  } else {
    return date.toLocaleString();
  }
}

function getStockInformation() {
  var format = createFormat({decimals:(unit == MM ? 2 : 3)});
  var workpiece = getWorkpiece();
  var delta = Vector.diff(workpiece.upper, workpiece.lower);
  var unit_ = unit == MM ? "MM" : "IN";
  var len = format.format(delta.x) + unit_;
  var wid = format.format(delta.y) + unit_;
  var height = format.format(delta.z) + unit_;
  if (infoSettings.stockMode == "TURNING") {
    var dia = format.format(Math.max(delta.x, delta.y)) + unit_;
    return ("Diameter=" + dia + " Length=" + height);
  } else {
    return ("Length=" + len + " Width=" + wid + (infoSettings.stockMode == "MILLING" ? " Height=" : " Thickness=") + height);
  }
}

var sep = infoSettings.formatSeperator;
if (typeof settings != "undefined" && settings.comments.permittedCommentChars) {
  settings.comments.permittedCommentChars += infoSettings.formatSeperator; // add addtional comment chars
}
if (typeof permittedCommentChars != "undefined") {
  permittedCommentChars += infoSettings.formatSeperator;
}

 

All you can do is copy the above section of code and paste in at the end of your post processor file (.cps) 
and call the writeHeaderInfos(); function wherever it is needed


Example on the fanuc post 
Image 11-12-23 at 11.28 AM.jpeg

I have added in the onOpen section 

This should output the corresponding heder info in the top of the nc program!

also in the copied section of code the you can use infoSetting object variables to granually control how this needed to be outputed 

var infoSettings = {
  toolChangeTime : 15,         // Default tool change time in seconds.
  rapidFeedRate  : 10000,      // Default Machine rapid feedrate in mm/min.
  durationFormat : "HH:MM:SS", // Supported Formats are "HH:MM:SS", "MM:SS" and "SS".
  dateFormat     : "LOCAL_DATE_TIME", // Supported Formats are "GMT", "LOCAL", "LOCAL_DATE_TIME"
  formatSeperator: ": ",       // Use this to seperate words.
  stockMode      : "MILLING",  // Outputs the stock information supported formats are "MILLING", "TURNING" and "CUTTING"
  headerInfo     : {           // writes the header information by calling writeHeaderInfos() function, following are the supported information. set false to not output the Information.
    documentName   : true,
    programmerName : true,
    ncGeneratedTime: true,
    stockInfo      : true,
    machiningTime  : true
  }
};

For example you can control the duration of tool Change time so that you get more accurate machining time,
and maximum rapid feedrate of the machine. and in the duration format you can control how do you want to output the machining time for instance.

 

here is the short video of how you can make edits to the posts to get this done

 

Feel free to post in the thread if you feel any other options are missing


Boopathi Sivakumar
Senior Technology Consultant

4 REPLIES 4
Message 2 of 5

All good stuff@boopathi.sivakumar 

 

Are there any plans to update the post processor engine to be able to pull the actual Fusion 360 user name instead of the Windows user name? Currently the example above will always return the Windows Login user name, not the actual Fusion Login user name. In an environment where there are shared computers on the shop floor, this would be really helpful.

Message 3 of 5

Hi @ktorokU233T 

Thanks for the feedback I will make a ticket 


Boopathi Sivakumar
Senior Technology Consultant

Message 4 of 5

Hi! Is it also possible to post the machining time for every tool? I need that for our robot cells toolmanagementsystem. I need something like this: 

j_zander_0-1705330552907.png

 

 

Message 5 of 5

Excellent work. Thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report