Page 1 of 1

Script: select all objects at once

Posted: Sun May 17, 2015 7:33 am
by pderks
This handler in my central lib stack selects all fields, buttons, … at once.

Message box in: SAO "F"
Message box out: select fld 1 and fld 2 and fld 3 and fld 4

Code: Select all

on SAO BtOrFd
   choose Pointer Tool
   if BtOrFd = "B"
   then
      put "btn" into ObD
      put the Number of btns into ObC
   else
      put "fld" into ObD
      put the Number of flds into ObC
   end if
   put "select" into SelCmd
   repeat with ii = 1 to ObC
      put space & ObD && ii && "and" after SelCmd
   end repeat
   delete last word of SelCmd
   put SelCmd into msg
   do SelCmd
end SAO
Peter

Re: Script: select all objects at once

Posted: Sun May 17, 2015 12:15 pm
by dave.kilroy
That's a nice piece of code Peter - thank you, I'm salting that away for future use :)

Re: Script: select all objects at once

Posted: Sun May 17, 2015 4:40 pm
by Klaus
Hi guys,

here a slighly shorter way:

Code: Select all

on SAO BtOrFd
   choose Pointer Tool
   if BtOrFd = "B" then
      repeat with i = 1 to the num of btns
         set the selected of btn i to TRUE
      end repeat
   else
      repeat with i = 1 to the num of flds
         set the selected of fld i to TRUE
      end repeat
   end if
end SAO
Best

Klaus

Re: Script: select all objects at once

Posted: Sun May 17, 2015 5:00 pm
by Klaus
P.S.
This is also quite handy when you need to group a couple (or all) objects!
No need to mess around with DO! 8)

Code: Select all

command group_all_buttons
   repeat with i = 1 to the num of btns
      set the selected of btn i to TRUE
   end repeat
   GROUP
   select empty
end group_all_buttons
You get the picture :D

Re: Script: select all objects at once

Posted: Sun May 17, 2015 5:06 pm
by dave.kilroy
Yes Klaus your way is much shorter and neater - and leaves 'DO' out of the picture so would be faster. But what I particularly liked about Peter's way was his (new to me) use of 'and' that I at first thought wouldn't compile until I tried it and realised it worked! :)

And thanks also Klaus for your 'group' handler