Cutter comp macro

Cutter comp macro

Eskondedo
Advocate Advocate
2,815 Views
13 Replies
Message 1 of 14

Cutter comp macro

Eskondedo
Advocate
Advocate

Hello all,

   I've been trying to find a way to automatically apply cutter comp to toolpaths labeled a certain way.  Is there a way to do a foreach search function of an NCProgram and apply Left comp value to the NCToolpaths that end in the string W/COMP?  Ive attached a screenshot here of what our structure looks like any help would be great.  Trying to go through every single NCProgram has become tedious at best.  Additionally, why are my NCPrograms showing a questionable yellow bubble when all my toolpaths have been collision checked and proven to be ok?  Just curious, any help would be appreciated  and thanks!

W_COMP.PNG

0 Likes
Accepted solutions (1)
2,816 Views
13 Replies
Replies (13)
Message 2 of 14

NanchenO
Collaborator
Collaborator

I use this macro to apply the correct compensation according to the machine type (full_radius or wear) and define a user variable that I use in the postpro to make sure that the correct one is activated.

 

FOREACH ent IN folder("NCProgram\Machine1") {
		ACTIVATE NCprogram $ent
		STRING nc = 'NCProgram\Cincinnati\' +$ent.Name
FOREACH tp in components(entity('ncprogram', '')) {
   IF $tp.RootType == 'nctoolpath' {
		EXPLORER SELECT Toolpath $tp NEW
		ACTIVATE TOOLPATH $tp.name
		EDIT TPPAGE SWCutterComp
		if $CNCCutterCompensation.Active == 1 {
			if $Toolpath.CNCCutterCompensation.Type == 'full_radius' {
				EDIT TOOLPATH $tp RECYCLE
				YES
				EDIT PAR 'Toolpath.CNCCutterCompensation.Type' 'wear'
				EDIT TOOLPATH $tp REAPPLYFROMGUI
				Yes
			DEACTIVATE TOOLPATH
			ACTIVATE TOOLPATH $tp.name
			}
		}
		EDIT TPPAGE SWUDSettings
		BOOL $chk = 0
		$chk = ERROR(entity('toolpath','').UserParameters.COMP)
		if $chk {
			EDIT USERPAR toolpath_strategy SELECT 'COMP'
			EDIT USERPAR toolpath_strategy  'normal' NAME "COMP"
			CREATE USERPAR toolpath_strategy $tp
			EDIT USERPAR toolpath_strategy $tp "COMP" "${CNCCutterCompensation.Type}"
			}
		}
		edit par "entity('toolpath','').userparameters.COMP" "${CNCCutterCompensation.Type}"
		DEACTIVATE TOOLPATH
	}
}

Works fine and I had no longer problems since the guys use it. Note that I made a special script in the postpros to check it:

 

function Compensation_fausse()
{
  // Interrupt processing if cutter compensation type is wrong in NCProgram (user parameter udp_COMP)
  if (GetParam("%p(udp_COMP)%") != "full_radius")
	{
	(MessageBox("Stop postprocessing: Cutter compensation wrong in" + GetParam("%p(Toolpath Name)%") + "  !", ppOk) == ppIdOk);
	UserError("Stop postprocessing: Cutter compensation wrong in" + GetParam("%p(Toolpath Name)%") + "  !");
	}
  return StandardResponse();
}

It's a bit tricky but could save a lot of troubles on the machines.

 

 

Olivier

0 Likes
Message 3 of 14

Eskondedo
Advocate
Advocate

I see what this macro does but I don't think this is what I am looking for.  If you look at this macro here I've got it looking at each NCProgram and only changing the comp when the toolname is labeled accordingly.  I'm trying to do the same thing but instead of the name look at the NC Toolpath and recognize whether the end of the name says W/COMP and turn on Left if it is and do nothing if it isn't.

 

Threadmill Comp.PNG

 

0 Likes
Message 4 of 14

NanchenO
Collaborator
Collaborator

If you already have a part of the solution, post it with your question, it is always faster than starting with nothing !

 

Of course, my macro does not do exactly what you want, but if you alter it, it could be a good basis to start... always better than nothing !

 

That's the way I made most of my macros: take a similar one, alter it, test it, make it available for other guys, as they did with the macro I used as a basis.

 

Olivier

Message 5 of 14

TK.421
Advisor
Advisor

try this-

 

STRING LIST programs = {}
FOREACH $ncP IN Folder ('NCProgram') {
        INT $Ok = add_last(programs, $ncp.name)  
}

INT c = 0
FOREACH tp IN programs {
    STRING LIST tpnames = extract(entity('ncprogram',$programs[$c]).nctoolpath, 'Name')
    INT $i = 0
    FOREACH toolpath IN $tpnames {
        INT has_comp = position(tpnames[$i], "W/COMP")
        IF $has_comp > 0 {
        ADD YOUR COMMAND HERE
        }    
        $i = $i + 1
    }
   

 

like @NanchenO said, use what you can off of the forum, and when you get something that works, repost it so others can use it too. Half of my macros are pasted together from things I've found here, and then changed to suit my needs. 

 

it is also important to go through it and understand what each command does. the debugger is pretty useful for that!

 

hope this helps


the numbers never lie
0 Likes
Message 6 of 14

Anonymous
Not applicable

The question mark is telling you that your program is not verified using a machine tool. If there is only one toolpath in the program you will get the blue check. 

Message 7 of 14

Eskondedo
Advocate
Advocate

Thank you for the help, I tried this macro this morning but it would appear Im not adding the correct command to change the comp vaule to left for when the list reaches a NCtoolpath with "W/COMP" in it.  I ran it through the debugger with a few different variants but to no avail.  I tried a variant with entity, I tried a variant with nctoolpath both produced the same error.  I'm using the summary area of powermill to find the correct parameter.  Am I formatting it incorrectly? Capture.PNG

 

Capture2.PNG

 

Capture3.PNG

 

0 Likes
Message 8 of 14

Eskondedo
Advocate
Advocate

Does this mean there is no way to create the blue check if more than one toolpath exists per NCprogram?

0 Likes
Message 9 of 14

TK.421
Advisor
Advisor

After much trial and error, and a visit to the old Delcam forum, I've got something that should work for you. It is a little persnickety, but I think it'll do the job. This works for the ACTIVE nc program only. I'm sure you can mod it to do all your nc programs should you choose.

 

Here is where it is goofy: When you create an NC program and add one toolpath to it, that becomes 'item 0'. The next one is 'item 1' and so on. Let's say you have 10 toolpaths in your NC program, and now you want to add another one (item 10 - remembering they start at 0) between item 3 and item 4. The one you add between 3 and 4 stays item 10. Powermill does not renumber the  toolpaths in the NC program, they stay what they are when first added to the NC program. This messes up the counter as it increases by 1 and 1000.    Just make sure your toolpaths are ordered how you want them when you add them to your nc program

 

INT i = 0 
INT item_num = 0
INT comp_num = 0 

FOREACH tp IN folder ('NCProgram') {
    STRING LIST tpnames = extract(entity('ncprogram','').nctoolpath, 'Name')
    FOREACH toolpath IN $tpnames {
        INT has_comp = position(tpnames[$i], "W/COMP")
        IF $has_comp > 0 {
			IF !is_empty(components(entity('ncprogram',''))) {
				IF components(entity('ncprogram',''))[0].RootType == 'nctoolpath' {
					EDIT NCPROGRAM ; ITEM $item_num COMPONENT $comp_num COMP_CODE RIGHT
				}
			} 
        }
        $i = $i + 1
		$item_num = $item_num + 1
		$comp_num = $comp_num + 1000
    }
}

 

As far as the colored tick, I dont know why it wouldn't be blue if all your toolpaths are blue (or purple. I think it's purple, but whatever).  pmill sees something it's unsure of. maybe it's a 2018 bug - who knows...

 

Let me know how this works for you

 


the numbers never lie
Message 10 of 14

Eskondedo
Advocate
Advocate

Thanks for the speedy response.  As far as the toolpath numbering we dont add toolpaths individually.  We send the entire folder as a whole to the NCprograms area.  If we need to add more later on we delete it and resend the entire folder, but thanks for the heads up.  I ran this just now and the macro does exactly what you said.  It doesn't however stop after running through the entire NCprogram.  The loop continues and when it restarts it finds that the expresison is already filled and errors.  I apologize for my ignorance here, When it comes to deep logic, or at least what I think is deep logic, macros im a serious noob.  Thanks again, I'd assume that all that is required is a stop gap after the macro reads every NCtoolpath in the NCprogram.

 

ERROR.PNG

0 Likes
Message 11 of 14

TK.421
Advisor
Advisor

"It doesn't however stop after running through the entire NCprogram."

 

I'll (try to) fix that.  I started as a noob too. I joined the old forum 5 years ago with no knowledge of code or logic and have been learning since then


the numbers never lie
Message 12 of 14

TK.421
Advisor
Advisor
Accepted solution

Here you go. works as it should for the active NC Program. Should work perfectly if you delete the NC Program and recreate it when there's a change.

 

INT i = 0 
INT item_num = 0
INT comp_num = 0 
STRING ncProg = entity('ncprogram','').name
STRING LIST ncP_toolpaths = extract(entity('ncprogram', ncProg).nctoolpath, 'Name')

FOREACH tp IN ncP_toolpaths {
	STRING tpName = $ncP_toolpaths[$i]
	INT has_comp = position(tpName, "W/COMP")
	IF $has_comp > 0 {
		IF !is_empty(components(entity('ncprogram',''))) {
			IF components(entity('ncprogram',''))[0].RootType == 'nctoolpath' {
				EDIT NCPROGRAM ; ITEM $item_num COMPONENT $comp_num COMP_CODE LEFT
			}
		} 
	}
	$i = $i + 1
	$item_num = $item_num + 1
	$comp_num = $comp_num + 1000
}

the numbers never lie
Message 13 of 14

Eskondedo
Advocate
Advocate

You're the man!! that worked beautifully! Now I can get it to cycle through all the NCprograms and I will be goldent the rest of the group will be on cloud nine with this!  Thanks a ton.

Message 14 of 14

Eskondedo
Advocate
Advocate

Finally got the cycle portion correct and here it is:

 

FOREACH $NCP IN FOLDER('ncprogram') {
activate NCPROGRAM $NCP
INT i = 0
INT item_num = 0
INT comp_num = 0
STRING ncProg = entity('ncprogram','').name
STRING LIST ncP_toolpaths = extract(entity('ncprogram', ncProg).nctoolpath, 'Name')


 FOREACH tp IN ncP_toolpaths {
  STRING tpName = $ncP_toolpaths[$i]
  INT has_comp = position(tpName, "W/COMP")
  IF $has_comp > 0 {
   IF !is_empty(components(entity('ncprogram',''))) {
    IF components(entity('ncprogram',''))[0].RootType == 'nctoolpath' {
     EDIT NCPROGRAM ; ITEM $item_num COMPONENT $comp_num COMP_CODE LEFT
   }
  }
 }
 $i = $i + 1
 $item_num = $item_num + 1
 $comp_num = $comp_num + 1000

 }
}

 

Thanks again for all  your help brother.