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: 

STOCK MODEL FACE MILLING

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
692 Views, 5 Replies

STOCK MODEL FACE MILLING

Please help with a macro if you can and thank you for reading this post.  My company wants all finish face milling strategies to be calculated to a stock model.  Once I program this path in Powermill the Z heights tend to be sporadic and or not in any type of order.  Does anyone have a macro and or an idea for a macro to split up a stock model path by every level being faced so I can organize what floors to cut first?  Thank you for your time!

Labels (4)
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

I have a macro that splits flat finishing toolpaths by their z-levels. It's not the fastest and maybe not the most elegant way but back then it was the only possibility I found. Maybe this is exactly what you are looking for or it helps you further to write your own macro.

 

FUNCTION Main() {
	
	GRAPHICS LOCK	
	ENTITY $TP = entity('toolpath', '')
	STRING $TPName = entity('toolpath', '').name
		
	// Create pattern and insert toolpath 
	CREATE PATTERN "TempPat"
	EDIT PATTERN "TempPat" INSERT TOOLPATH $TPName
	
	// export pattern as pic file and delete the pattern
	STRING $fileName = project_pathname(0) + "/1.pic"
	STRING $cmd = "KEEP PATTERN 'TempPat' FILESAVE '" + $fileName + "' Yes"
	DOCOMMAND $cmd		
	DELETE PATTERN "TempPat"
	
	// Get all unique z levels from the pic file
	FILE OPEN $fileName FOR READ AS input
	STRING LIST $file = {}
	FILE READ $file FROM input
	FILE CLOSE input
	$file[1] = ""	
	REAL LIST $ZLevels = {}	
	FOREACH $line IN $file {
		STRING LIST $Tokens = tokens($line,' ')		
		IF (size($Tokens) == 5) {
			REAL $ZValue = 0
			CALL ConvertSciNot($Tokens[2], $ZValue)
			INT $s = add_last($ZLevels, $ZValue)			
		}
	}
	INT n = remove_duplicates($ZLevels)
	$ZLevels = sort($ZLevels)
	IF (size($ZLevels) == 1) {
		// Only one z level -> Exit Macro		
		RETURN
	}		
	
	//Split toolpath	
	STRING $OldName = ""
	STRING $NewName = ""
	INT $counter = 0
	REAL $ZLevel = $ZLevels[$counter]

	// First Split
	ACTIVATE Toolpath $TPName
	EDIT TOOLPATH LIMIT PLANE
	EDIT TOOLPATH LIMIT PLANEOPTIONS SELECT Z
	EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
	EDIT TOOLPATH LIMIT DELETE N	
	EDIT TOOLPATH LIMIT KEEP BOTH
	EDIT TOOLPATH LIMIT REORDER NO
	PROCESS TPLIMIT
	// rename original TP to X_Save
	$NewName = $TPName + "_Save"
	RENAME Toolpath $TPName $NewName
	// rename X_1 to X_ZLevel
	$OldName = $TPName + "_1"
	$NewName = $TPName + "_Z" + $ZLevel
	RENAME Toolpath $OldName $NewName
	// rename X_2 to X
	$OldName = $TPName + "_2"
	$NewName = $TPName
	RENAME Toolpath $OldName $NewName
	
	// X Splits
	$counter = $counter + 1
	IF (size($ZLevels) > 2) {		
		WHILE ($counter < size($ZLevels) - 1) {
			ACTIVATE Toolpath $TPName
			$ZLevel = $ZLevels[$counter]
			EDIT TOOLPATH LIMIT DELETE Y
			EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
			PROCESS TPLIMIT
			// rename X_1 to X_ZLevel
			$OldName = $TPName + "_1"
			$NewName = $TPName + "_Z" + $ZLevel
			RENAME Toolpath $OldName $NewName
			// rename X_2 to X
			$OldName = $TPName + "_2"
			$NewName = $TPName
			RENAME Toolpath $OldName $NewName
			$counter = $counter + 1
		}
	}
	
	//Last Split
	ACTIVATE Toolpath $TPName
	$ZLevel = $ZLevels[$counter]
	EDIT TOOLPATH LIMIT DELETE Y
	//EDIT TOOLPATH LIMIT KEEP OUTER
	EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
	PROCESS TPLIMIT
	// rename X_1 to X_ZLevel
	$OldName = $TPName + "_1"
	$NewName = $TPName + "_Z" + $ZLevel
	RENAME Toolpath $OldName $NewName
	FORM CANCEL TPLIMIT		
}


FUNCTION ConvertSciNot(STRING $input, OUTPUT REAL $output) {

	STRING LIST $Tokens = tokens($input,'E')
	REAL $first = real($tokens[0])
	INT $exp = int($tokens[1])
	$output = $first * 10 ^ $exp
	
}
Message 3 of 6
Anonymous
in reply to: Anonymous

Thank you very much for the quick reply.  I tried running the macro and ran into a renaming error -

 

Toolpath 'A_2' does not exist - Line 82 - RENAME Toolpath $OldName $NewName

 

Have you ever ran into this issue on your end?  

 

Once again Thank You!  This macro you have shared will get us a lot closer to our goal and is much appreciated.

Message 4 of 6
Anonymous
in reply to: Anonymous

I have reworked the macro again and have found and hopefully eliminated a few possible error sources.

 

Originally the macro was only intended for "Offset Flat Finishing" and "Raster Flat Finishing" toolpaths. Now it should also work with "Face Milling" and "Model Area Clearance" toolpaths.

 

Also, the error in line 82 should no longer occur now.

FUNCTION Main() {

	GRAPHICS LOCK

	REAL $tolerance = 0.01
	STRING $TPName = entity('toolpath', '').name

	// Create pattern and insert toolpath
	CREATE PATTERN "TempPat"
	EDIT PATTERN "TempPat" INSERT TOOLPATH $TPName

	// export pattern as pic file and delete the pattern
	STRING $fileName = project_pathname(0) + "/1.pic"
	STRING $cmd = "KEEP PATTERN 'TempPat' FILESAVE '" + $fileName + "' Yes"
	DOCOMMAND $cmd
	DELETE PATTERN "TempPat"

	// Get all unique z levels from the pic file
	FILE OPEN $fileName FOR READ AS input
	STRING LIST $file = {}
	FILE READ $file FROM input
	FILE CLOSE input
	$file[1] = ""
	REAL LIST $ZLevels = {}
	FOREACH $line IN $file {
		STRING LIST $Tokens = tokens($line,' ')
		IF (size($Tokens) == 3 OR size($Tokens) == 5) {
			REAL $ZValue = 0
			CALL ConvertSciNot($Tokens[2], $ZValue)
			INT $s = add_last($ZLevels, $ZValue)
		}
	}
	INT n = remove_duplicates($ZLevels)
	$ZLevels = sort($ZLevels)
	IF (size($ZLevels) == 1) {
		// Only one z level -> Exit Macro
		RETURN
	}

	//Split toolpath
	STRING $OldName = ""
	STRING $NewName = ""
	INT $counter = 0
	REAL $ZLevel = $ZLevels[$counter] + $tolerance

	// First Split
	ACTIVATE Toolpath $TPName
	EDIT TOOLPATH LIMIT PLANE
	EDIT TOOLPATH LIMIT PLANEOPTIONS SELECT Z
	EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
	EDIT TOOLPATH LIMIT DELETE N
	EDIT TOOLPATH LIMIT KEEP BOTH
	EDIT TOOLPATH LIMIT REORDER NO
	PROCESS TPLIMIT
	// rename original TP to X_Save
	$NewName = $TPName + "_Save"
	RENAME Toolpath $TPName $NewName
	// rename X_1 to X_ZLevel
	$OldName = $TPName + "_1"
	$NewName = $TPName + "_Z" + ROUND($ZLevel - $tolerance, 2)
	RENAME Toolpath $OldName $NewName
	// rename X_2 to X
	$OldName = $TPName + "_2"
	$NewName = $TPName
	RENAME Toolpath $OldName $NewName

	// X Splits
	$counter = $counter + 1
	IF (size($ZLevels) > 2) {
		WHILE ($counter < size($ZLevels) - 1) {
			ACTIVATE Toolpath $TPName
			$ZLevel = $ZLevels[$counter] + $tolerance
			EDIT TOOLPATH LIMIT DELETE Y
			EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
			PROCESS TPLIMIT
			// rename X_1 to X_ZLevel
			$OldName = $TPName + "_1"
			$NewName = $TPName + "_Z" + ROUND($ZLevel - $tolerance, 2)
			RENAME Toolpath $OldName $NewName
			// rename X_2 to X
			$OldName = $TPName + "_2"
			$NewName = $TPName
			RENAME Toolpath $OldName $NewName
			$counter = $counter + 1
		}
	}

	//Last Split
	ACTIVATE Toolpath $TPName
	$ZLevel = $ZLevels[$counter] + $tolerance
	EDIT TOOLPATH LIMIT DELETE Y
	//EDIT TOOLPATH LIMIT KEEP OUTER
	EDIT TOOLPATH LIMIT PLANEOPTIONS POINT POSZ $ZLevel
	PROCESS TPLIMIT
	// rename X_1 to X_ZLevel
	$OldName = $TPName + "_1"
	$NewName = $TPName + "_Z" + ROUND($ZLevel - $tolerance, 2)
	RENAME Toolpath $OldName $NewName
	FORM CANCEL TPLIMIT		
}


FUNCTION ConvertSciNot(STRING $input, OUTPUT REAL $output) {

	STRING LIST $Tokens = tokens($input,'E')
	REAL $first = real($tokens[0])
	INT $exp = int($tokens[1])
	$output = $first * 10 ^ $exp
}

 

Message 5 of 6
Anonymous
in reply to: Anonymous

Absolutely perfect!  Tested the macro and it works great.  Thank you so much for you time and help!

Message 6 of 6
Anonymous
in reply to: Anonymous

Hello Feuerbowle,

 

I have been doing multiple test with this code received from you and it has worked 95% of the time.  I have some projects that are massive and sometimes the positive Z levels don't all split into individual paths.  What I mean buy this is that some toolpath strategies have two different Z levels in the same path and the macro names only the top Z level.  A lot of our face mill paths work on both sides of 0 (negative and positive Z levels) and on all of our smaller projects this macro runs amazing yet on the big projects it just seems like the macro doesn't follow all the way thru.  Just curious if you have ever ran into this issue before and or if you had any idea where a problem in the code might exist.  Always seems to be the last two Z level split strategies that are giving me a fit.  

 

You have helped me out so much and I thank you!  Any ideas on this issue would be greatly appreciated.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report