Applying action to all graphics on card

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Applying action to all graphics on card

Post by xfratboy »

Yet another newbie question here. I've been playing around with graphic objects and I would like to figure out an easy way to set properties of every graphic on my card (e.g. height, width, backgroundcolor). For example, let's say I have 2 ovals, two polygons, and two rectangles, on my card. How could I apply the same action to every graphic on the card without having to write the same command for each object, e.g.
set the height of graphic oval1 to the height of graphic oval1 +10
set the height of graphic oval2 to the height of graphic oval2 +10
set the height of graphic poly1 to the height of graphic poly1 +10
set the height of graphic poly2 to the height of graphic poly2 +10
set the height of graphic rect1 to the height of graphic rect1 +10
set the height of graphic rect2 to to the height of graphic rect2 +10

I know there must be a way to get a list of every graphic on a card then loop through that list, but I don't know what I'm doing. Any pointers would be greatly appreciated.
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Applying action to all graphics on card

Post by jmburnod »

Welcome

You can do it in a loop with a list

Code: Select all

on ResizeSomeG
   put "oval1,oval2,poly1,poly2,rect1,rect2" into LesG
   repeat with i = 1 to the num of items of LesG
      put item i of LesG into UnG
      set the height of grc UnG to (the height of grc UnG) +10
   end repeat
end ResizeSomeG
or for all grcs on cd

Code: Select all

on ResizeAllG
   repeat with i = 1 to the num of grcs
      set the height of grc i to (the height of grc i) +10
   end repeat
end ResizeAllG
Regards
Jean-Marc
https://alternatic.ch
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Applying action to all graphics on card

Post by bn »

xfratboy,
xfratboy wrote:I know there must be a way to get a list of every graphic on a card
if you are shure you want to set this for every graphic then you could say

Code: Select all

repeat with i = 1 to the number of graphics
   set the width of graphic i to the width of graphic i + 10
end repeat
regards
Bernd
xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Re: Applying action to all graphics on card

Post by xfratboy »

Perfect! Thanks to all.
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Applying action to all graphics on card

Post by bn »

xfratboy,
all the thanks go to Jean-Marc. When I posted I somehow did not realize he had also posted the handler for every graphic on the card
regards
Bernd
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Applying action to all graphics on card

Post by jmburnod »

Bernd,

I am so happy to have be faster :D

Jean-Marc
https://alternatic.ch
xfratboy
Posts: 97
Joined: Fri Mar 05, 2010 9:09 pm

Re: Applying action to all graphics on card

Post by xfratboy »

I have noticed something weird that perhaps the great Bernd or Jean-Marc could answer. Why does this only work once? I have this:

Code: Select all

on IncreaseObjectSize
 put "ObjBall,ObjOval,ObjLine,ObjDiamond,ObjSquare" into myObjectList
   repeat with i = 1 to the number of items of myObjectList
      put item i of myObjectList into UnG
      if the height of graphic UnG on stack "untitled 3" >400 then next repeat
      set the height of graphic UnG on stack "untitled 3" to the height of graphic UnG + 5
      set the width of graphic UnG on stack "untitled 3" to the width of graphic UnG +5
      end repeat
end IncreaseObjectSize
The first time it runs it seems to work. But clicking a second time does nothing. I'm executing the handler from a scrollbar button like this:

Code: Select all

on scrollbarLineDec
      IncreaseObjectSize
end scrollbarLineDec
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Applying action to all graphics on card

Post by bn »

Jean-Marc,

at least I made an honorable second place, not bad :)

regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Applying action to all graphics on card

Post by bn »

xfratBoy,

did you set the lineInc (depending on your preferences it could be called "on arrow click") in the inspector -> basic propterties -> Scroll distance? for me it defaulted to 0, when I set it to 1 or any other value it works for me.

regards
Bernd
Post Reply