Select group cameras?


Hi guys,
Is there a way to select a camera that in group and without ungroup it?


yes and no, you can collect all camera’s in a group with something like

groupcams = for i in $Group01.children where isKindOf i camera collect i

if you then try

select groupcams 


select groupcams[1] 

and the group is closed you just select the group, but if the group is open then it will select the cameras or camera. so something like

groupcams = for i in $Group01.children where isKindOf i camera collect i
 setGroupOpen $Group01 true
 select groupcams[1]

but if you can do the changes in mxs without having the camera selected you can forgo the setGroupOpen stage


Thanks Klunk,I did the test,

groupcams = for i in $Group01.children where isKindOf i camera collect i
 setGroupOpen $Group01 true
 select groupcams[1]

setGroupOpen $Group01 false

these codes works for me,I will do some change to handle it base on your codes,the last thing I need to comfirm is:
If I setGroupOpen $Group01 true,then the Group01 has ungrouped or not?I mean ,whether the Group still there,does not ungrouped,but I can access it and all sub objects in Group01,or the Group01 has already ungrouped?


It’s not that easy you know.
By using $Group001.children you are not be able to collec all nodes if you have nested group.
Let’s say that we have $Group002 which is grand parent and $Group001 which is nested group
and $Camera001 is the member of this group.
Try this fn and tell me what you think

fn selectFirstCamInGroup grp =
  	fn getFirstGroupParent obj = (while not isGroupHead obj do obj = obj.parent)
  	for c in (join #() grp) where isKindOf c camera do exit with \
  		if isOpenGroupMember c then c.isSelected = on else
  			if (grp = getFirstGroupParent c) != null do (setGroupOpen grp on ; c.isSelected = on)
  selectFirstCamInGroup $Group002


One more example:
Now we have tree groups
#1 nested Group001

 --> #children($Sphere005, $Camera002.Target, $Camera002, $Sphere006)

#2 nested Group002

 --> #children($Camera001, $Camera001.Target, $Sphere004, $Sphere003, $Group001)

#3 grand parent Group003

 --> #children($Sphere002, $Sphere001, $Group002)

With this function you will be able to select all cams in Grand Parent (Group003)

fn selectCamsInGroup grp =
 	fn getFirstGroupParent obj = (while not isGroupHead obj do obj = obj.parent)
 	local cams = for c in (join #() grp) where isKindOf c camera collect 
 		if not isOpenGroupMember c do 
 			if (grp = getFirstGroupParent c) != null do setGroupOpen grp on
 		) ; c
 	if cams.count == 0 then "No Cameras in this Group!" else select cams
 selectCamsInGroup $Group003

c.isSelected = on 

this is wrong… do you know why?

edited… my bad. the function is called ‘select first’ … but anyway… it’s wrong :slight_smile:


are you familiar how groups work? if so you have to know that any selection of a member of closed group selects whole group. if you want to be able select an individual member of a group, the group has to be open.
about a camera in group… do you want to know all cameras in a specified group or all cameras that a member of any group?


… and why do you want exactly select?


Why? Group related topics requires painful and long discussion like last time :slight_smile:


the function has to select a first camera… what does it do if there is no one? nothing. this is wrong.


If is there not camera fn does nothing. So U suggest to simply use select method?


a function that selects something by specified condition has to clear selection in case if no one found.


Thanks for your help, gazybara~,but your code is base on Open Group,whatever you do,if the Group is ungrouped ,the group node would change.
I have a script need to change cameras in scene,my friend told me ,when running it in a big scene,when selecting cameras ,some objects were moved to a new position,that’s mean ,the scene has changed,cannot render correctly,so ask me if there a way to aviod,I used these codes to ungroup all:

explodeGroup $*	

then select the camera for example “camera_004”

max views redraw 
select $camera_004
max vpt camera	

if the codes right,why the scene has changed?if the scene would not changed,setGroupOpen function is good enough to handle it.
I still looking for a solution.


Thanks denisT,now I am very sure of how the groups work,and can not select it without open group.I just want to select the cameras in group ,and without ungroup it ,because ,my friend have a big scene,need to select cameras(some in groups),if ungroup it ,will cause problem…
Any other good idea?
(I tried copy a new temp camera same as the group camera,but ,the copy one,also in that group )


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.