Grouping script

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Grouping script

Post by jwtea » Fri Apr 27, 2018 4:14 am

Hello,

anybody know how to create a group that can group all those small group??

I got alot of group and i want to group all as 1 so that i can make it scrollable as
the content is not enough to fit in my size.

Any help is appreciated!

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

Re: Grouping script

Post by dunbarx » Fri Apr 27, 2018 5:13 am

Hi.

Do you mean a handler that can create a large group from a bunch of controls or groups? This is easy to do by hand. You simply select objects with the shiftKey, and hit the group icon in the menuBar.

Or, if you know the names of the groups of interest, you can write something like

Code: Select all

on mouseUp
    select group "aa" and grp "bb"
   group 
end mouseUp
The word "and" allows this to go forward.

But if you do not know the names of the groups, but want to group any number of them, you need (I think) to do something a little more sophisticated:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of grps -- and/or controls
      put the name of grp y && "and "  after temp
   end repeat
   delete the last word of temp
   do "select" &&  temp
   do  "group" && temp
end  mouseUp
You might put a conditional in front of the "put" line to filter the objects you want:

Code: Select all

if the name of control y contains "XYZ" then put the name ... 
But now looking at the dictionary, I see that there is yet another way, to use an "objectList" as the list of groups or controls to, er, group. This objectList seems to be an array, and I am not sure how it is constructed. Someone else will chime in, though.

Craig Newman

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Grouping script

Post by jwtea » Fri Apr 27, 2018 5:20 am

Hello , thanks for your fast replies!!

I had some issue because.... i got 4 groups and this 4 groups got the same name... or you got any idea to
group the whole card???

Thanks!

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

Re: Grouping script

Post by dunbarx » Fri Apr 27, 2018 2:42 pm

Hi.

Well, first off, it is usually bad practice to have controls (or groups) have the same name.

But you can use other properties, such as the number, to collect these objects:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of grps -- and/or controls
      put "group" && y && "and "  after temp
   end repeat
   delete the last word of temp
   do "select" &&  temp
   do  "group" && temp
end  mouseUp
I am building essentially the same reference. Step through the handlers and see what is in "temp" in each case.

Craig

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Grouping script

Post by jwtea » Mon Apr 30, 2018 2:23 am

Hello ,

Thanks above the script worked perfectly!!

But can i ask you why everytime i move the location of my box, when it hit the maximum height it will auto go to the middle??

Example : my first box will move to 150,200 location then second box will move to 150,400 then my third box will move to 150,600. But my fourth box and fifth box will auto go to the 150,165 .... (i'm using repeat coding for the moving of box)

Any idea i can go let them go 150,800 then 150,1000 and continue..... then after that i can use my script to group down and allow scrolling??

Thanks!!

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

Re: Grouping script

Post by dunbarx » Mon Apr 30, 2018 6:52 pm

Hi.

I am not sure I understand.

By "box" do you mean "field"? And when you run the handler, you are seeing the controls or groups moving all by themselves? You may have to post an example stack.

In any case, you can always add a short repeat loop that sets the loc of each group in any way you want to. Do you need help with that?

Craig

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Grouping script

Post by jwtea » Wed May 02, 2018 2:08 am

Hello dunbarx,

thanks for your help! & i already managed to solve the problem 8)

JereMiami
Posts: 119
Joined: Mon Nov 03, 2014 12:17 am

Re: Grouping script

Post by JereMiami » Fri Aug 20, 2021 4:39 pm

I used a similar method in a repeat command (also grouping multiple groups into a group) as above.

Without repeating the whole code, it does result in

Code: Select all

do "group" && tObjectList
...where tObjectList is: group "Group 1" and group "Group 2"

BUT - I get this execution error: "group: object cannot be grouped."

I should note that both Group 1 and Group 2 are already within a Group, so that may be where the error is coming from (i.e., the desired result would be both Group 1 and Group 2 being in a new subgroup to a larger group).

What does this mean?

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

Re: Grouping script

Post by Klaus » Fri Aug 20, 2021 5:05 pm

Hi friends,

no need to DO anything!

Code: Select all

...
   repeat with y = 1 to the number of grps 
     set the selected of grp y to TRUE
  end repeat
  group
  select empty
...
:-)

Best

Klaus

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

Re: Grouping script

Post by Klaus » Fri Aug 20, 2021 5:40 pm

Hi JereMiami,

You cannot group an object (group or wahtever) that is already part of another group!
So you can check if that is the case, if the group is NOT part of another group, its OWNER is the current card.

Code: Select all

...
   repeat with y = 1 to the number of grps 
    if word 1 of the owner of grp y = "card" then
     ## e.g. card id 1111 = NOT a subgroup
     set the selected of grp y to TRUE
   end if
  end repeat
  group
  select empty
...
Best

Klaus

andresdt
Posts: 146
Joined: Fri Aug 16, 2019 7:51 pm

Re: Grouping script

Post by andresdt » Fri Aug 20, 2021 9:30 pm

Hello there,
When I want to do something like that I always use the childControlIDs property. Since I discovered it it has helped me a lot jjj

See a possible solution to your problem using the childControlIDs property.

Code: Select all

    local tChilds, tLongId

    select empty
    
    # set the layer of group"MyGrp" to 1
    
    if there is a group 1 then ungroup group 1
    put the childControlIDs of this card into tChilds
    
    if the number of lines of tChilds > 1 then
        
        repeat for each line tId in tChilds
            put the long id of control id tId into tLongId
            
            if word 1 of tLongId is no "group" then next repeat --> Groups only, remove to group all controls
            set the selected of tLongId to true
        end repeat
        
        group
        select empty
    end if
    

JereMiami
Posts: 119
Joined: Mon Nov 03, 2014 12:17 am

Re: Grouping script

Post by JereMiami » Mon Aug 23, 2021 1:11 am

Thanks! It was part of another group and simply copying to "this card" (and not the group) before copying it into the group resolved the issue. Thanks everyone!

Post Reply

Return to “Talking LiveCode”