Grouping objects by script

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
garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

Grouping objects by script

Post by garyth123 » Mon Feb 17, 2014 10:57 am

Hi,

How do I add objects (possibly including other groups) to a group (actually a scrolling group) by script?

Thanks in advance.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Grouping objects by script

Post by Simon » Mon Feb 17, 2014 11:05 am

Take a look at "start editing"

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Grouping objects by script

Post by jmburnod » Mon Feb 17, 2014 11:27 am

Hi,

You can use copy group like that:

Code: Select all

copy group "grMyGroupMaster" to group "grMyScrollGroup"
Best regards
Jean-Marc
https://alternatic.ch

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Grouping objects by script

Post by Klaus » Mon Feb 17, 2014 1:14 pm

You can also directly create objects in groups:
...
create fld "a text field" in grp " a big group"
...

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

Re: Grouping objects by script

Post by garyth123 » Tue Feb 18, 2014 11:38 am

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?

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Grouping objects by script

Post by Klaus » Tue Feb 18, 2014 12:51 pm

HI garyth123,
garyth123 wrote: Will this change the suggestions made already?
no, why should it?
We wanted to leave some work up to you, too! :D


Best

Klaus

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

Re: Grouping objects by script

Post by garyth123 » Sun Feb 23, 2014 7:02 pm

Klaus wrote:HI garyth123,
garyth123 wrote: Will this change the suggestions made already?
no, why should it?
We wanted to leave some work up to you, too! :D


Best

Klaus
I am not getting this to work. I have tried

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.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Grouping objects by script

Post by Klaus » Sun Feb 23, 2014 7:20 pm

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"
so do you have a group named "scrollgroup" or not?
LC does not lie most of the time :D
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.
So this works as exspected?
All groups get copied correctly?
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.
Please always note WHAT error you get!

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
...
Hope that helps!


Best

Klaus

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

Re: Grouping objects by script

Post by garyth123 » Sun Feb 23, 2014 7:50 pm

so do you have a group named "scrollgroup" or not?
LC does not lie most of the time :D
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 this works as exspected?
All groups get copied correctly?
Yes.
Please always note WHAT error you get!
"error in object expression."
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
...
Hope that helps!
Yes, "set the selected" is what I needed to know. Thank you.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7235
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Grouping objects by script

Post by jacque » Mon Feb 24, 2014 6:36 pm

Just for the record, the "start editing" command requires that you refer to the group as a "background":

Code: Select all

start editing bg "scrollgroup"
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

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”