Passing component parameters to the Macro program

Top | Previous | Next

 

It is often useful to use parameters that exist in a given component in a JS Macro program. For example, a paper clip holder recessed into a tabletop requires a rectangular pocket to be milled. This component may have parameters “Length” and “Width” which control the length and width of this component. Obviously, such a component also requires a different pocket size. Therefore, the Macro program that will generate the subprogram for the milling of the Woodwop rectangular pocket (see here for a description) will need to transfer these parameters.

 

 

Paper clip holder

Paper clip holder

 

 

Attention! In order for these parameters to be available in the JS Macro program, it is necessary to declare these parameters as exported parameters.

 

Declaration of exported component parameters

Declaration of exported component parameters

 

 

In JS Macro, these parameters are accessible via the keywords interpreter object "KeywordParser".

The "Parse" method allows the interpretation of any allowed combination of keywords.

 

KeywordParser.Parse('<Keyword string>')

 

 

Thus, to access the “Length” parameter of a given component we should use the following expression:

 

KeywordParser.Parse('Macro.CuttingComponent.Parameter.Length')

 

 

To access the “Width” parameter we should write the following expression:

 

KeywordParser.Parse('Macro.CuttingComponent.Parameter.Width')

 

 

Note that the parameters are returned in units, which are stored in the internal format of Autodesk Inventor. In this case, the “Length” parameter is declared as a distance unit, so it is stored in centimeters in Autodesk Inventor’s internal data. Specifically, if you follow the values shown in the figure, it will be 12.0. Therefore, before using it in the program, remember to convert it to the units that will be output in the final text of the Front-End program. If you need millimeters, for example, then the output size should be multiplied by 10. For more details on converting and formatting output sizes, see the section “Units and formatting of output values”.

 

Given the above, the function and the required pocket recess formatting, which is generated by the JS Macro program, should look like this:

 

export function Result()

{

 

var result

 

result='<112 \\Tasche\\\r\n'

result+='XA=\"'+ Coord2Str.Output(Macro.Origin.Point.X) + '\"\r\n'

result+='YA=\"'+ Coord2Str.Output(Macro.Origin.Point.Y) + '"\r\n'

result+='LA=\"'+ Coord2Str.Output(KeywordParser.Parse('{Macro.CuttingComponent.Parameter.Length}'))+'\"\r\n'

result+='BR=\"'+ Coord2Str.Output(KeywordParser.Parse('{Macro.CuttingComponent.Parameter.Width}'))+'\"\r\n'

result+='RD=\"'+ 8 + '\"\r\n'

result+='WI=\"'+ Angle2Str.Output(Macro.Origin.RotationAngle)+'\"\r\n'

result+='TI=\"'+ 13.0 + '\"\r\n'

result+='ZT=\"1\"\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

}

 

 

In addition, the workpiece parameters can be accessed. For example:

 

KeywordParser.Parse('{Item.Code}') - gražins detalės numerį

KeywordParser.Parse('{Item.Length}') - grąžins detalės ilgį

KeywordParser.Parse('{Item.FillWorkpiece.Material.Code}') - grąžins medžiagos kodą

 

 

The keyword interpreter needs to generate the query in a syntax that is specific to the BOM keyword interpreter.