Community
PowerMill Forum
Welcome to Autodesk’s PowerMill Forums. Share your knowledge, ask questions, and explore popular PowerMill topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reorder toolpaths inside Nc Program

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
iamcdn79
470 Views, 5 Replies

Reorder toolpaths inside Nc Program

When I add multiple toolpaths with different names and different tool diameters with a macro it doesn't order the toolpaths as they were in the toolpath tree.

 

There is a command in the NC program to order toolpaths by tool number, tool diameter or workplane but it doesn't work. So I am trying to make a macro that reorders all the toolpaths in the active nc program by largest tool diameter, this is what I have so far but it errors on line 15 and 26

 

// Get the name of the active NC program
STRING ncProg = entity('ncprogram','').name

// Get the toolpaths in the active NC program
STRING LIST ncP_toolpaths = extract(entity('ncprogram', ncProg).nctoolpath, 'Name')

// Create a list to store the tool diameters
REAL LIST tool_diameters = {}

FOREACH tp IN ncP_toolpaths {
    // Get the tool entity associated with the toolpath
    ENTITY tool = entity('toolpath', tp).tool

    // Get the diameter of the tool and add it to the list
 Error on this --->   tool_diameters = append(tool_diameters, tool.diameter)
}

// Sort the toolpaths by tool diameter in a new list
STRING LIST sorted_toolpaths = sort(ncP_toolpaths, tool_diameters)

// Initialize a counter for the new order
INT new_order = 0

FOREACH tp IN sorted_toolpaths {
    // Reorder the toolpath in the NC program
 Will Error on this line --->   EDIT NCPROGRAM ncProg ORDER ITEM find(ncP_toolpaths, tp) AFTER ITEM new_order
    // Increment the counter
    new_order = new_order + 1
}

Here is the before and after if I do it manually 

iamcdn79_1-1715784620592.png

 

 


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

5 REPLIES 5
Message 2 of 6
ondrej.mikulec
in reply to: iamcdn79

// Get the name of the active NC program
STRING ncProg = entity('ncprogram','').name

// Get the toolpaths in the active NC program
STRING LIST ncP_toolpaths_Names = extract(components(entity('ncprogram', ncProg)), 'Name')

// Get the toolpaths entities in the ncP_toolpaths_Names
ENTITY LIST ncP_toolpaths = {}
FOREACH tp IN ncP_toolpaths_Names {
    INT $i = add_last($ncP_toolpaths,entity('Toolpath',$tp))
}

// Sort the toolpaths by tool diameter in a new list
ENTITY LIST sorted_toolpaths = sort(ncP_toolpaths, 'Tool.Diameter')

FOREACH tp IN sorted_toolpaths {
    // Reorder the toolpath in the NC program
    EDIT NCPROGRAM $ncProg ORDER TOOLPATH $tp.name LAST
}
Message 3 of 6
iamcdn79
in reply to: ondrej.mikulec

Thats better with no errors but it sorts the tool diameters by smallest first then largest when I need the largest first then smallest. Also, I need it to sort the toolpath names from smallest to largest, there would be duplicate toolpath names.

 

iamcdn79_1-1715857797973.png

 

 

 


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 4 of 6
ondrej.mikulec
in reply to: iamcdn79

I have added the 
$sorted_toolpaths = reverse(sorted_toolpaths)
and the loop
WHILE remove(ncP_toolpaths_Names,$tp.Name)

// Get the name of the active NC program
STRING ncProg = entity('ncprogram','').name

// Get the toolpaths in the active NC program
STRING LIST ncP_toolpaths_Names = extract(components(entity('ncprogram', ncProg)), 'Name')

// Get the toolpaths entities in the ncP_toolpaths_Names
ENTITY LIST ncP_toolpaths = {}
FOREACH tp IN ncP_toolpaths_Names {
    INT $i = add_last($ncP_toolpaths,entity('Toolpath',$tp))
}

// Sort the toolpaths by tool diameter in a new list
ENTITY LIST sorted_toolpaths = sort(ncP_toolpaths, 'Tool.Diameter')
$sorted_toolpaths = reverse(sorted_toolpaths)

// Reorder the toolpath in the NC program
FOREACH tp IN sorted_toolpaths {
    //Do the order command till the name is present in the ncP_toolpaths_Names list
	WHILE remove(ncP_toolpaths_Names,$tp.Name) {
		EDIT NCPROGRAM $ncProg ORDER TOOLPATH $tp.name LAST
	}
}

 

 

Message 5 of 6
iamcdn79
in reply to: ondrej.mikulec

It puts the tool diameters in the proper order but not the toolpath names, and when running the macro a second time it gives a different toolpath name order. The toolpath names needs to be from smallest to largest.

 

iamcdn79_0-1715946737583.png

 


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 6
ondrej.mikulec
in reply to: iamcdn79

Try this:

// Sort the toolpaths by tool diameter in a new list
ENTITY LIST sorted_toolpaths = sort(ncP_toolpaths, 'Name')
$sorted_toolpaths = reverse(sorted_toolpaths)
$sorted_toolpaths = sort(sorted_toolpaths, 'Tool.Diameter')
$sorted_toolpaths = reverse(sorted_toolpaths)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators