Page 1 of 1

How to group multiple objects by scripts?

Posted: Wed Mar 05, 2014 2:52 pm
by penopia
Hi ^^

I'm trying to group multiple buttons by scripts.
The following scripts works;

group button 1 and button 2

But, following scripts make error. saying (Chunk: error in object expression) near "button 1 and button 2",

put "button 1 and button 2" into tButtonList
group tButtonList

How should I put [ObjectList] after group command to select multiple objects ?

Re: How to group multiple objects by scripts?

Posted: Wed Mar 05, 2014 3:28 pm
by Thierry
penopia wrote:Hi ^^
How should I put [ObjectList] after group command to select multiple objects ?
Hi,

From the dictionnary and down to User contribution,
I found:

Code: Select all

tAPKS =
button id 1282 of card id 1002 of stack "drag" of stack XXXXX
button id 1283 of card id 1002 of stack "drag" of stack XXXXX
button id 1284 of card id 1002 of stack "drag" of stack XXXXX
button id 1285 of card id 1002 of stack "drag" of stack XXXXX
button id 1286 of card id 1002 of stack "drag" of stack XXXXX

Code: Select all

put the number of lines of the tAPKS of stack "drag" into tNum //Get number of lines to process
put 1 into tLine //start from line 1
put line tLine of the tAPKS of stack "drag" into tList //put the first long id from tAPKS into the tList variable
repeat until tLine = tNum //Use a repeat function that allows you to go through every line of tAPKS
   put tLine + 1 into tLine //Use a simple counter for the repeat function
   put " and " & line tLine of the tAPKS of stack "drag" after tList //Add and "and" (standard grouping syntax) aswell as the next line of tAPKS to the tList variable
end repeat
group tList //Group everything in the tList variable
Best,

Thierry

Re: How to group multiple objects by scripts?

Posted: Wed Mar 05, 2014 3:34 pm
by Klaus
Hi penopia,

you need to tell the engine to actually DO/Execute the supplied "string"
and not handle it as a simple string, which it is in fact :D

Your example is one of the rare cases where one has to use DO. This works:

Code: Select all

on mouseup
   put "button 1 and button 2" into tButtonList
   do ("group" && tButtonList)
end mouseUp
Best

Klaus

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 2:32 am
by penopia
Thanks Klaus.
You gave me the very simple and perfect solution !
(I can not fully understand the reason to use "do" script, but I work :D )

on mouseUp
local tButtonList
put the name of btn 1 into tButtonList
put " and " after tButtonList
put the name of btn 2 after tButtonList
do("group" && tButtonList)
put the long name of btn 1 into fld 1
end mouseUp

gave me the followings in fld 1:

button "Button" of group id 1007 of card id 1002 of stack "Untitled 1"

To Tierry;

Thanks for your advice.
The following scripts also doesn't work. I think group command does not accept 'string list' as a parameter regardless of the infotmation in it, as Klaus said.

on mouseUp
local tButtonList
put the long name of btn 1 into tButtonList
put " and " after tButtonList
put the long name of btn 2 after tButtonList
group tButtonList
end mouseUp

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 8:00 am
by Thierry
penopia wrote:I think group command does not accept 'string list' as a parameter..
Umm, I was only quoting "the wrong code" from the dictionary! :evil:

Glad that Klaus gave you the solution :)

Regards,

Thierry

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 1:16 pm
by Klaus
Hi friends,

you can also use a list like Thierry posted earlier to use it to group all object in it!
But in a slightly other way :D

Using Thierrys example variable: tAPKS =
button id 1282 of card id 1002 of stack "drag" of stack XXXXX
button id 1283 of card id 1002 of stack "drag" of stack XXXXX
button id 1284 of card id 1002 of stack "drag" of stack XXXXX
button id 1285 of card id 1002 of stack "drag" of stack XXXXX
button id 1286 of card id 1002 of stack "drag" of stack XXXXX

Code: Select all

...
## You can also set the SELECTED property of any object instead of "select btn xyz"
repeat for each line i in tAPKS
  set the selected of i to TRUE
end repeat

## Now everything is selected:
GROUP

## Clean up:
select empty
...
:D


Best

Klaus

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 2:47 pm
by Thierry
Klaus wrote:Hi friends,
Using Thierrys example variable:

Code: Select all

...
GROUP
...
Hi Klaus,
I prefer to give credit where it is due, especially when it's not working :)
so this code sample comes from the Dictionary!

Regards,

Thierry

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 2:52 pm
by Klaus
Ahm yes, found it in the dictionary. OK, tAPKS was custom prop in that example.

As the poster wrote: "Here's an inefficient but quick way to group a list of long ids."
He is right :D

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 3:06 pm
by Thierry
Klaus wrote:As the poster wrote: "Here's an inefficient but quick way to group a list of long ids."
He is right :D
Klaus,
You win the gold medal of "marketing"
Here is your price: http://www.ina.fr/video/I06268518 ... in French :)

Thierry

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 3:18 pm
by Klaus
Merci, mon ami! :D

But my french is not good enough to understand that guy.
And from watching I confess I don't find him funny at all 8)

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 3:30 pm
by Thierry
Klaus wrote:Merci, mon ami! :D
But my french is not good enough to understand that guy.
ah, humour.. so difficult to share.. :)

Best,

Thierry

Re: How to group multiple objects by scripts?

Posted: Thu Mar 06, 2014 3:48 pm
by bn
There is a subtle difference between the two ways of grouping objects by script.

the first

Code: Select all

on mouseup
   put "button 1 and button 2" into tButtonList
   do ("group" && tButtonList)
end mouseUp
works but not on objects already grouped

the second

Code: Select all

...
## You can also set the SELECTED property of any object instead of "select btn xyz"
repeat for each line i in tAPKS
  set the selected of i to TRUE
end repeat

## Now everything is selected:
GROUP

## Clean up:
select empty
...
also works on objects within a group if they are within the same subgroup

Kind regards
Bernd

Re: How to group multiple objects by scripts?

Posted: Sat Mar 08, 2014 8:04 am
by penopia
Hi,
Thanks for letting me know another cool way to group multiple objects by scripts. For the beginners like me, I will write again simple scripts.

In case there are 3 buttons, and you want group all of these buttons;

repeat with i=1 to 3
set the selected of button i to true
end repeat
group

What a nice use of property "selected" !!!
Thank all of you again for getting me out of troubles.

Re: How to group multiple objects by scripts?

Posted: Sun Sep 02, 2018 10:30 am
by TorstenHolmer
Hi,

I had the same question and found a good hint in the famous book "Cooking with HyperCard" frm Dan Winkler and Scott Knaster, in which are recipies for doing the same thing to a group of objects.

The key is "repeat with i = 1 to the number of buttons" where you don't have to specify each button in advance.

I am using this script in order to create a cardboard-like interface where buttons or fields can be moved around the card and the canvas can be bigger than the visible card size.

Code: Select all


on mouseUp
   
   lock screen
   if the number of groups > 0 then exit mouseup
   
   repeat with i = 1 to the number of buttons
      set the selected of button i to TRUE
   end repeat
   GROUP
   
   select empty
   unlock screen
   
end mouseUp

Cheers,
Torsten