Page 1 of 1

group an unknown number of groups

Posted: Mon Nov 19, 2018 7:50 am
by Peter@multidesk.se
I have an unknown number of groups that I need to group into one group

Any suggestions on how to do this?

Probably simple but I'm stuck!

Code: Select all

on openCard
   put yLine into tTemp
   repeat with x = 1 to tCreate 
      clone group "template" of me 
      set the name of it to (carLine & x)
      if x = 1 
      then  
         set the loc of group (carLine & x) to xLine, yLine
      else
         set the loc of group (carLine & x)  to xLine, (tTemp + 44)
         add 44 to tTemp
      end if
   end repeat
   
   -- Here I need to group all the groups I created above into one group
   
end openCard

///Peter

Re: group an unknown number of groups

Posted: Mon Nov 19, 2018 8:22 am
by [-hh]
You could try the following.

Code: Select all

repeat with x = 1 to tCreate 
   ...
   put " and group " & (carLine & x) after doJob
end repeat
put "group" into word 1 of doJob
do doJob
Or you could directly group the objects (use copy instead of clone)

Code: Select all

if there is no grp "newGroup" then create grp "newGroup"
repeat with x = 1 to tCreate 
   copy grp "template" to grp "newGroup"
   set the name of grp id it to (carLine & x)
   ...

Re: group an unknown number of groups

Posted: Tue Nov 20, 2018 12:06 pm
by Peter@multidesk.se
Just what I needed!

I was not familiar with the command "do" :oops: , definitely useful for various projects!

Thanks


///Peter

Re: group an unknown number of groups

Posted: Tue Nov 20, 2018 12:11 pm
by Klaus
Hi Peter,

maybe this is a bit more understandable (and my favourite!):

Code: Select all

...
## Select all groups just like with the mouse and SHIFT-key, but via script:
repeat with x = 1 to tCreate 
      set the selected of grp (caLine & x) to TRUE
end repeat

## All of your groups are selected not and we can simply issue this fine command:
group

## De-select everything and here you go :-)
select empty
...
Best

Klaus