JS Macro programming principles

Top | Previous | Next

 

The JS Macro description is a short program written in JavaScript syntax. The program is created in a special editor provided in the JS Macro build command. The program is interpreted after a recess cut has been performed on a furniture component and a recess processing operation has been created. The interpretation is triggered in two cases:

 

1.The program is traced to debug its operation. See here for information on how a program can be traced.

2.The Post-Processor generates the final program of the CNC technology developed.

 

Inside the JS Macro, the program can manipulate an auxiliary Macro object which carries all the parameters needed to successfully generate a fragment of the CNC program.

 

Factors that can be interpreted to form the program fragment:

 

1.The position of the piece of furniture hardware itself in the cut part, and, at the same time, the position of the Macro origin of the coordinate system on the part.

2.The parameters exported by the furniture fixture component. For example, the fixture component has a length parameter. The value of this parameter can be used to form the Front-End Macro body.

3.Various parameters for a part that has already been affected by a Sculpt operation with a given sculpt body. For example, the length, width and thickness of the workpiece to be cut, the value of oversize, etc. can be read.

 

Let’s say that a JS Macro program needs to generate text to be output in a CNC program. In order for the Post-Processor to interpret such a JavaScript program and include the result, the program must have a Result function whose result must be text. For example:

 

export function Result()

{

var result

 

result='This is the text that the post-processor \r\n'

result+='will output to the final CNC program. '

 

return result

}

 

 

The following text will be placed in the output CNC program:

 

This is the text that the post-processor

will output to the final CNC program.

 

 

Now let’s give an example of a JS Macro program that is adapted to generate a recess processing for a knob with a mill as shown in the example below:

 

 

Processing operation of the handle

Processing operation of the handle

Woodwop parameters of the vertical pocket

Woodwop parameters of the vertical pocket

 

 

For the processing operation, we will use Woodwop's Trimming Pocket Vertical function. The call of this function in the Woodwop MPR format consists of the following description:

 

<112 \Tasche\

XA="0"

YA="0"

LA="120"

BR="20"

RD="5"

WI="0"

TI="2"

ZT="0"

XY="80"

DS=“1“

T_="101"

F_="STANDARD"

Explanation:

XA : Center coordinate in X

YA : Center coordinate in Y

LA : Length (dimension in X)

BR : Width (dimension in Y)

RD : Edges radius

WI : Turn angle

TI : Depth

ZA : Z-Reference value for the depth

ZT : Deliver depth

XY : Delivering in XY-level

T_ : Tool number

F_ : Feedrate: contains either the concrete value in m/min or the key word STANDARD.

By STANDARD the Feedrate of the Tooldatas will be used (default).

DS : Turning direction: 0 = clockwise, 1= counter clockwise

KO : Coordinate system

?? : Condition (default=1)

EN : Enable (default=1)

 

 

It is not convenient to generate all the text of the CNC program in one go, so we will increment each line of text using the variable “result”. For each instance of the knob that is cut during the design process, there is a call to the Trimming Pocket Vertical function with different parameters, i.e. different insertion co-ordinates and a different rotation angle. It is therefore necessary to feed the correct coordinates and other parameters into the text to be generated. These parameters are extracted using the properties of the Macro.Origin object. Each JS Macro has a Macro object automatically populated with all the parameters of a particular Macro operation at the time of interpretation. These values can be used to generate the final CNC code fragment. The text of the function output from the example below could look like this:

 

export function Result()
{
 
var result
 
result='<112 \\Tasche\\\r\n'
result+='XA=\"'+ Macro.Origin.Point.X*10.0 + '\"\r\n'//"Macro.Origin.Point.X" provides the X coordinate in cm units 
                                                     // of the macro base point coordinate system. 
result+='YA=\"'+ Macro.Origin.Point.Y*10.0 + '"\r\n' //"Macro.Origin.Point.X" provides the Y coordinate in cm units 
                                                     // of the macro base point coordinate system. 
result+='LA=\"'+ 90+'\"\r\n'                         // Length of pocket.
result+='BR=\"'+ 28+'\"\r\n'                         // Width of pocket.
result+='RD=\"'+ 14 + '\"\r\n'                       // Radius of pocket corners
result+='WI=\"'+ 180.0 / Math.PI * Macro.Origin.RotationAngle+'\"\r\n' //"Macro.Origin.RotationAngle" provides rotation angle in radians
                                                                       // of macro base point coordinate system.
result+='TI=\"'+ 14 + '\"\r\n'                                         // Thickness of pocket
result+='ZT=\"5\"\r\n'
result+='XY=\"50\"\r\n'
result+='T_=\"101\"\r\n'
result+='F_=\"STANDARD\"\r\n'
result+='DS=\"0\"\r\n'
result+='KM=\"\"'
 
return result
}

 

 

The text output by the Post-Processor to the final CNC program might look like this:

 

<112 \Tasche\

XA="208.000"

YA="301.000"

LA="90"

BR="28"

RD="14"

WI="0"

TI="14"

ZT="4"

XY="50"

T_="101"

F_="STANDARD"

DS="0"

KM=""

 

 

The program described can use external JavaScipt libraries, which can be added using the import operator.

 

import * as Utils from 'C:/Users/Public/Documents/Woodwork for Inventor/2022/v13/JS/UtilityFunctions.js'

 

 

All function calls from the libraries and function uses must respect the JavaScript language requirements.

 

 

On global variables

 

The Woodwork for Inventor JS Macro interpreter runs in sequence all JS Macros that are present in a given CAM technology in the order in which they are arranged when they are compiled in the cutting component, and also in the order in which they are arranged in the CAM technology. All JS Macros may have variables that transport their value from one JS Macro to another. For example, this is how a coordinate system counter works. Let’s say each JS Macro requires a new coordinate system to be created for it, which needs to be given a new number. Therefore, the following function can be provided in the Macro:

 

var CoordinateSystemNumber;

 

// Gets increment number for each next coordinate system naming

export function GenerateCoordinateSystemNumber(Increment) {

 

  if (typeof CoordinateSystemNumber === 'undefined')

      CoordinateSystemNumber = 10;

 

  CoordinateSystemNumber = CoordinateSystemNumber + Increment

 

  return CoordinateSystemNumber

 

}

 

 

CoordinateSystemNumber – the counter common to all JS Macros is incremented if the function GenerateCoordinateSystemNumber(Increment) is called in the JS Macro. Thus, for each Front-End Macro, a new coordinate system number is generated, regardless of how many JS Macros are run on a given part.