Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Deselecting selected after unhide a child

4 REPLIES 4
Reply
Message 1 of 5
iqbot
400 Views, 4 Replies

Deselecting selected after unhide a child

Good day to all!
I am very very new to the maxscript and to the English language too
I had a lot of fun programming the script via ChatGT, but I encountered a problem that it can't solve.
Task: When selecting one of several cameras, it is necessary that the child plane to it is unhide.
Problem: The planes are displayed as they should be, but when clicking on an unselected camera, if the plane was previously hidden, the selection is removed from the camera. This only happens when the camera is selected onclick. If you select the camera with a selection area or in layers, then the selection stays. The selection also remains if the linked plane to the camera has not been hidden.

 

 

 

try(destroydialog myRollout)catch()
rollout myRollout "MyRollout" width:140 height:265 (

fn SelectionChanged = 
	(
	selection[1].children.ishidden = false
	)

on myRollout open do(
callbacks.removescripts id:#MySelectionChange
callbacks.addscript #selectionSetChanged "myRollout.SelectionChanged()" id:#MySelectionChange
)
on myRollout close do 	(callbacks.removescripts id:#MySelectionChange)	
)	
createdialog myRollout

 

 

 

4 REPLIES 4
Message 2 of 5
denisT.MaxDoctor
in reply to: iqbot

Do you want to have fun with ChatGPT or learn MXS?
If the former, then you can continue... if the latter, then:

 

 

 

fn sync_camera_sel =
(
	for c in cameras where iskindof c Camera do 
	(
		if c.isselected then selectmore c.children else deselect c.children
	)
	ok
)

callbacks.removescripts id:#sync_camera_sel
callbacks.addscript #selectionSetChanged "sync_camera_sel()" id:#sync_camera_sel

 

 

 

Message 3 of 5

I removed the previous solution and replaced it with a simple one. And everything seems to work well, but this simplified solution has some issues... that can be discovered during more thorough testing. 
The ability to anticipate problems sets an experienced developer apart from ChatGPT.

Message 4 of 5
iqbot
in reply to: denisT.MaxDoctor

Thank you for your reply. I find such code beautiful, even though I don't understand some parts of it. Ok, now I've found out about the camera collection, it will be useful in other parts of my script.


However, this example doesn't seem to directly solve my problem or I'm not sure how it could help. Perhaps I didn't describe the issue clearly enough.


Using the example of this code, if we replace "selectmore c.children" with "hide c.children" we will get about what I need, but the problem itself will remain. And it lies in the fact that with a single click on the camera in the viewport window, the camera selects for a moment, the child hides, but then the selection from the camera disappears. At the same time, the camera remains selected if you select it not with a single click, but with the selection area.

 

 

for c in cameras where iskindof c Camera do 
	(
		if c.isselected then hide c.children else deselect c.children
	)
	ok

 

 

PS: I don't claim to be an experienced developer, because I started studying the script three days ago, without having proper programming experience in general. I was able to achieve the result I wanted and it helped speed up my team's work, but I still want to work on improving some aspects of the script to make it work a little more beautiful.

Message 5 of 5
denisT.MaxDoctor
in reply to: iqbot

first of all, you need to clearly define the goal you want to achieve. for example:

 

the goal description:
- when you select any camera object, all its children need to be un-hided and selected as well
- all unselected camera children must be unselected and hidden

 

this is called a "terms of reference" or a "technical specifications" ...

the more precise it is, the more likely it will be understood correctly and you will get what you need.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report