[MACRO] Rename macro not working correctly in 2019, thoughts?

[MACRO] Rename macro not working correctly in 2019, thoughts?

danmic7JH66
Advocate Advocate
1,755 Views
16 Replies
Message 1 of 17

[MACRO] Rename macro not working correctly in 2019, thoughts?

danmic7JH66
Advocate
Advocate

I have this rename macro that cycles through all selected toolpaths and renames them based on some factors. Since updating to 2019 it doesn't work correctly. It will cycle through each toolpath and assign them a number but when it goes to the next toolpath, it sometimes deselects the toolpath it had just changed. The result is leaving some toolpath names like below, you can see how the toolpaths are deselected in the explorer window.

rename.PNG

It's not always on drilling programs that it deselects, just worked out that way for this session. Below is the macro. Thoughts or suggestions?

STRING RNM = ' '
INT CNT = 0


// CYCLES THROUGH ALL SELECTED PROGRAMS AND CLEARS THE NAME AND ASSIGNS A NUMBER
 FOREACH $Selected_Toolpath IN (explorer_selected_entities()) {
    // Exit if the selected entities are not Toolpaths
    IF $Selected_Toolpath.RootType != "toolpath" {
        BREAK
  }
    MACRO APPERROR CONTINUE

// CLEARS THE TOOLPATH NAME AND ASSIGNS EACH ONE A NUMBER
IF CNT < 10 {
		$RNM = "0" + $CNT + "-" 
	} ELSE {
		$RNM = $CNT + "-"
	}
	
	RENAME Toolpath $Selected_Toolpath $RNM
	$CNT = $CNT + 1
	}
 
	// DETERMINS TOOL DIAMETER AND ADDS THAT TO THE TP NAME
	  
	 FOREACH $Selected_Toolpath IN (explorer_selected_entities()) {
		// Exit if the selected entities are not Toolpaths
		IF $Selected_Toolpath.RootType != "toolpath" {
			BREAK
	  }
		MACRO APPERROR CONTINUE
	ACTIVATE TOOLPATH $Selected_Toolpath

	// TOOLPATH NAME VARIABLE AND TOOLNUMBER VARIABLE
	STRING TPNAME = ENTITY('toolpath','').name
	INT TOONUM = ENTITY('toolpath','').tool.number
	STRING MISSEDTOOLNAME = ENTITY('tool','').name
	STRING TOOLNAME = ' '
	IF $TOONUM < 10 {
	$TOOLNAME = "T00" + $TOONUM + "-"
	} ELSE {
	$TOOLNAME = "T0" + $TOONUM + "-"
	}
	IF $TOONUM == 0 {
	MESSAGE INFO "YOU FORGOT TO ADD A TOOLNUMBER TO TOOL... $MISSEDTOOLNAME , ADD TOOLNUMBER AND RESTART MACRO!"
	RENAME TOOLPATH ; "NO TOOL NUMBER"
	BREAK
	}
	
	// TOOL DIAMETER VALUES
	STRING TOODIA = ENTITY('tool','').Diameter
	REAL TOOREA = $TOODIA
	REAL TOORND = ROUND ($TOOREA, 4)
	REAL TOOMET = $TOORND / 0.03937
	REAL METRND = ROUND ($TOOMET, 2)
	INT METINT = ROUND ($METRND, 1) 
	
	// HIGH TOLERANCE VALUE
	REAL TOL = ENTITY('toolpath','').tolerance
	
	
	
	
	// STOCK VARIABLES	
	REAL THICC = Toolpath.Thickness
	STRING STOCK = ' '
	
	IF $THICC >= 0.015 {
	$STOCK = "ROUGH"
	}
	IF $THICC < 0.015 AND $THICC >= 0.001 {
	$STOCK = "SEMI"
	}
	IF $THICC < 0.001 {
	$STOCK = "FINISH"
	}
	
	REAL FLTTHICC = Toolpath.AxialThickness
	STRING FLTSTOCK = ' '
	
	IF $FLTTHICC >= 0.015 {
	$FLTSTOCK = "ROUGH"
	}
	IF $FLTTHICC < 0.015 AND $THICC >= 0.001 {
	$FLTSTOCK = "SEMI"
	}
	IF $FLTTHICC < 0.001 {
	$FLTSTOCK = "FINISH"
	}
		
		// SPIGOT TOOL VARIABLE
		STRING SPIGNAM = ENTITY('tool','').name
		$SPIGNAM = UCASE ($SPIGNAM)
		
		// NEW NAME BASE STRING
		STRING NEWNAME = $TPNAME + $TOOLNAME
		
		// TOOLPATH NAME VARIABLES
		STRING CHAMFERNAME = $NEWNAME + "CHAMFER"
		STRING SCRIBENAME = $NEWNAME + "SCRIBE"
		STRING DRILLNAME = $NEWNAME + $METRND + "MM_DRILL"
		STRING TAPNAME = $NEWNAME + $METINT + "MM_TAP"
		STRING HELINAME = $NEWNAME + $METINT + "MM_HELICAL-" + $STOCK
		STRING RASTERFLAT = $NEWNAME + $METINT + "MM_FLAT-" + $FLTSTOCK
		STRING OFFSETFLAT = $NEWNAME + $METINT + "MM_OFFSETFLAT-" + $FLTSTOCK
		STRING BALLNAME = $NEWNAME + $METINT + "MM_BALL-" + $STOCK
		STRING SPIGOT = $NEWNAME + "10MM_SPIGOT"
		STRING SPIGOTT = $NEWNAME + "14MM_SPIGOT"
		STRING SPIGOTTT = $NEWNAME + "18MM_SPIGOT"
		STRING SPIGOTTTT = $NEWNAME + "22MM_SPIGOT"
		
		// DECIDES WHAT TO NAME THE TOOLPATH BASED ON DIFFERENT TOOLPATH VARIABLES
		
		IF Strategy == "chamfer" {
		$NEWNAME = $CHAMFERNAME
				
		} ELSEIF Tool.Type == "taper_tipped" {
		$NEWNAME = $SCRIBENAME
		
		} ELSEIF Strategy == "drill" {
		
		IF toolpath.Drill.Type == "helical" {
		$NEWNAME = $HELINAME
		
			} ELSEIF toolpath.Drill.Type == 'tap_2' {
			$NEWNAME = $TAPNAME
				
				} ELSEIF toolpath.Drill.DepthType == 'chamfer' {
					$NEWNAME = $CHAMFERNAME
					
					} ELSEIF POSITION ($SPIGNAM,"10MM SPIGOT") >= 0 {
					$NEWNAME = $SPIGOT
				
						} ELSEIF POSITION ($SPIGNAM,"14MM SPIGOT") >= 0 {
						$NEWNAME = $SPIGOTT
						
							} ELSEIF POSITION ($SPIGNAM,"18MM SPIGOT") >= 0 {
							$NEWNAME = $SPIGOTTT
								
								} ELSEIF POSITION ($SPIGNAM,"22MM SPIGOT") >= 0 {
								$NEWNAME = $SPIGOTTTT
									} ELSE {
									$NEWNAME = $DRILLNAME
} 

		} ELSEIF Strategy == "raster_flat" {
		$NEWNAME = $RASTERFLAT
		
		} ELSEIF Strategy == "offset_flat" {
		$NEWNAME = $OFFSETFLAT
		
		} ELSEIF $TOOREA == 2.0 {
		$NEWNAME = $NEWNAME + "2_" + $STOCK
		
		} ELSEIF Tool.Type == "ball_nosed" {
		$NEWNAME = $BALLNAME
		
		} ELSE {
		$NEWNAME = $NEWNAME + $METINT + "MM-" + $STOCK
		}
		
		IF $TOL <= 0.0001 {
		$NEWNAME = $NEWNAME + "-HT"
		
		} ELSE {
		$NEWNAME = $NEWNAME
		}
		
		RENAME TOOLPATH ; $NEWNAME
}
MESSAGE INFO "TOOLPATHS RENAMED"
0 Likes
Accepted solutions (1)
1,756 Views
16 Replies
Replies (16)
Message 2 of 17

Ye。xg
Advocate
Advocate

Define selection filtering:

 

ENTITY LIST sel_ = explorer_selected_entities()
ENTITY LIST sel_Toolpath = {}
INT tpn = 0

FOREACH Toolpath IN sel_ {
IF position(pathname($Toolpath), "Toolpath") != -1 {
$tpn = add_last(sel_Toolpath, $Toolpath)
}
}

BOOL carryon = 0
IF $tpn != 0 {
STRING yesnoprompt = "Name the selected toolpath?" + CRLF + "Yes (selected)" + CRLF + "No (all)"
$carryon = QUERY $yesnoprompt
}
ENTITY LIST sel = select($carryon == 0 or $tpn == 0 ; folder('Toolpath'); $sel_Toolpath )

Message 3 of 17

danmic7JH66
Advocate
Advocate

I'll give that a try and report back later, thanks

 

0 Likes
Message 4 of 17

danmic7JH66
Advocate
Advocate

@Ye。xg wrote:

Define selection filtering:

 

ENTITY LIST sel_ = explorer_selected_entities()
ENTITY LIST sel_Toolpath = {}
INT tpn = 0

FOREACH Toolpath IN sel_ {
IF position(pathname($Toolpath), "Toolpath") != -1 {
$tpn = add_last(sel_Toolpath, $Toolpath)
}
}

BOOL carryon = 0
IF $tpn != 0 {
STRING yesnoprompt = "Name the selected toolpath?" + CRLF + "Yes (selected)" + CRLF + "No (all)"
$carryon = QUERY $yesnoprompt
}
ENTITY LIST sel = select($carryon == 0 or $tpn == 0 ; folder('Toolpath'); $sel_Toolpath )


So far so good, thanks!

0 Likes
Message 5 of 17

danmic7JH66
Advocate
Advocate

Ok, nevermind. It's doing the same thing again...

rename.PNG

0 Likes
Message 6 of 17

Anonymous
Not applicable
0 Likes
Message 7 of 17

danmic7JH66
Advocate
Advocate

@Anonymous wrote:

@danmic7JH66

 

Check below link,

 

https://forums.autodesk.com/t5/powermill-forum/macro-serial-number-in-toolpath/m-p/7818384#M8995

 

regards,

Krupal Vala

 


No, sorry that doesn't help. 

0 Likes
Message 8 of 17

rui_rita
Advocate
Advocate

hi @danmic7JH66

 

Can you check if this happens when you change you folder name ( you have 'TOOLPATH' as folder)



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.
0 Likes
Message 9 of 17

danmic7JH66
Advocate
Advocate

@rui_rita wrote:

hi @danmic7JH66

 

Can you check if this happens when you change you folder name ( you have 'TOOLPATH' as folder)


Having different folder names does not change the results

 

0 Likes
Message 10 of 17

danmic7JH66
Advocate
Advocate

Still haven't found a solution to this problem but I have discovered it mainly skips cloned toolpaths and toolpaths generated from drilling methods. Does anyone have any idea what's going on here?

 

0 Likes
Message 11 of 17

5axes
Advisor
Advisor

Without a sample project to make some test it will be difficult to analyse your issue. Looks like a specific problem 

0 Likes
Message 12 of 17

danmic7JH66
Advocate
Advocate

@5axes wrote:

Without a sample project to make some test it will be difficult to analyse your issue. Looks like a specific problem 


Ok, here is a sample project and the macro. If you select all the toolpaths and run the macro it will end up looking like this.

Capture1.PNG

it cycles through each toolpath, clears the name and assigns the base number. after it adds the number, it deselects any toolpaths which are cloned/mirrored or created with a drilling method. This only started happening when I switched over to 2019. If you run the macro twice, it will rename everything with no problem.

0 Likes
Message 13 of 17

danmic7JH66
Advocate
Advocate

It won't let me upload the file so here's a google drive link

https://drive.google.com/open?id=1APUbn_c5f0gvj_x3YB-eA3CoIwf739Cw

0 Likes
Message 14 of 17

5axes
Advisor
Advisor
Accepted solution

Hello,

I don't know if it's a bug , but I would suggest to not work directly on the explorer_selected_entities() list directly. As you can have in your macro this list can change especialy if you use it twice like in your macro.

 

So First think store this temporary list into an ENTITY list and work on these lists

// INIT the list of selected entities
ENTITY LIST SelEnt=explorer_selected_entities()
ENTITY LIST ModiEnt={}

Herewith your modified (Working) macro

 

 

 

0 Likes
Message 15 of 17

danmic7JH66
Advocate
Advocate

@5axes wrote:

Hello,

I don't know if it's a bug , but I would suggest to not work directly on the explorer_selected_entities() list directly. As you can have in your macro this list can change especialy if you use it twice like in your macro.

 

So First think store this temporary list into an ENTITY list and work on these lists

// INIT the list of selected entities
ENTITY LIST SelEnt=explorer_selected_entities()
ENTITY LIST ModiEnt={}

Herewith your modified (Working) macro

 

 

 


That did the trick, thanks! I haven't experimented much with creating lists so I didn't even think about doing that. Thanks for the help!

0 Likes
Message 16 of 17

5axes
Advisor
Advisor

Your welcome ..

By the way, it's nice also to have a project with your tool library, it's offer me the opportunity to test my own marcos on a different user configuration.  One of my macro is design to test invalid toolholder :
Test in the library, tools with the same holder reference but different geometry .  In your case several tool are detected by the macro . It's not big difference but on my mpoint of view it's better to start form a clean tool list. Have a look to the joined video 🙂

Message 17 of 17

danmic7JH66
Advocate
Advocate

That's interesting thanks! I was the one who started out the tool list for that machine originally and another employee took it over when I got swamped so I'm assuming that's where the differences started. The tool library for that machine is a mess and I've been meaning to get to it but just haven't had the time.