Jump to content

PCM Nested if syntax help


---
 Share

Recommended Posts

Greetings Code Ninjas!
I have a little code /PCM knowledge and need some help.

Here is an idea of what I am trying to do :

I have a program which inspects a part at two operations , lets just say : pre and post machining of a bore.

Before the first operation, machine the bore, I measure 2 circles and report the positions for machining reference, and also use at next operation reference information.
I have two mini plans with separate characteristics for each operation, and PCM to make the operator choose one.

I used PCM to output the .x and .y actuals of the positions at the first operation where this feature will be machined away; and output them to a .para file
The file is named from the u_field input ; essentially "work order#_serial number#" { e.g. 12345679_0123.para } in a folder in the inspectionDir().

When they run 2nd Op, It searches if file exists and reads it based on WO# and S/N#. I can get that much to work as intended.

However what I would like to do is :

1.) Search for WO_SN.para and read if found
2.) if it is not found, I would like to give the operator the option to input these manually from a hard copy report if .para is not found for whatever reason; just to bulletproof the process.
I have done so with inquireNumber(input from report - X Value, etc.) This writes to VARIABLE; which just populates theoretical circles to re-establish a missing feature : which is what the .para files does. (I understand this is a questionable machining and inspection practice - first time I've had to do it at current location 🙄 )
3.) I'd like to add the option to give the operator to also say NO to entering X & Ydata manually, and end with a message.

I'll enter my code here, this is the latest iteration which I know is clearly wrong, just having a go at it.
// MiniPlan Option List
//

MP=inquireList("Please Choose Operation # :           "+cr()+cr()+cr(),"OP 0020", "OP 0030")

// Run ID's
//

if MP=="OP 0020"
setRunID("OP 0020")
endif

if MP=="OP 0030"
setRunID("OP 0030")
endif

setRunID(MP)

// If OP 0030 ; Automagically Get Op 0020 actuals from saved file by WO# + SN#
//

FILE=fileExists(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para")

if MP=="OP 0030" then
	if FILE=="true" readPCMFile(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para") else
		if FILE=="false" then
			DATA=inquireList("No results found from OP0020, : Input Data Manually?", "Yes", "No")
			if DATA=="No" then 
     			message("Nope")
				cncBreak()
				if DATA=="Yes"
				OP0020_BTM_X=inquire("Please enter OP0020 R.6255 Position x1: 'X' Exact value from report")
				OP0020_BTM_Y=inquire("Please enter OP0020 R.6255 Position x1: 'Y' Exact value from report")
				OP0020_TOP_X=inquire("Please enter OP0020 R.6255 Position x2: 'X' Exact value from report")
				OP0020_TOP_Y=inquire("Please enter OP0020 R.6255 Position x2: 'Y' Exact value from report")
			endif
		endif
	endif
endif
This may be too many if statements for Calypso, but perhaps can be done in a .bat , etc.
This is not critical, I have simpler methods ; they just won't be as 'bulletproof/failsafe" etc.

Thanks everybody ! Hope this helps someone else as well.
Link to comment
Share on other sites

Hi Chris,

if you are letting the operater input the values, you have to make sure that they are using a "." not a "," , maybe this is not a problem in your location, in mine it is! 😃

I added a repeat loop after the input of the values to see if everthing is correct.
// MiniPlan Option List
//

MP=inquireList("Please Choose Operation # :           "+cr()+cr()+cr(),"OP 0020", "OP 0030")

// Run ID's
//

if MP=="OP 0020"
setRunID("OP 0020")
endif

if MP=="OP 0030"
setRunID("OP 0030")
endif

setRunID(MP)

// If OP 0030 ; Automagically Get Op 0020 actuals from saved file by WO# + SN#
//

FILE=fileExists(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para")

if MP == "OP 0030" then
	if FILE=="true" then
		readPCMFile(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para") 
	else
			DATA = confirm("No results found from OP0020, : Input Data Manually?", "Yes", "No")
			if DATA == "false" then 
     				message("Nope")
				cncBreak()
			else
				// Preset the Values of the parameters for using it in inquireParameterList
				OP0020_BTM_X = 0
				OP0020_BTM_Y = 0
				OP0020_TOP_X = 0
				OP0020_TOP_Y = 0
				repeat
				inquireParameterList("OP0020_BTM_X","Please enter OP0020 R.6255 Position x1: 'X' Exact value from report","OP0020_BTM_Y","Please enter OP0020 R.6255 Position x1: 'Y' Exact value from report","OP0020_TOP_X","Please enter OP0020 R.6255 Position x2: 'X' Exact value from report","OP0020_TOP_Y","Please enter OP0020 R.6255 Position x2: 'Y' Exact value from report")

				INPUTS = confirm("Are the inputs correct" + cr() + "OP0020_BTM_X = " + OP0020_BTM_X + cr() + "OP0020_BTM_Y = " + OP0020_BTM_Y + cr() + "OP0020_TOP_X = " + OP0020_TOP_X + cr() + "OP0020_TOP_Y = " + OP0020_TOP_Y + cr() + "Make sure the decimal seperator is a . (point)")
				until INPUTS == true
			endif
		endif
endif
I think this should work.
Link to comment
Share on other sites

// MiniPlan Option List
//
FILE=getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para"
DATA=""

MP=inquireList("Please Choose Operation # :           "+cr()+cr()+cr(),"OP0020","OP0030")
	selectCase MP
		case "OP0020"
			setRunID("OP 0020")
		case "OP0030"
				setRunID("OP 0030")
					if fileExists(FILE) then
						readPCMFile(FILE)
					else
						DATA=inquireList("No results found from OP0020, : Input Data Manually?", "Yes", "No")
							if (DATA=="No") or (DATA=="") then 
     							message("Nope")
								cncBreak()
							else
								OP0020_BTM_X=inquire("Please enter OP0020 R.6255 Position x1: 'X' Exact value from report")
								OP0020_BTM_Y=inquire("Please enter OP0020 R.6255 Position x1: 'Y' Exact value from report")
								OP0020_TOP_X=inquire("Please enter OP0020 R.6255 Position x2: 'X' Exact value from report")
								OP0020_TOP_Y=inquire("Please enter OP0020 R.6255 Position x2: 'Y' Exact value from report")
							endif
					endif
endSelect

Using caseSelect is much cleaner... This isn't exactly tested that well but it should do. Something to note, caseSelect does not like spaces. So you can see I changed OP 0020 to OP0020, your miniplan name can have spaces however, but I tend to name them exactly the same when I do this stuff.

Something else to consider.... What happens if the operator does not put anything in for your X and Y values? If you can, you should create default values... or if that doesnt apply to your situation each of those inquires should become a loop with a way of canceling the run if the operators do not input anything.
Link to comment
Share on other sites

Here's an example of some code I use everywhere that seems long but you only have to write it once if you do it well, this forces operators to select from a list. But also cancel at any point.
We don't let operators do anything that's not controlled.
cancelMess="		Invalid entry, Cancel or No selected.		"+cr()+cr()+cr()+ "		   Do you wish to end the program?		"
nextLoop=false
loopBreak=false
programCancel=false
selectionCheck=true
setupQuestion=""
if getRecordHead("operid") == "User"
		curMachID=getRecordHead("procid")
		curPalletID=getRecordHead("fixtid")
		curParaID=getRecordHead("startcomment")
			//------Start of main loop------
			repeat
				employNum=""
				mach=""
				pall="N/A"
				para=""
				loopBreak=false
					
					//-------------Machine Number Input Loop---------------------
						repeat
							loopBreak=false
							mach=inquireList("Choose CNC Machine (Last Entered: "+curMachID+")","A","B","C","D","E","G")
								if mach=="" then
									loopBreak=confirm(cancelMess)
											if loopBreak then
												nextLoop=false
												programCancel=true
											endif
								else
									loopBreak=true
									nextLoop=true
								endif
						until loopBreak
					
					//-------------Run Parameter Input Loop---------------------
					if nextLoop then
						repeat
							loopBreak=false
							para=inquireList("Select Run Parameters (Last Entered: "+curParaID+")","Firstoff","Lastoff","ToolChange","OIS","Recheck","","GrooveOnly","HolesOnly","","Setup","Setup Recheck")
								if (para=="Setup") or (para=="Setup Recheck") then
									setupQuestion=confirm("You have selected Setup or Setup Recheck: "+cr()+cr()+"Setup will run the entire program"+cr()+"Setup Recheck will only run whatever is selected in current selection."+cr()+cr()+"This is NOT to be used for anything other than setting up machines. Are you sure this is what you want? Selecting No will allow you to select again, or cancel the run")
								endif
								if (para=="") or (setupQuestion==false) then
									loopBreak=confirm(cancelMess)
										if loopBreak then
											nextLoop=false
											programCancel=true
										endif
								else
									loopBreak=true
								endif
						until loopBreak
					endif

				//Displays the selections and asks if the operator is happy with them
				if programCancel==false
					selectionCheck=executeCode("ICCDialog confirm: 'You selected:"+cr()+cr()+cr()+cr()+"Machine Number:				<u><c:red>"+mach+"</u></c>"+cr()+cr()+cr()+"Run Identifier:					<u><c:red>"+para+"</u></c>"+cr()+cr()+cr()+cr()+"Is this correct?' asRichText")
						if selectionCheck==false
							loopBreak=confirm(cancelMess)
									if loopBreak then
										programCancel=true
									endif
						else
							loopBreak=true
						endif
				endif
			until loopBreak
			
		//------Skips to here if Cancel is selected at any point in the selection menu's at program start------
		if programCancel then
			message("You have chosen to cancel the program")
			cncBreak()
		else

			//-----------Sets the run based on selection from Run Parameter Loop
			if (para == "Recheck") or (para == "Setup Recheck") then
				addCF(safetyCheckPoint)
				else
					selectCase para
						case "GrooveOnly"
							setRunID("GrooveOnly")
						case "HolesOnly"
							setRunID("HolesOnly")
						caseElse
							setRunID("FullProgram")
					endSelect
			endif
		
			//-------Sets the header data from the selections chosen by the operator
				setRecordHead("vda_signature",employNum)
				setRecordHead("procid",mach)
				setRecordHead("fixtid",pall)
				setRecordHead("startcomment",para)
		endif
endif
Link to comment
Share on other sites

Great Help guys.

I've tried Florian's code, I like it. Excellent work mate.
I've thought about operator input error. I obviously need more PCM training. I did sign up for the class, I think I'm the only one on the waitlist.

The only thing that didn't work, is if the operator chooses NO to enter data manually.

However with Michael's code above, I should be able to figure this out.

Thanks gents, I'll report back.

Edit .. Tested Michael's code: works as intended. If Operator Choose "NO", Inspection stops.
However I do like Florian's inquire input box. I will try some pieces of both.

Thank you code ninjas !

Cheers ! 🙂
Link to comment
Share on other sites

One other minor conundrum here guys:

All 3 codes above cause Calypso to prompt at end of run " Op 0020 circle has not been measured and is activated by Op0020 position characteristic .. blah,blah, etc. )

Whether I run from features or characteristic list ( I normally run from features list) it is measuring Op 0020 feature and position characteristic. I even put a condition if MP="OP0020" to skip the characteristic ; doesn't work ...

Also I did not notice a way to set run from 'char' or 'features' list with PCM, I'm aware of setCF(), but is there a way to set always run from 'char list' with PCM ?

Thanks again guys.
Link to comment
Share on other sites

Yes Calypso does that, it's annoying.

That position must be using your Op 0020 circle (maybe you filled out the DRF with an alignment instead of actually filling in the datums) so just simply add the diameter or whatever it is you're reporting on that circle normally to your mini-plan and till stop warning you about that.

I don't know why Calypso won't just automatically do it without asking but we've run into it to with position characteristics and alignments used rather than properly filling out the DRF.

Edit: Helpful tip I wish I knew much sooner. Ctrl+Y is an interupt...

so when you screw up writing a repeat loop and it goes on infinitely you can cancel it, without using task manager. It will stop most things in Calypso.
Link to comment
Share on other sites

Please sign in to view this quote.

Michael,

thanks for the info. I've made sure those Op 20 positions are now not refencing an alignment, or other feature from Op 0030. I've put the conditions on Op 20 position char.'s and even used if MP==Op0030 setCF(Op30Char1,2,3,4 etc) Neither mini-plan has any secondary alignment highlighted. I even moved the group char (only 2 dias and 2 positions) to end of Char List. These 2 Op0020 positions print out as well as Op 0030 char.'s however the Op 0020 radii sizes do not.

I will try filling out the DRF in the position char. ....

Thank you again !

I'm aware of the Ctrl + Y ; I've used it on occasion.


UPDATE : so as an update, something was definitely activating OP20 Positions, I removed all code to ensure mini-plans alone dont activate it - they do not. Well I believe the culprit was I was defining the variables BTM_X BTM_Y ,etc. then using an if Op 20 statement to output them. I also had to add if OP 20 statement before assign the variables. Now it works as intended so far.
positionCMM(300,-800,-100,"Z","X","Y")

//--------------------Get position deviations--------------------------------------------

if MP=="OP0020"
BTM_X=formatL((getActual("OP 0020 R .6255 Position x1").actual.x),0,5)
BTM_Y=formatL((getActual("OP 0020 R .6255 Position x1").actual.y),0,5)
TOP_X=formatL((getActual("OP 0020 R .6255 Position x2").actual.x),0,5)
TOP_Y=formatL((getActual("OP 0020 R .6255 Position x2").actual.y),0,5)
endif

// Delete file if it exists; or if has been run previously and is being re-ran , etc.
deleteFile(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para")

getParameterNamed("MP")
if MP=="OP0020"
addToFile(getActualInspectionDir()+"\PCMTEST\"+getRecordHead("u_field7")+"_"+getRecordHead("u_field10")+".para","OP0020_BTM_X=",BTM_X+cr(),"OP0020_BTM_Y=",BTM_Y,+cr(),"OP0020_TOP_X=",TOP_X+cr(),"OP0020_TOP_Y=",TOP_Y)
endif






By the way; is there a way to set RunFrom, Char List or Feat List with PCM ?

Thanks again All !!
Link to comment
Share on other sites

Hi Chris,

you might don't need it anymore but the reason why it was not working was, if you prove something true or false in a if condition then you have to write true or false without quotaition marks.

Like this:

if DATA == false then


NOT like this:

if DATA == "false" then
Link to comment
Share on other sites

 Share

×
×
  • Create New...