Entity based functions
These functions work on specific entities.
Command | Description |
---|---|
entity_exists() |
Returns true if the named entity exists. |
geometry_equal() |
Compares two tools, or two workplanes for geometric equivalence. |
new_entity_name() |
Returns the name assigned to the next entity. |
set_workplane() |
Sets the vectors and origin of a workplane. |
segments() |
Returns the number of segments in a toolpath, boundary or pattern. |
stockmodel_visible_volume() |
Returns the stock model volume, based on the stock model drawing option used to show the material. |
limits() |
Returns the XYZ limits of an entity. |
toolpath_cut_limits() |
Returns the XYZ limits of the toolpath's cutting moves. |
- Equivalence
- Number of segments
- Stock model volume
- Limits
- Toolpath cut limits
- Does an entity exist?
- New entity name
- Improving entity-specific macros
- Creating an entity-specific macro
Equivalence
You can use the inbuilt function geometry_equal()
to test whether two tools, or two workplanes are geometrically equivalent. For a tool the test is based on the cutting geometry of the tool.
Number of segments
The inbuilt function segments()
returns the number of segments in a pattern or boundary:
IF segments(Pattern) == 0 {
PRINT "The pattern is empty"
}
To return the number of segments in a toolpath, use:
function toolpath_component_count(toolpath,type)
For example:
print par ${toolpath_component_count('toolpath', '1', 'links')}
print par ${toolpath_component_count('toolpath', '1', 'leads')}
print par ${toolpath_component_count('toolpath', '1', 'segments')}
// Returns the number of toolpath segments, links and leads moves in toolpath named '1'
Stock model volume
The inbuilt function stockmodel_visible_volume()
returns the stock model volume, based on the stock model drawing option used to show the material. The drawing options are:
Show all material
Show rest material
Show removed material
For example:
real volume = stockmodel_visible_volume(entity('stockmodel',"SM"))
// Assigns the volume of the stock model named "SM" to variable "volume".
Limits
The inbuilt function limits()
returns an array of six elements containing the XYZ limits of the given entity. The supported entities are: pattern, boundary, toolpath, feature set, or model.
REAL ARRAY Lims[] = limits('model','MyModel')
The values in the array are:
REAL MinX = Lims[0]
REAL MaxX = Lims[1]
REAL MinY = Lims[2]
REAL MaxY = Lims[3]
REAL MinZ = Lims[4]
REAL MaxZ = Lims[5]
Toolpath cut limits
The inbuilt function toolpath_cut_limits()
returns an array of 6 real values that hold the XYZ limits of the toolpath's cutting moves. The entity parameter must be a calculated toolpath. The returned array can be used to initialize, or assign to, another array or list.
REAL ARRAY lims[] = toolpath_cut_limits(Toolpath)
$lims = toolpath_cut_limits('my toolpath')
The values in the array are:
array[0] = Minimum X value.
array[1] = Maximum X value.
array[2] = Minimum Y value.
array[3] = Maximum Y value.
array[4] = Minimum Z value.
array[5] = Maximum Z value
Does an entity exist?
The inbuilt function entity_exists()
returns true if the entity exists. You can call this function with:
an entity parameter such as
entity_exists(Boundary)
,entity_exists(ReferenceTool)
, orentity_exists(entity('toolpath',''))
.two parameters that specify the entity type and name such as
entity_exists('tool','MyTool')
.
For example:
IF entity_exists(Workplane) {
PRINT "An active workplane exists"
} ELSE {
PRINT "No active workplane using world coordinate system."
}
IF NOT entity_exists(entity('toolpath','')) {
PRINT "Please activate a toolpath and try again."
MACRO ABORT ALL
}
New entity name
The inbuilt function new_entity_name()
returns the next name that PowerMill gives to a new entity of the given type. You can supply an optional basename argument to obtain the name that PowerMill uses when creating a copy or clone of
an entity.
This example shows you how to determine the name of a new entity.
CREATE WORKPLANE 1
CREATE WORKPLANE 2
CREATE WORKPLANE 3
// Prints 4
PRINT = new_entity_name('workplane')
DELETE WORKPLANE 2
// Prints 2
PRINT = new_entity_name('workplane')
CREATE WORKPLANE ;
// Prints 2_1
PRINT = new_entity_name('workplane', '2')
Improving entity-specific macros
You can use parameters to write macros that instruct PowerMill to execute specific lines of code before and after it processes the first and last entity in a loop. The parameters enable PowerMill to:
identify the last selected entity; and
display the total number of selected entities and the entity PowerMill is currently processing.
The parameters are:
powermill.Status.MultipleSelection.Last
This enables PowerMill to identify the last selected entity.
powermill.Status.MultipleSelection.Count
This enables PowerMill to display the entity it is processing, for example, 'Checking toolpath 6 for collisions'.
powermill.Status.MultipleSelection.Total == 0
This enables PowerMill to display the total number of selected entities.
powermill.Status.MultipleSelection.First
This enables PowerMill to identify the first entity in a loop.
Creating an entity-specific macro
The example shows how to create a macro that uses a user-defined clearance value to collision check the select toolpaths. The macro:
asks the user to enter the holder clearance PowerMill uses to collision check the toolpaths.
displays the name of the toolpath it is processing.
displays a message when collision checking is complete.
Function Main( STRING $Selected_Toolpath ) { // Create new project parameter to store the holder clearance BOOL $chk = 0 $chk = ERROR $project.clearance if $chk { // Project variable does not exist. Create it and set it to 5 degrees EDIT PAR CREATE REAL "clearance" } // Before checking the first toolpath, PowerMILL should ask the user to enter the holder clearance IF ($powermill.Status.MultipleSelection.First) OR $powermill.Status.MultipleSelection.Total == 0 {$project.clearance = INPUT ${"Enter the holder clearance PowerMILL uses when checking the " + $powermill.Status.MultipleSelection.Total + " selected toolpaths for collisions "}} // Now collision check toolpath with entered clearance // Set the clearance: EDIT COLLISION HOLDER_CLEARANCE $project.clearance // Now check the toolpath for collisions EDIT COLLISION TYPE COLLISION PRINT = "Processing toolpath " + $powermill.Status.MultipleSelection.Count EDIT COLLISION APPLY // Tell user all selected toolpaths have been checked IF ($powermill.Status.MultipleSelection.Last) { MESSAGE INFO "All toolpaths have been checked " } }