Macro for generating toolpaths

Macro for generating toolpaths

Anonymous
Not applicable
4,465 Views
16 Replies
Message 1 of 17

Macro for generating toolpaths

Anonymous
Not applicable

Hi,

 

I'm looking to make some macros so that we can automatically generate toolpaths for our more commonly used strategies.

 

The issue I've got is that when I run the macro, unless the toolpath number automatically generated is the same as the one generated when I wrote the macro, it won't work.

 

The macro line in question is - RENAME TOOLPATH "1" "EM8 MAC rough" 

 

where "1" is the automatically generated toolpath name and "EM8 MAC rough" is whatever the name of that particular strategy is called.

 

The issue is when there has already been a toolpath generated with the name "1". Even if it has subsequently been renamed, running the macro gives an error message along the lines of TOOLPATH 1 ALREADY EXISTS. It's trying to rewrite toolpath 1 but the toolpath generated by the macro might be toolpath 2 or 3 or so on.

 

What I want is to write the macro so that it says something along the lines of  - RENAME TOOLPATH "whatever it is called" "EM8 MAC rough"

 

I just don't know the macro code for "whatever it is called".

 

Not sure if that makes sense. Sorry, I'm all rather new to macros.....

0 Likes
Accepted solutions (1)
4,466 Views
16 Replies
Replies (16)
Message 2 of 17

NanchenO
Collaborator
Collaborator

Hi,

 

There is for sure a solution, but could you please provide two screenshots "before-after" to better explain what you want to do ?

 

Olivier

0 Likes
Message 3 of 17

5axes
Advisor
Advisor
Accepted solution

RENAME TOOLPATH "whatever it is called" "EM8 MAC rough" -> Whatever is called could be replace by $Toolpath ...  just after the new toolpath creation this one is still active. So it could be identify with the variable $Toolpath

 

Solution : RENAME TOOLPATH $Toolpath "EM8 MAC rough"

Message 4 of 17

Anonymous
Not applicable

Cheers Guys.

 

That $Toolpath code worked a treat.

 

I'd taken a look thorough the "guide to writing macros" and noticed the $ commands, but it all looked a little confusing. Some good bedtime reading...

 

Cheers

 

Rich.

0 Likes
Message 5 of 17

iamcdn79
Mentor
Mentor

This would also be an alternative wouldn't it be?

 

 

RENAME TOOLPATH ; "EM8 MAC rough"

They both rename an active toolpath

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

Message 6 of 17

5axes
Advisor
Advisor

The Macro langage is very rich, that's a strength and also sometimes a problem because it could be confusing :

 

so you can use :

 

RENAME TOOLPATH  $Toolpath "EM8 MAC rough"

 

RENAME TOOLPATH # "EM8 MAC rough"

 

RENAME TOOLPATH ; "EM8 MAC rough"

 

RENAME TOOLPATH $ENTITY('toolpath','') "EM8 MAC rough"

 

you can also use a function like new_entity_name to get the name of the next toolpath created.

 

STRING $TpName = new_entity_name('toolpath')

 

and then

 

RENAME TOOLPATH  $TpName "EM8 MAC rough"

 

There is always differents way to reach the same goal

Message 7 of 17

Anonymous
Not applicable

If you're ever stuck for a macro command, providing you know how to do what you want, you can use the Echo Commands tool.

 

On the Menu Bar click Tools then Echo Commands

 

The Command window will open at the bottom of your screen, then every time you click a button or change a setting in PowerMILL the command line will be shown in the bottom window. Simply copy the line and paste it into your macro, then edit as needed.

 

It's a great tool, even after years of writing macros I still use it regularly (especially when the developers change the language or command Smiley Tongue )

0 Likes
Message 8 of 17

Anonymous
Not applicable
The guy who did our training on Pmill went through that.

The issue in this case is that echoing commands would only bring up the
specific toolpath number which was generated, not a term for generic tool
numbers.

all sorted now though.

Thanks folks.

--


------------------------------------------------------------------------------------------
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed.

Information or opinions in this email which do not relate to the
official business of Allies and Morrison are neither given nor endorsed by
it.

If you have received this email in error please notify
*[email protected] *
Allies and Morrison LLP (OC404597) is a Limited Liability
Partnership incorporated in England and Wales whose registered office is 85
Southwark Street, SE1 0HX
------------------------------------------------------------
------------------------------
0 Likes
Message 9 of 17

yanbin.liuTE8KH
Explorer
Explorer

there are 10 toolpaths, and I want change the toolpath name to "toolname+holdername+thickness"  one by one .

how can we do by macro?

 

0 Likes
Message 10 of 17

5axes
Advisor
Advisor

something like :

// Rename every toolpath
STRING NewName = ''
FOREACH ent IN folder('Toolpath') {
    ACTIVATE TOOLPATH $ent
    
    $NewName= $ent.tool.name + "-" + $ent.tool.HolderName + "-"  + $ent.Thickness
    // test if the Name is already valid if not true nothing to do 
    if $ent.Name != $NewName {
	    // test if toolpath name already exist
	    if entity_exists('toolpath', $NewName) {
	        // Give the next valid toolpath name
	    	$NewName = new_entity_name('toolpath', $NewName)
	    }
	    RENAME TOOLPATH $ent.name $NewName
    }
}
Message 11 of 17

yanbin.liuTE8KH
Explorer
Explorer
thanks
0 Likes
Message 12 of 17

vasilevich555
Contributor
Contributor

I am learning Powermill macro. Very bad description.There is no good description, and the information is not structured and there is no integrity.Therefore, questions arise. Perhaps you can answer some. We have a function extract (list, par_name) returns a list of parameter values ​​(par_name) extracted from the list (list) of the input list. It says so in the description. Let's take several different parameters with different data types in essence the toolpath.

 

1 Parameter "Batch" bool type. Get a list of bool type parameter values.

bool list m = extract(folder('toolpath'),'Batch')

vasilevich555_0-1664640480186.png

2. Parameter "Revision" type int. Get a list of parameter values ​​of type int.

int list m = extract(folder('toolpath'),'Revision')

vasilevich555_1-1664640515314.pngvasilevich555_2-1664640529392.png

 

3. Parameter "Block.Limits.Xmax" type real. Get a list of values ​​of the real type parameter.

real list m = extract(folder('toolpath'),'Block.Limits.Xmax')

vasilevich555_3-1664640568303.pngvasilevich555_4-1664640603074.png

4. The "Stepover" parameter is of type real. We get an empty list of parameter values.  What does it mean???

real list m = extract(folder('toolpath'),'Stepover')

vasilevich555_5-1664640656660.pngvasilevich555_6-1664640668850.png

5.  Parameter Type of object "Coolant". Get a list of object values.object list m = extract(folder('toolpath'),'Coolant')Why is MAP shown for debugging and not object ???

vasilevich555_7-1664640710125.pngvasilevich555_8-1664640722257.png

6.  Parameter "Strategy" type ENUM. Powermill gives an error. For both cases. 

What is wrong here?

string list m = extract(folder('toolpath'),'Strategy')

enum list m = extract(folder('toolpath'),'Strategy')

vasilevich555_9-1664640799999.pngvasilevich555_10-1664640816569.png

 

 

0 Likes
Message 13 of 17

ondrej.mikulec
Advocate
Advocate

I don't see so much benefit in using the Extract() function in macros. I am using the Extract() function in my applications where there is a significant bottleneck between the app and Powermill. 

real list m = extract(folder('toolpath'),'Stepover')
Works well in my macro/computer. But to properly test try printing the result in the command line. Just type in the command line: 
print par "extract(folder('toolpath'),'Stepover')"

Instead of the 'Coolant' use 'Coolant.Value'. 

'Strategy' doesn't work in my macro/computer either. But printing value is alright 

print par "extract(folder('toolpath'),'Strategy')"

so I can't help with that. Some other ENUM values work alright. So maybe a Powermill bug?

 

Message 14 of 17

vasilevich555
Contributor
Contributor

If you use the print par ${extract ()} command, then all types work. This command gives an array of the same type as specified in the entity structure. For types  string, bool, int, real it will be array m[] = $extract(). The type object would be list = $extract().

Questions remain on some types. For example

1. Type real array

print par ${extract(folder('TOOLPATH'),'EndPoint.Position')}

vasilevich555_0-1665851192341.png

2 Type enum

print par ${extract(folder('TOOLPATH'),' Strategy')}

vasilevich555_1-1665851266962.png

What should be written on the left side of the expression to get these arrays or lists?

 ??? = $extract(folder('TOOLPATH'),'EndPoint.Position')

  ??? = $extract(folder('TOOLPATH'),'Strategy')

 

3 You also specify what can be used Instead of "Coolant", use "Coolant.Value". I don't understand what exactly you mean?

0 Likes
Message 15 of 17

ondrej.mikulec
Advocate
Advocate

REAL LIST $extractedX = $extract(folder('TOOLPATH'),'EndPoint.Position.X')

REAL LIST $extractedY = $extract(folder('TOOLPATH'),'EndPoint.Position.Y')

REAL LIST $extractedZ = $extract(folder('TOOLPATH'),'EndPoint.Position.Z')

 

or

 

REAL LIST $extractedX = $extract(folder('TOOLPATH'),'EndPoint.Position[0]')

REAL LIST $extractedY = $extract(folder('TOOLPATH'),'EndPoint.Position[1]')

REAL LIST $extractedZ = $extract(folder('TOOLPATH'),'EndPoint.Position[2]')

 

This is the same as with "Coolant" and "Coolant.Value". When you are attempting to extract the "Coolant" the extracted output cannot be cast into the STRING list, because "Coolant" properties are not of the string type. The "Coolant" is maybe a class that has the property "Value" inside which is correctly returning the string castable value. 

 The "EndPoint.Position" is an array. So it cannot be cast into the REAL LIST. Theoretically, you would need something as "List<double[]>" but I'm not sure that Powermill macro is capable of doing that. You have to extract the final values of the array which are indexed. I have also tried X, Y, and Z, and it's working. 

 

Why the “Strategy” doesn’t work? I don't know. I would just use the FOREACH loop to fill a list anyway. 

 

The “extract” method is tricky because the extracted list skips toolpaths that have not implemented the extracting property. So therefore the array indexes of the extracted values don’t match. I am extracting via “print par” which is also returning [0], [1], [2], …. Next to extracted values so I have correct indexes. But I am not using that in standard Powermill macros, only in .NET applications with really big Powermill projects with a lot of entities.

Message 16 of 17

vasilevich555
Contributor
Contributor

It seems that the macro language in powermill is poorly designed, lacking clear logic and lacking repeatability with different data types. print par {} command gives the same, clear and simple representation, the extract() function is absolutely not up to it. Probably, there is a degradation of developers and therefore the lack of a common concept. Probably, there is no selection of developers by psychotypes. I would replace the one who manages the development. Some kind of chaos in general in powermill, not only in macros, they do what they want, but not what they need.

 

Here a number of questions arise.

 

  1. If print par{} works well, is it possible to use this command to get data? I did not find her description of the instructions.
  2. REAL LIST $extractedX = $extract(folder('TOOLPATH'),'EndPoint.Position.X'). The fields X,Y,Z are not present in the entity.

vasilevich555_0-1666091844983.png

       Also in the example STRING LIST names = extract(folder('toolpath'),'name') - there is no             'name' field in the object structure. Where can I find a description of all fields?

vasilevich555_1-1666091940993.png

 

3. It is not clear how to define an array, where are two sizes? For example an array

vasilevich555_2-1666091987459.png

How to set such an array for example for a real array[ ][ ] = ???

 

4. It is not clear in which cases the use of $ is necessary, and in some cases it is not,

especially if it is an expression. I haven't found any universal rule. This language construct is not understood. Can you explain this to me?

 

5. There is another question on another topic. It is not clear where you can find a description of the command with their parameters. For example, the instruction contains a command to create a toolpath. An example is given in the instructions section Sorted list”.

CREATE TOOLPATH 'bbb' RASTER - This command doesn't work 

 In echo, the creation of a trajectory looks like a set of other commands. Where can I get a     description of the commands and a description of their parameters?

0 Likes
Message 17 of 17

ondrej.mikulec
Advocate
Advocate

For a lot of things, I recommend contacting Autodesk support. If you want to Autodesk improve macro you must create a case in the support. In my opinion, the macro language had a really short life of development if assuming Autodesk did only a little development.

 

  • 1.&2. All parameters are in Documentation -> Parameters -> Reference. This is the primary source of information. There are also all available functions.
  • 3. I think it is not possible. Ask Autodesk support or create a case in the Autodesk support that you would like it to implement.
  • 4. At all your defined variables. At Powermill parameters and functions, it is not necessary, but I am using them there because when you need to just print out a function or parameter in the command line you must have that there. Also, the macro language is forgiving when you omit it in some spots. Both macros below work:
  •  

 

INT LIST $toolsNumbers = $extract($folder('Tool'), 'Number.Value')

INT $dummy = $remove_duplicates($toolsNumbers)

FOREACH $toolNumber IN $toolsNumbers {

	REAL $cuttingTimeSum = 0

	FOREACH $tp IN $folder("Toolpath") {
	
		IF $tp.Tool.Number.Value == $toolNumber {
		
			$cuttingTimeSum = $cuttingTimeSum + $tp.Statistics.TotalTime
		}
	}
	
	PRINT ${"Tool Number: " + $toolNumber + " Total Time: " + $time_to_string($cuttingTimeSum)}

}​
INT LIST toolsNumbers = extract(folder('Tool'), 'Number.Value')

INT dummy = remove_duplicates(toolsNumbers)

FOREACH toolNumber IN toolsNumbers {

	REAL cuttingTimeSum = 0

	FOREACH tp IN folder("Toolpath") {
	
		IF tp.Tool.Number.Value == toolNumber {
		
			$cuttingTimeSum = $cuttingTimeSum + tp.Statistics.TotalTime
		}
	}
	
	PRINT ${"Tool Number: " + toolNumber + " Total Time: " + time_to_string(cuttingTimeSum)}

}

 

  • Type HELP in the command line. You will get a list of available commands. Then type HELP CREATE and you will get all available commands after the command CREATE. Then type HELP CREATE TOOLPATH and you got nothing. So you can't create a toolpath with this command. Type HELP CREATE BOUNDARY and it's alright. Type HELP CREATE BOUNDARY ; and you will get all available commands when the ";" is a placeholder for the name of a boundary. So you can use CREATE BOUNDARY ; SILHOUETTE or CREATE BOUNDARY "HelloName" SILHOUETTE
0 Likes