Tool List Display Three Character Offset Numbers

DCDForeman
Contributor

Tool List Display Three Character Offset Numbers

DCDForeman
Contributor
Contributor

Hello,

 

I'm attempting to get my tool list to display the tool number with offsets. I have partially succeeded, but I can only display two of the three offset numbers. I'm using a Doosan SMX2100ST mill-turn with a post that has been slightly modified for my needs. 

 

This is what I'm outputting now:

(T0101 - UPPER CNMG 432-PM 4425)
(T1099 - 1.0" INDXBL MILL R.122" - TOOL GRP 10)
(T1299 - 2.5" INDXBL MILL R.122" W/EXT - TOOL GRP 12)
(T5151 - 1/2" .030R 7FLT ENDMILL)
 
This is what I would like:
(T01001 - UPPER CNMG 432-PM 4425)
(T10999 - 1.0" INDXBL MILL R.122" - TOOL GRP 10)
(T12999 - 2.5" INDXBL MILL R.122" W/EXT - TOOL GRP 12)
(T51051 - 1/2" .030R 7FLT ENDMILL)

 

Below is the code from my post. I have tools that use the same tool number, and different offsets, so it's not quite typical:

 

if (properties.writeTools) {
    var tools = [];
    var numberOfSections = getNumberOfSections();
    for (var i = 0; i < numberOfSections; ++i) {
      var section = getSection(i);
      var tool = section.getTool();
      var isDuplicate = false;
      for (var j = 0; j < tools.length; ++j) {
        if (tools[j].number == tool.number && tools[j].compensationOffset == tool.compensationOffset) {
          isDuplicate = true;
        }
      }
      if (!isDuplicate) {
        tools.push(tool);
      }
    }

    var zRanges = {};
    if (is3D()) {
      var numberOfSections = getNumberOfSections();
      for (var i = 0; i < numberOfSections; ++i) {
        var section = getSection(i);
        var zRange = section.getGlobalZRange();
        var tool = section.getTool();
        if (zRanges[tool.number + compensationOffset]) {
          zRanges[tool.number + compensationOffset].expandToRange(zRange);
        } else {
          zRanges[tool.number + compensationOffset] = zRange;
        }
      }
    }

    for (var i = 0; i < tools.length; ++i) {
      var tool = tools[i];
      var compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset;
      var comment = "T" + toolFormat.format(tool.number * 100 + compensationOffset % 100) + " - " + tool.description;
      writeComment(comment);
    }
  }
 
Thank you in advance!
0 Likes
Reply
Accepted solutions (1)
341 Views
4 Replies
Replies (4)

aju_augustine
Autodesk
Autodesk

Hi @DCDForeman ,

 

Please try modifying your code as below, it should resolve the issue:

 

    for (var i = 0; i < tools.length; ++i) {
      var tool = tools[i];
      var compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset;

      // New variable to handle compensationOffset condition
      var formattedCompensationOffset = compensationOffset < 100 ? '0' + compensationOffset.toString() : compensationOffset.toString();

      var comment = "T" + tool.number.toString() + formattedCompensationOffset + " - " + tool.description;
      writeComment(comment);
    }

 

In this code, we're adding a new variable formattedCompensationOffset to handle the condition for compensationOffset. If compensationOffset is less than 100, a '0' is added in prefix to it. Otherwise, it is output as it is.

Hope this helps.



Aju Augustine
Technology Consultant
0 Likes

DCDForeman
Contributor
Contributor

Hi @aju_augustine ,

 

Thanks for your quick response! This is so close to being perfect for me! The tool list works perfectly for any 2 digit tool number, but with single digit tool numbers, and single digit offsets is it possible to add a preceding 0?

 

(T101 - UPPER CNMG 432-PM 4425)
(T3999 - UPPER DNMG 432-PM 4425)
(T10999 - 1.0" INDXBL MILL R.122" - TOOL GRP 10)
(T19019 - 0.6496"/16.5MM INDEXABLE CARBIDE DRILL)
0 Likes

aju_augustine
Autodesk
Autodesk
Accepted solution

Hi @DCDForeman ,

 

Assuming that you have tools less that hundred I have modifed the tool number format by limiting to 2 digits, and for the compensationoffset I have added its format by limiting to 3 digits, as shown in screenshot below:

 

5.png

 

Then change the codes in the post as shown below:

    for (var i = 0; i < tools.length; ++i) {
      var tool = tools[i];
      var compensationOffset = tool.isTurningTool() ? tool.compensationOffset : tool.lengthOffset;
      var comment = "T" + toolFormat.format(tool.number) + lengthCompensationFormat.format(compensationOffset) + " - " + tool.description;
      writeComment(comment);
    }

 

It should work as shown below:

 

6.png

 



Aju Augustine
Technology Consultant
0 Likes

DCDForeman
Contributor
Contributor

Hi @aju_augustine 

 

Thank you for this, It is exactly what I hoped for! 

0 Likes