[Macro] Automatic selecting the corresponding possprocessor

[Macro] Automatic selecting the corresponding possprocessor

Anonymous
Not applicable
1,941 Views
23 Replies
Message 1 of 24

[Macro] Automatic selecting the corresponding possprocessor

Anonymous
Not applicable

Hello all forum member!

I am a PowerMill programmer but just an amateur in creating macro, I have an issue that would very much like  your helping

My program is using 2 head ---1 head name" TIC " for roughing and another one name "TOE" head for Finishing.with every Head , I use 2 difference possprocessor for coding.

I want when I run the macro before creating nc program, it will be select the correct possprocessor automatically. I do this base on the difference machine that I am using in toolpaths.

tic.jpg

 

toe.jpg

 

I have created a macro :

 

FOREACH tp in folder('Toolpath') {
If MachineName= "Parpas_TOE_3-2-2016" {
FORM NCPREFERENCES
EDIT NCPROGRAM PREFERENCES TAPEOPTIONS FILEOPEN
"C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"
PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TOE_3-2-2016"
EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
EDIT NCPROGRAM PREFERENCES PROJECT ON
NCPREFERENCES ACCEPT
}
If MachineName= "Parpas_TIC" {
FORM NCPREFERENCES
EDIT NCPROGRAM PREFERENCES TAPEOPTIONS FILEOPEN
"C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"
PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TIC"
EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
EDIT NCPROGRAM PREFERENCES PROJECT ON
NCPREFERENCES ACCEPT
}
}

 

Here is its error when I run the Macro

error.jpg

 

Please help me you can. Thank you very much!

 

 

 

0 Likes
1,942 Views
23 Replies
Replies (23)
Message 2 of 24

kukelyk
Advisor
Advisor

Try this:

FOREACH tp in folder('Toolpath') {
	FORM NCPREFERENCES
	If $tp.machinetool.name= "Parpas_TOE_3-2-2016" {
		
		EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"
		PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
		EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TOE_3-2-2016"
	}
	If $tp.machinetool.name= "Parpas_TIC" {
		EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"
		PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
		EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TIC"

	}
	EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
	EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
	EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
	EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
	EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
	EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
	EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
	EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
	EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
	EDIT NCPROGRAM PREFERENCES PROJECT ON
	NCPREFERENCES ACCEPT
}
0 Likes
Message 3 of 24

Anonymous
Not applicable

 Kukelyk,

Thank you very much for your helping , however when I run your macro , it still has an error

ERROR2.jpg

By the way, to get safer when coding,  what do I should do if I want to change my condition :

-if Machine TOOL  = "Parpas_TOE_3-2-2016" AND ToolNumber>20, select  "C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"

-if Machine TOOL  = "Parpas_TIC"" AND ToolNumber<20, select"C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"

Hopefully received your helping.

THANK YOU VERY MUCH!

 

 

0 Likes
Message 4 of 24

kukelyk
Advisor
Advisor

Sorry, my mistake ('==' instead of '='):

 

FOREACH tp in folder('Toolpath') {
	FORM NCPREFERENCES
	If $tp.machinetool.name == "Parpas_TOE_3-2-2016" {
		
		EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"
		PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
		EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TOE_3-2-2016"
	}
	If $tp.machinetool.name == "Parpas_TIC" {
		EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"
		PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
		EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TIC"

	} 
	EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
	EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
	EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
	EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
	EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
	EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
	EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
	EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
	EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
	EDIT NCPROGRAM PREFERENCES PROJECT ON
	NCPREFERENCES ACCEPT
}

 

Message 5 of 24

Anonymous
Not applicable

Same problem , kukelyk

error3.jpg

Hopefully continue receive your helping!Thank you very much!

 

0 Likes
Message 6 of 24

kukelyk
Advisor
Advisor

I have tested this code right now, and it works. What PM version? First try restarting Pmill. 

0 Likes
Message 7 of 24

Anonymous
Not applicable

I will upgrade to PM 2018 soon but now I'm using PM 2016. Would you help me edit the macro file if my mine is early version than yours?

Thank you very much!

 

0 Likes
Message 8 of 24

kukelyk
Advisor
Advisor

I have tested it on pm2016, with no problems

0 Likes
Message 9 of 24

Anonymous
Not applicable

 kukelyk,

Please see the Video file of the problem and give me advice ! 

 

https://www.youtube.com/watch?v=8W9vOY6RBB8&feature=youtu.be

 

Thank you very much!

 

 

0 Likes
Message 10 of 24

kukelyk
Advisor
Advisor

Try run macro in debug mode line by line

0 Likes
Message 11 of 24

Anonymous
Not applicable

This is what happen in debug

deburg.jpg

Thank you very much!

 

0 Likes
Message 12 of 24

kukelyk
Advisor
Advisor

What happen if You write it:

PRINT = $toolpath.machinetool.name

to the command window (and there is an active toolpath)?

0 Likes
Message 13 of 24

Anonymous
Not applicable

It show "Parpas_TIC"

TIC.jpg

0 Likes
Message 14 of 24

urizenYHS3W
Advocate
Advocate

Put a break point on line3 in the macro. Run the debugger until it stops on the breakpoint check that tp.machinetool is actually set.

 

PRINT = entity_exists(tp.machinetool)

 

run the macro until it stops at the breakpoint again, and repeat the check. You probably have a toolpath where the machinetool isn't set.

 

 

0 Likes
Message 15 of 24

kukelyk
Advisor
Advisor

Ok, I know what is the problem.

Try this one:

FOREACH tp in folder('Toolpath') {
	IF member($tp._keys, "machinetool") {
		FORM NCPREFERENCES
		If $tp.machinetool.name == "Parpas_TOE_3-2-2016" {
			EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"
			PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
			EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TOE_3-2-2016"
		}
		If $tp.machinetool.name == "Parpas_TIC" {
			EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"
			PATHSELECTOR PATHLISTS LISTCHANGE OUTPUT PATHSELECTOR PATHLISTS CLEAR PATHSELECTOR PATHLISTS ADD "D:\PMill_PShape_Master_Reference\Code_Files"
			EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TIC"
		} 
		EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
		EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
		EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
		EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
		EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
		EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
		EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
		EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
		EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
		EDIT NCPROGRAM PREFERENCES PROJECT ON
	} ELSE {
		//none of them used..
	}
}
0 Likes
Message 16 of 24

Anonymous
Not applicable

Dear!

Thank you very much for your helping, I'm sorry for late feedback because I finish my work shift. it look like to help me touch my target but still have some issue , please take a little bit time let me present my whole problem

1.As I said, I have a list of toolpaths , among them, I have set 2 machine name "Parpas_TOE_3-2-2016" and "Parpas_TIC" in my toolpath setting.
2.Now, I want to run the macro (that is the macro  I would like your help).

After reference and try running all your Macro,This is the Macro that I edited, (but it still not  make me satisfy!!!!!!!!)

 

FOREACH tp in folder('Toolpath') {
IF member($tp._keys, "machinetool") {
If $tp.machinetool.name == "Parpas_TIC" {
EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TIC_5ax_v10.pmoptz"
FORM NCPREFERENCES
EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TIC"
EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
EDIT NCPROGRAM PREFERENCES PROJECT ON
NCPREFERENCES ACCEPT
}
If $tp.machinetool.name == "Parpas_TOE_3-2-2016" {
EDIT NCPROGRAM PREFERENCES TAPEOPTIONS "C:\dcam\config\ductpost\Parpas_H530_TOE_5ax_v7.pmoptz"
FORM NCPREFERENCES
EDIT NCPROGRAM PREFERENCES MACHINETOOL "Parpas_TOE_3-2-2016"
EDIT NCPROGRAM PREFERENCES WORKPLANE "Mfg"
EDIT NCPROGRAM PREFERENCES MODELLOCATION "ML"
EDIT NCPROGRAM PREFERENCES CONNECTION MOVE_ROTATE
EDIT NCPROGRAM PREFERENCES TOOLCOORDS TIP
EDIT NCPROGRAM PREFERENCES MACHINECLEARANCE .5
EDIT NCPROGRAM PREFERENCES HOLDERCLEARANCE 0.05
EDIT NCPROGRAM PREFERENCES SHANKCLEARANCE 0.01
EDIT NCPROGRAM PREFERENCES FIXTUREOFFSET NAME "1"
EDIT NCPROGRAM PREFERENCES FILEMASK "0000.H"
EDIT NCPROGRAM PREFERENCES PROJECT ON
NCPREFERENCES ACCEPT
} ELSE {
//none of them used..
}
}
}

 

 

3.After runing Macro, I will create the nc program:

nc1.jpg

 

This is nc program setting that I created after running Macro:

 

tic1.jpgtoe2.jpg

 

All of them using same machine and same possprocessor. That isn't what I want. I want IN NC PROGRAM ALSO USING THE SAME MACHINE IN TOOLPATH SEETING AND CORRECT POSSPROCESSOR FOR EVERY MACHINE!

Please take time help me for REVIEW and Edit them when you available, I really appreciate your helping!

Thank you very much!

 

 

0 Likes
Message 17 of 24

urizenYHS3W
Advocate
Advocate
EDIT NCPROGRAM PREFERENCES ...

Sets the default value for all NCPROGRAMS you need to change the values on the individual NCPROGRAMs. So instead of looping over the toolpaths you need to loop over the NC Programs

 

FOREACH prog IN folder('ncprogram) {
  IF size(components(prog)) != 1 {
     PRINT "NCProgram should only have 1 toolpath"
     MACRO ABORT
  }
  OBJECT nctp = components(prog)[0] {
  ENTITY tp = entity('toolpath',nctp.name)
  IF tp.machinetool.name == 'Parpas_TIC' {
    $prog.HolderClearance = .5
    // 
  } elseif ... {
  }
  break;
 }
0 Likes
Message 18 of 24

kukelyk
Advisor
Advisor

@urizenYHS3W has right,

If You edit the preferences two times in a row, then You set it only once. You cannot store two different cases here.

So the best way to do what You want is the next:

In a loop

    -create ncprogram, append the toolpath for that

    -check if the toolpath has machine setting.

        if yes, then set the postprocessor

        if no, than ask the user, and set the postprocessor

   -set some more ncprogram options

 

Note, that in this case You should not set the postprocessor in the Preferences form.

 

 

Or, if You already have some ncprograms without correct postrocessor setting, then use what @urizenYHS3W suggests

Message 19 of 24

NanchenO
Collaborator
Collaborator

I use this to post a program to two different machines, using each time the correct PP, path and file extension:

 

BOOL $repOK = 0
BOOL $OK = 0
STRING $Tp_Workplane = ""
EXPLORER SELECT FOLDER "NCProgram\Cincinnati" NEW
DEACTIVATE NCProgram
ENTITY LIST $ents = INPUT ENTITY MULTIPLE ncprogram "Selection des programmes"
FOREACH $nc IN $ents {
	ACTIVATE NCProgram $nc.Name
	// Check if workplane defined + if multi axis
	$repOK = ERROR $entity('ncprogram','').OutputWorkplane.Name
	if $repOK {
		MESSAGE ERROR nc.Name + " : Pas de repere de sortie defini !!!"
		RETURN
	}
	//PRINT $entity('ncprogram','').MultiAxis
	//IF $entity('ncprogram','').MultiAxis == 1 {
	FOREACH $Tp IN COMPONENTS($Nc) {
		IF LCASE($Tp.RootType) == 'nctoolpath' {
		// Get the toolpaths workplane name
		PRINT $Tp.Name
		//$Err = ERROR($entity('toolpath',$Tp.name).workplane.name)
			//IF NOT $Err {
				$Tp_Workplane = $entity('toolpath',$Tp.name).workplane.name
			//}
		// Exit Loop
        //BREAK
			IF $Tp_Workplane != $entity('ncprogram','').OutputWorkplane.Name {
				MESSAGE ERROR nc.Name + " : Programme 5 axes, controler le repere de " + Tp.name + " !!!"
				
				RETURN
			}
		}
	}
	// Cin 3x
	EDIT NCPROGRAM SELECTED FOLDER "P:\DNCNET\DNCNET_I\"\r
	NCSELECTED APPLY\r
	EDIT NCPROGRAM SELECTED FILEMASK  P:\DNCNET\DNCNET_I\{ncprogram}.tap
	NCSELECTED APPLY\r
	EDIT NCPROGRAM SELECTED TAPEOPTIONS "P:\Powermill\Post-processeurs\PM_CINCINNATI_A950_V1_0_1.pmoptz"
	NCSELECTED ACCEPT\r
	EDIT NCPROGRAM PREFERENCES CLIMBLEFTCOMP ON
	KEEP NCPROGRAM SELECTED\r
	YES\n
	// Cin 5x
	EDIT NCPROGRAM SELECTED FOLDER "P:\H5_800XT\"\r
	NCSELECTED APPLY\r
	EDIT NCPROGRAM SELECTED FILEMASK  P:\H5_800XT\{ncprogram}.PUN
	NCSELECTED APPLY\r
	EDIT NCPROGRAM SELECTED TAPEOPTIONS "P:\Powermill\Post-processeurs\PM_CINCINNATI_ACRAMATIC_V1_0_1.pmoptz"\r
	NCSELECTED ACCEPT\r
	KEEP NCPROGRAM SELECTED\r
	YES\n
}
DEACTIVATE NCProgram

I basically correct all parameters and post the program to one machine and then correct them for the othre machine and post to it.

 

If you modify the macro to ask the user at the beginning and make a condition, the macro will then, according to the user's answer, correct the parameters to put it to the correct machine.

 

If you have a look at the first machine, I also make sure that the program's workplane is correctly defined, since it is a 3 axis machine. You can use such a macro to make all needed checks before posting. Just make the macro "sexy" enough to make sure that your guys will always use it.

 

Olivier

 

0 Likes
Message 20 of 24

Anonymous
Not applicable

Dear all,

Thank you all for your helping but I still not get my purpose.

I do this because I don't  want to get confuse in programming. My program usually have a lot of toolpaths (over 100) . According to our company template, I make 1 nc program for each toolpath so that mean I have to create a lot of nc program. So I don't want to set machine tool ,postprocessor and  some other things for each nc program , this will lead to  make confuse and take more time.

I already have 2 separate macro for each machine tool and possprocessor. IT IS running OK right now, but sometime, I and my Guys still have wrong machine tool when the program have too many program.

That's why I would like to look for a better Macro. Hopefully all of you could be help me continue fix this situation.

Thank you very much!

 

0 Likes