Adding Objects To Groups

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
Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Adding Objects To Groups

Post by Not a lot of thought » Tue Jun 09, 2015 10:35 pm

I'd like to add an object to an existing group without ungrouping and regrouping. Any way to do that?

msellke
Posts: 22
Joined: Mon Oct 21, 2013 2:57 am

Re: Adding Objects To Groups

Post by msellke » Tue Jun 09, 2015 10:51 pm

It can certainly be done.
There are many ways to do it.
You can use the project browser and drag & drop the object into the required group for one method.
You can also add an object to group via script.

Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Re: Adding Objects To Groups

Post by Not a lot of thought » Tue Jun 09, 2015 11:22 pm

I guess I didn't specify. I need to add it to the group using script from the button creating the object.

msellke
Posts: 22
Joined: Mon Oct 21, 2013 2:57 am

Re: Adding Objects To Groups

Post by msellke » Tue Jun 09, 2015 11:34 pm

If you want to add it to a group whilst creating the object it's quite simple.
Fore example creating a button in group test using script as per below.

on mouseUp
create button "button_name" in grp "test"
end mouseUp

Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Re: Adding Objects To Groups

Post by Not a lot of thought » Tue Jun 09, 2015 11:52 pm

...well now I feel silly. I should tried that. Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Adding Objects To Groups

Post by dunbarx » Wed Jun 10, 2015 3:29 pm

Hi all.
..well now I feel silly. I should tried that
There are 2000-odd native words in the dictionary. It may not have been obvious that there was such a command as "create", nor that it contains within it the ability to target a group as a destination. As in learning any language, it takes time to get a decent vocabulary. That is why we have this forum.

Craig Newman

Greg O.
Posts: 21
Joined: Wed Jun 18, 2014 4:02 am
Location: Peyton, Colorado

Re: Adding Objects To Groups

Post by Greg O. » Thu Jun 11, 2015 6:02 pm

dunbarx wrote:Hi all.

There are 2000-odd native words in the dictionary. It may not have been obvious that there was such a command as "create", nor that it contains within it the ability to target a group as a destination. As in learning any language, it takes time to get a decent vocabulary. That is why we have this forum.

Craig Newman

That is without a doubt the best response to this type of post I have ever seen. It made me feel better for having similar questions.

Thank you.

Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Re: Adding Objects To Groups

Post by Not a lot of thought » Tue Jun 23, 2015 9:51 pm

Ok I'm going to try resurrecting this post. How do you add an object to group using script outside of creating the button within the said group?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Adding Objects To Groups

Post by FourthWorld » Tue Jun 23, 2015 9:59 pm

Not a lot of thought wrote:Ok I'm going to try resurrecting this post. How do you add an object to group using script outside of creating the button within the said group?
In the Dictionary, for creating new objects see the "create" command, or for copying existing objects into a group see the "copy" command.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Not a lot of thought
Posts: 77
Joined: Thu May 21, 2015 2:41 am

Re: Adding Objects To Groups

Post by Not a lot of thought » Tue Jun 23, 2015 10:08 pm

I can't just add an object to a group, it must be copied to that group? Wouldn't that then require me to delete the original control?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Adding Objects To Groups

Post by FourthWorld » Tue Jun 23, 2015 10:34 pm

Not a lot of thought wrote:I can't just add an object to a group, it must be copied to that group? Wouldn't that then require me to delete the original control?
To create use "create".
For copy use "copy".
To change the layer of a control set its "layer" property, with the "relayerGroupedControls" global property set to true while you do it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Adding Objects To Groups

Post by dunbarx » Tue Jun 23, 2015 10:37 pm

Hi again.

Code: Select all

Wouldn't that then require me to delete the original control?
I think so. You can move a control out of a group by changing its layer. But you cannot insert a control into a group by the same means, interspersing its layer.

You can create a new control into a group, or you can copy a control into a group, but you cannot insinuate a control into a group.

Or am I wrong? Anyone?

Craig

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

Re: Adding Objects To Groups

Post by jmburnod » Tue Jun 23, 2015 10:50 pm

Hi Craig,
but you cannot insinuate a control into a group
Yes we can.
We have to know the layer of the first and last control of the target group and we can set the layer of a control
between this two layers.
Don't forget

Code: Select all

set the relayerGroupedControls to true
Best regards
Jean-Marc
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Adding Objects To Groups

Post by bn » Tue Jun 23, 2015 11:14 pm

Hi all,

if you want to move a control within a group to the top you can do this:

Code: Select all

on mouseUp
   put the layer of group 1 into tLayerNo -- group layer is always the lowest layer of the group
   put the number of controls of group 1 into tControlCount 
   put tLayerNo + tControlCount into tTopLayer -- layer of group plus the number of the controls of the group is the topLayer within the group
   
   set the relayerGroupedControls to true
   set the layer of field "myField" of group 1 to tTopLayer
   set the relayerGroupedControls to false
end mouseUp
if you want to move a control to the lowest layer within a group do this

Code: Select all

on mouseUp
   put the layer of group 1 into tLayerNo -- group layer is always the lowest layer of the group

   set the relayerGroupedControls to true
   set the layer of field "myField" of group 1 to tLayerNo + 1 -- this is the lowest layer within the group
   set the relayerGroupedControls to false
end mouseUp
Just be careful, if the layer number is wrong you can "layer" the control out of the group.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Adding Objects To Groups

Post by dunbarx » Wed Jun 24, 2015 4:22 am

Ah, the reLayerGroupControls.

I forgot about that. From the dictionary:
Important! It is not possible for other controls to be interspersed between the controls in a single group, so changing a grouped control's layer may change its group membership if the relayerGroupedControls is true:

* You can move a control out of a group by setting the control's layer to a number greater than the topmost control in the group, or less than the bottom-most control in the group.

* Conversely, you can move a control into a group by setting the control's layer to a number between the bottom-most and topmost controls in the group.
Right.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”