Macro help. entity list if is_empty

Macro help. entity list if is_empty

LasseFred
Collaborator Collaborator
1,329 Views
9 Replies
Message 1 of 10

Macro help. entity list if is_empty

LasseFred
Collaborator
Collaborator

Hello.

 

I simply got into a problem.
I can't exactly figure out how to do this.

I want to check if my list: Selected_ncprogram is empty if it is select all NCPrograms.

I came up with this:

		ENTITY LIST Selected_ncprogram=explorer_selected_entities()
	
		IF is_empty(Selected_ncprogram) {
			ENTITY List Selected_ncprogram = folder('NCProgram')
		}

		STRING LIST tools = {}
		FOREACH $nc IN $Selected_ncprogram {
               ........

thanks in advance...

 

 

______________________
Lasse F.
0 Likes
Accepted solutions (2)
1,330 Views
9 Replies
Replies (9)
Message 2 of 10

LasseFred
Collaborator
Collaborator

Ups sorry.. 

 

The problem is my variable "Selected_ncprogram" is empty after my bracket.

______________________
Lasse F.
0 Likes
Message 3 of 10

TK.421
Advisor
Advisor

you have to populate your list after you create it:

 

STRING LIST selected_ncprogram = {}
FOREACH ncp IN explorer_selected_entities() {
   INT $i = add_last(selected_ncprogram, ncp.name)
}

Now you can go through your list:

FOREACH ncp IN selected_ncprogram {
   do whatever
}

the numbers never lie
Message 4 of 10

TK.421
Advisor
Advisor

if you simply want to check if your list is empty you can get the size:

 

INT i = size(selected_program)


the numbers never lie
0 Likes
Message 5 of 10

LasseFred
Collaborator
Collaborator

thanks for the answer. i am looking for something else.

if i "explore select" some nc programs the macro works fine.

ENTITY LIST Selected_ncprogram=explorer_selected_entities()

But if i dont have some nc programs selected, then list all my nc programs.

with this macro code:

 

 

IF is_empty(Selected_ncprogram) {
ENTITY List Selected_ncprogram = folder('NCProgram')
}

But after that curly brackets } there is end of my IF is_empty. the macro "delete all my listed things in my list Selected_ncprogram"

 

 

all the code. 

	ENTITY LIST Selected_ncprogram=explorer_selected_entities()
		
	IF is_empty(Selected_ncprogram) {
			ENTITY List Selected_ncprogram = folder('NCProgram')
	}

 

______________________
Lasse F.
0 Likes
Message 6 of 10

TK.421
Advisor
Advisor

sorry, i misunderstood.

 

try this:

	ENTITY LIST Selected_ncprogram=explorer_selected_entities()
	
INT i = size(Selected_ncprogram) IF $i == 0 { ENTITY List Selected_ncprogram = folder('NCProgram') }

the numbers never lie
0 Likes
Message 7 of 10

LasseFred
Collaborator
Collaborator

Sorry it doesn't work.

it throws away all the listed variables when it does the last curly bracket }

 

	ENTITY LIST Selected_ncprogram=explorer_selected_entities()
	
        INT i = size(Selected_ncprogram)
	IF $i == 0 {
			ENTITY List Selected_ncprogram = folder('NCProgram')
			// it listed all the nc programs
	}
			// throws all the listed variables away

 

______________________
Lasse F.
0 Likes
Message 8 of 10

Anonymous
Not applicable
Accepted solution

Read the "Scope of variables" in PowerMill help

ENTITY LIST Selected_ncprogram=explorer_selected_entities()
	
        INT i = size(Selected_ncprogram)
	IF $i == 0 {
		//	ENTITY List Selected_ncprogram = folder('NCProgram')
		$Selected_ncprogram = folder('NCProgram')
			// it listed all the nc programs
	}
0 Likes
Message 9 of 10

TK.421
Advisor
Advisor
Accepted solution

sorry, I should've paid closer attention. I'm glad you've got an answer. My code should've been something like this:

IF $i == 0 {
  $selected_program = folder(ncprogram)
}

since the variable is already defined outside the loop. i think by re-initializng it inside the loop, it does not carry through once the loop ends.  Glad you got there!


the numbers never lie
0 Likes
Message 10 of 10

LasseFred
Collaborator
Collaborator

Thanks to your both.

i have forgot all about re-initializing in {curly-brackets}.

it's been some time since i last worked with macro.

but when you get started again. it's like riding a bike 😉

 

______________________
Lasse F.