How to group multiple objects by scripts?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How to group multiple objects by scripts?
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 ?
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?
Hi,penopia wrote:Hi ^^
How should I put [ObjectList] after group command to select multiple objects ?
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
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: How to group multiple objects by scripts?
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
Your example is one of the rare cases where one has to use DO. This works:
Best
Klaus
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
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
Klaus
Re: How to group multiple objects by scripts?
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 )
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
You gave me the very simple and perfect solution !
(I can not fully understand the reason to use "do" script, but I work )
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?
Umm, I was only quoting "the wrong code" from the dictionary!penopia wrote:I think group command does not accept 'string list' as a parameter..
Glad that Klaus gave you the solution
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: How to group multiple objects by scripts?
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
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
Best
Klaus
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
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
...
Best
Klaus
Re: How to group multiple objects by scripts?
Hi Klaus,Klaus wrote:Hi friends,
Using Thierrys example variable:Code: Select all
... GROUP ...
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: How to group multiple objects by scripts?
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
As the poster wrote: "Here's an inefficient but quick way to group a list of long ids."
He is right
Re: How to group multiple objects by scripts?
Klaus,Klaus wrote:As the poster wrote: "Here's an inefficient but quick way to group a list of long ids."
He is right
You win the gold medal of "marketing"
Here is your price: http://www.ina.fr/video/I06268518 ... in French
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: How to group multiple objects by scripts?
Merci, mon ami!
But my french is not good enough to understand that guy.
And from watching I confess I don't find him funny at all
But my french is not good enough to understand that guy.
And from watching I confess I don't find him funny at all
Re: How to group multiple objects by scripts?
ah, humour.. so difficult to share..Klaus wrote:Merci, mon ami!
But my french is not good enough to understand that guy.
Best,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 4012
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How to group multiple objects by scripts?
There is a subtle difference between the two ways of grouping objects by script.
the first
works but not on objects already grouped
the second
also works on objects within a group if they are within the same subgroup
Kind regards
Bernd
the first
Code: Select all
on mouseup
put "button 1 and button 2" into tButtonList
do ("group" && tButtonList)
end mouseUp
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
...
Kind regards
Bernd
Re: How to group multiple objects by scripts?
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.
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.
-
- Posts: 57
- Joined: Mon Oct 28, 2013 1:23 pm
- Location: Dresden, Germany
Re: How to group multiple objects by scripts?
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.
Cheers,
Torsten
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
Torsten