Grouping objects by script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Grouping objects by script
Hi,
How do I add objects (possibly including other groups) to a group (actually a scrolling group) by script?
Thanks in advance.
How do I add objects (possibly including other groups) to a group (actually a scrolling group) by script?
Thanks in advance.
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Grouping objects by script
Take a look at "start editing"
Simon
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Grouping objects by script
Hi,
You can use copy group like that:
Best regards
Jean-Marc
You can use copy group like that:
Code: Select all
copy group "grMyGroupMaster" to group "grMyScrollGroup"
Jean-Marc
https://alternatic.ch
Re: Grouping objects by script
You can also directly create objects in groups:
...
create fld "a text field" in grp " a big group"
...
...
create fld "a text field" in grp " a big group"
...
Re: Grouping objects by script
Maybe I should say that I am attempting to add a group of objects which act as a template to a group which will act as a scroll group. So there will be many objects added to the scroll group each of which will have to be placed below each other in the scroll group. Will this change the suggestions made already?
Re: Grouping objects by script
HI garyth123,
We wanted to leave some work up to you, too!
Best
Klaus
no, why should it?garyth123 wrote: Will this change the suggestions made already?
We wanted to leave some work up to you, too!
Best
Klaus
Re: Grouping objects by script
I am not getting this to work. I have triedKlaus wrote:HI garyth123,no, why should it?garyth123 wrote: Will this change the suggestions made already?
We wanted to leave some work up to you, too!
Best
Klaus
start editing group "scrollgroup"
and get an execution error "Chunk: can't find background"
I have tried
copy grp "myTemplateGroup" of cd "template card" to this card
placing successive copies (in a loop) of the template group as I want them to appear on the new card, and then attempted to group these via script.
I found that in the IDE I could get a command like
group "group ID 4149" and "group ID 4156" and "group ID 4163"
to work, but trying to recreate the command via script got another chunk error.
I appreciate your comment, Klaus, about leaving me some work to do but the documentation in the dictionary for some of the commands is very sparse. Coupled with the fact that there are many things in LC that I have yet to learn (and want to learn), then it is like hitting your head against a brick wall, as the saying has it. Or it may just be that I'm not very good at programming.
Re: Grouping objects by script
so do you have a group named "scrollgroup" or not?garyth123 wrote:I am not getting this to work. I have tried
start editing group "scrollgroup"
and get an execution error "Chunk: can't find background"
LC does not lie most of the time
So this works as exspected?garyth123 wrote:I have tried
copy grp "myTemplateGroup" of cd "template card" to this card
placing successive copies (in a loop) of the template group as I want them to appear on the new card, and then attempted to group these via script.
All groups get copied correctly?
Please always note WHAT error you get!garyth123 wrote: I found that in the IDE I could get a command like
group "group ID 4149" and "group ID 4156" and "group ID 4163"
to work, but trying to recreate the command via script got another chunk error.
In your "copy" loop you should also manage a list of the new IDs of the copied groups, sou you can later group them.
Something like this:
Code: Select all
...
put empty into tIDList
repeat ...
copy grp "myTemplateGroup" of cd "template card" to this card
## Now note that ID:
put the ID of LAST group & "," after tIDList
end repeat
## Delete trailing COMMA:
delete last char of tIDList
## Now select all these groups and group them:
repeat for each item tID in tIDList
set the selected of grp ID tID to TRUE
end repeat
## Do it now :-)
GROUP
## Deselect again
select empty
...
Best
Klaus
Re: Grouping objects by script
No I don't. I need to create the group by script. That was my original intention in the first post of this thread. Apologies if I was not sufficiently clear.so do you have a group named "scrollgroup" or not?
LC does not lie most of the time
Yes.So this works as exspected?
All groups get copied correctly?
"error in object expression."Please always note WHAT error you get!
Yes, "set the selected" is what I needed to know. Thank you.In your "copy" loop you should also manage a list of the new IDs of the copied groups, sou you can later group them.
Something like this:Hope that helps!Code: Select all
... put empty into tIDList repeat ... copy grp "myTemplateGroup" of cd "template card" to this card ## Now note that ID: put the ID of LAST group & "," after tIDList end repeat ## Delete trailing COMMA: delete last char of tIDList ## Now select all these groups and group them: repeat for each item tID in tIDList set the selected of grp ID tID to TRUE end repeat ## Do it now :-) GROUP ## Deselect again select empty ...
-
- VIP Livecode Opensource Backer
- Posts: 7235
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Grouping objects by script
Just for the record, the "start editing" command requires that you refer to the group as a "background":
And of course, the group needs to exist. But you don't really need to go into background editing mode just to create objects in a group, as Klaus mentioned.
EDIT:
Here's the skelton of what you want:
Code: Select all
start editing bg "scrollgroup"
EDIT:
Here's the skelton of what you want:
Code: Select all
create grp "scrollgroup"
create fld "myField" in grp "scrollgroup"
create btn "myButton" in grp "scrollgroup"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com