Machining Time, Document Name, Stock Information in NC program

Machining Time, Document Name, Stock Information in NC program

boopathi.sivakumar
Autodesk Autodesk
2,379 Views
12 Replies
Message 1 of 13

Machining Time, Document Name, Stock Information in NC program

boopathi.sivakumar
Autodesk
Autodesk

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,
    programmerEmail: false,
    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.programmerEmail) {
    writeComment("Programmer Email  " + sep + getUserEmail());
  }
  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("display-name", "");
}

function getUserEmail() {
  return getGlobalParameter("user-email", "");
}

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,
    programmerEmail: false,
    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
Principal Technology Consultant

2,380 Views
12 Replies
Replies (12)
Message 2 of 13

ktorokU233T
Advocate
Advocate

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 13

boopathi.sivakumar
Autodesk
Autodesk

Hi @ktorokU233T 

Thanks for the feedback I will make a ticket 


Boopathi Sivakumar
Principal Technology Consultant

0 Likes
Message 4 of 13

j_zander
Contributor
Contributor

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

 

 

0 Likes
Message 5 of 13

mlindleyHW8VL
Community Visitor
Community Visitor

Excellent work. Thank you

0 Likes
Message 6 of 13

jrmitchellj
Participant
Participant

I am working on a MacBook Pro M4 computer, with OS26.

Is there a Mac centric version of the Post Processor Training Guide?

 

 

0 Likes
Message 7 of 13

boopathi.sivakumar
Autodesk
Autodesk

Hi @jrmitchellj 
The fusion post processor utility is same for mac as well so pretty much everything is same! apart from couple of things
one is the post executable path for mac will be different You can refer this Thread 
if you making a custom .cnc file you have to manually import the cnc file. for windows we do automatically import the custom cnc files but for mac you have to right click on the folder and import cnc file https://cam.autodesk.com/posts/posts/guides/Post%20Processor%20Training%20Guide.pdf#page=54

 


Boopathi Sivakumar
Principal Technology Consultant

0 Likes
Message 8 of 13

jrmitchellj
Participant
Participant

Thank you for the links.  That helped!

It is working now, but the username is not correct. (see attached photos)

You can see line 13 the username is ROOT)  instead of my login.

I also included a snapshot of the code that generates the username.

 

Thank you for your help!

 

Ray

0 Likes
Message 9 of 13

boopathi.sivakumar
Autodesk
Autodesk

Hi @jrmitchellj 
Currently the user name is your pc host name not the fusion user id. this is something we will be addressing shortly in the coming release of fusion


Boopathi Sivakumar
Principal Technology Consultant

0 Likes
Message 10 of 13

jrmitchellj
Participant
Participant

I expected it to be my login on my computer, and I am not logged in as ROOT!

I look forward to the fix.

A more permanent solution would be to add it to the post processor, where they could be enabled/disabled with check marks in the format section.  (see attached screenshot)  jsut below the "Write tools" checkmark.

0 Likes
Message 11 of 13

boopathi.sivakumar
Autodesk
Autodesk

Hello everyone! 
With the latest update with Fusion Jan release in addition to existing parameter now the full name of the logged in user has been exposed. also we have also exposed the user logged in email and the unique Autodesk Id has been exposed to use it in the post processing.

To get the Full User name one can get using the following code sinppet

getGlobalParameter("display-name", "")

 

 2 . To get user email 

getGlobalParameter("user-email", "")

 

3. To get the unique Autodesk user id.

getGlobalParameter("user-id", "")

 

I have also updated the above code snippet. Hope it helps for user who has looking for it.

 


Boopathi Sivakumar
Principal Technology Consultant

Message 12 of 13

jrmitchellj
Participant
Participant
Does that mean you updated the code in the first entry in this chain?

0 Likes
Message 13 of 13

ktorokU233T
Advocate
Advocate

Thanks for the update @boopathi.sivakumar 

Worked like a charm.

0 Likes