You are not logged in.

aperture147

Beginner

  • "aperture147" started this thread

Posts: 17

Location: Vietnam

Occupation: DevOps

  • Send private message

1

Thursday, June 27th 2019, 4:10pm

Is there any efficient way to clear all children of a layer/ScrollArea?

I'm making a ScrollArea layer which needs to update its content frequently. I find that there is no function to remove all of children of the scrollarea and layer in general. My workaround way is removing the layer (which can remove its children too) and recreate a new one then add the new content to it, but this way is too long.
Thanks for your helping.
KRPano Showcases:
Showcase 1
Showcase 2

Fernando

Intermediate

Posts: 330

Location: Habana, Cuba

Occupation: Architect, Photographer.

  • Send private message

2

Sunday, June 28th 2020, 10:23pm

Hi, my solution is to set a property for all elements inside scrollarea, example group=scrollingobj
Then, adapting a solution from this forum, remove all layers whith group=scrollingobj

Source code

1
2
3
4
5
6
7
8
9
10
11
<action name="loop_all_layers">
sub(i,layer.count,1);
loop_all_layers_next(get(i));
</action>
<action name="loop_all_layers_next">
if(layer[%1].grupo == scrollingobj,
removelayer(%1, true);
);
dec(i);
if(i GE 0, loop_all_layers_next(get(i)) );
</action>

aperture147

Beginner

  • "aperture147" started this thread

Posts: 17

Location: Vietnam

Occupation: DevOps

  • Send private message

3

Wednesday, July 8th 2020, 5:30am

Hi, my solution is to set a property for all elements inside scrollarea, example group=scrollingobj
Then, adapting a solution from this forum, remove all layers whith group=scrollingobj

Source code

1
2
3
4
5
6
7
8
9
sub(i,layer.count,1);
loop_all_layers_next(get(i));


if(layer[%1].grupo == scrollingobj,
removelayer(%1, true);
);
dec(i);
if(i GE 0, loop_all_layers_next(get(i)) );
Thanks! It seems like there is no better way to do this.
KRPano Showcases:
Showcase 1
Showcase 2

Tuur

Sage

Posts: 3,839

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

4

Wednesday, July 8th 2020, 2:00pm

Hi,

two options here:

Source code

1
2
3
4
5
6
for(set(i,0), i LT layer.count, inc(i),
 if(layer[get(i)].grupo == scrollingobj,
     removelayer(get(layer[get(i)].name), true);
     dec(i);
   );
);


or

Source code

1
2
3
4
5
for(sub(i,layer.count,1), i GE 0, dec(i),
 if(layer[get(i)].grupo == scrollingobj,
     removelayer(get(layer[get(i)].name), true);
   );
);


Hope it helps
Tuur *thumbsup*

This post has been edited 1 times, last edit by "Tuur" (Jul 8th 2020, 2:32pm)


5

Wednesday, July 8th 2020, 2:09pm

cant you just removelayer() with children?
or do you want to keep the scroll layer container ?

instead of setting a marker
you can also traverse all layers and check for the parent

Source code

1
2
3
4
5
for(sub(i,layer.count,1), i GE 0, dec(i),
 if(layer[get(i)].parent == "my_scroll_layer",
     removelayer(get(layer[get(i)].name), true); // with children
   );
);

Tuur

Sage

Posts: 3,839

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

6

Wednesday, July 8th 2020, 2:30pm

Quoted

instead of setting a marker
you can also traverse all layers and check for the parent


In some cases that could work as well of course
.. but then it will delete all with the same parent, which could not be ideal in all cases.


Source code

1
if(layer[get(i)].parent == "my_scroll_layer",


double quotes?? *blink* *g*

Tuur *thumbsup*