macro help please! Check if all NCs are written...

macro help please! Check if all NCs are written...

rui.ramosQ3G7Y
Explorer Explorer
397 Views
2 Replies
Message 1 of 3

macro help please! Check if all NCs are written...

rui.ramosQ3G7Y
Explorer
Explorer

Hello Guys,

I wounder if someone could help me out here, to see what am I doing wrong.

Im trying to build this macro to check if all NCs are written, if not, prompts a message in order for the user to see.

otherwise if all NCs are written it closes pmill.

 

macro:

DIALOGS ERROR OFF
DIALOGS MESSAGE OFF

 

FOREACH $nc IN FOLDER('ncprogram') {

IF $nc.Status == "not_written" {

message WARN "Some NCs are not written!!" + " " +CRLF+ " NC: " + $nc.name

} elseIF $nc.Status == "written" {

MESSAGE INFO "all NCs are written!!"

Exit

}
}
}

DIALOGS ERROR On
DIALOGS MESSAGE On

 

thanks in advance!

 

Good Day!

 

0 Likes
Accepted solutions (1)
398 Views
2 Replies
Replies (2)
Message 2 of 3

TK.421
Advisor
Advisor
Accepted solution

here you go! i changed your code a little and marked it up so you can see my thinking.

// Turn off messages
DIALOGS ERROR OFF
DIALOGS MESSAGE OFF

// Initialize some variables
BOOL b = false
STRING s = ""

// Loop through NC Programs, checking for any that
// are unwritten. If there's an unwritten program, 
// make the BOOL true, get the name of the program
// and exit the loop
FOREACH $nc IN FOLDER('ncprogram') {
	IF $nc.Status == "not_written" {
		$b = true
		$s = $nc.Name
		BREAK
	}
}

// If the BOOL is true, pop the message warning the user,
// if it is false, save and close the project
IF $b == true {
	MESSAGE WARN "Some NCs are not written!!" + " " + CRLF + " NC: " + $s
	DIALOGS ERROR ON
	DIALOGS MESSAGE ON
} ELSE {
	DIALOGS ERROR ON
	DIALOGS MESSAGE ON
	PROJECT SAVE 
	EXIT
}

the numbers never lie
0 Likes
Message 3 of 3

rui.ramosQ3G7Y
Explorer
Explorer
Perfect!!
thank you very much!!

have a nice day!
0 Likes