Notifications
Clear all

[Closed] Select group cameras?

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

13 Replies
2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

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?

(@momo2012)
Joined: 11 months ago

Posts: 0

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 )

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 

or

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

8 Replies
(@momo2012)
Joined: 11 months ago

Posts: 0

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?

(@gazybara)
Joined: 11 months ago

Posts: 0

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
(@denist)
Joined: 11 months ago

Posts: 0
c.isSelected = on 

this is wrong… do you know why?

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

(@gazybara)
Joined: 11 months ago

Posts: 0

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

(@denist)
Joined: 11 months ago

Posts: 0

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

(@gazybara)
Joined: 11 months ago

Posts: 0

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

(@denist)
Joined: 11 months ago

Posts: 0

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

(@momo2012)
Joined: 11 months ago

Posts: 0

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 $*	
hideByCategory.cameras=false

then select the camera for example “camera_004”


max views redraw 
select $camera_004
max vpt camera	
clearSelection()

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.

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

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

#2 nested Group002

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

#3 grand parent Group003

$Group003.children
 --> #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

… and why do you want exactly select?