# Maxscript callback help

**URL:** <https://forums.chaos.com/t/maxscript-callback-help/56982>\
**Category:** Off-topic\
**Tags:** callbacks, maxscript\
**Created:** [February 1, 2016, 5:35pm UTC](https://forums.chaos.com/t/maxscript-callback-help/56982 "2016-02-01T17:35:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![MoonDoggie](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/moondoggie/32/68517_2.png) [@MoonDoggie](https://forums.chaos.com/u/MoonDoggie)\
**Post date:** [February 1, 2016, 7:20pm UTC](https://forums.chaos.com/t/maxscript-callback-help/56982/5 "2016-02-01T19:20:12Z")

</div>

> [@Vray rendernodes - universal usage question across platforms](https://forums.chaos.com/t/vray-rendernodes-universal-usage-question-across-platforms/49877/5):
>
> Thanks a lot Colin. I have a camera lister script/dialog that allows me to quickly adjust the cameras in the scene. It’s started from Track’s camera lister (can’t find the link now) but I’ve heavily modified to it my needs, added some functionality and added support for physical cameras. It works great but I’m just trying to push it so that if a scene camera is deleted it automatically refreshes the dialog UI which then has the new list of cameras (without the deleted one). It basically just rebuilds the camera list from scratch each time it’s refreshed so the camera should no longer be in the scene. I know I could easily set it up to catch any errors if I try to adjust a deleted camera, I’m just trying to be fancy. I may try to have it remove the matching, to be deleted camera, from the array of scene cameras it collects (code portion below). This might get complicated if I delete multiple cameras though.  
> `physCamArr=for p in cameras where (classof p == Physical and p.isHidden != true ) collect p`
> 
> So in short, I need know that a camera has been deleted, then after deletion, rebuild the UI. Honestly, don’t spend a lot of time on this, but thanks for your help.

Gotcha, here is a proof of concept:

Notes: There are lots of other callbacks we would need to use to detect any possibility of a new camera.

```auto

(
	-- Global declarations 
	global rlt_test
	global OnCameraPossibleChangeEvent	-- Callback for post delete

	callbacks.removeScripts id:#OnCameraPossibleChangeEvent

	-- Add the callback for the functions
	callbacks.addScript #selectedNodesPostDelete "OnCameraPossibleChangeEvent()" id:#OnCameraPossibleChangeEvent	-- Node deleted
	callbacks.addScript #postNodesCloned "OnCameraPossibleChangeEvent()" id:#OnCameraPossibleChangeEvent -- Node cloned
	callbacks.addScript #sceneNodeAdded "OnCameraPossibleChangeEvent()" id:#OnCameraPossibleChangeEvent -- Node added
	callbacks.addScript #nodeHide "OnCameraPossibleChangeEvent()" id:#OnCameraPossibleChangeEvent -- Node hidden
	callbacks.addScript #nodeUnhide "OnCameraPossibleChangeEvent()" id:#OnCameraPossibleChangeEvent -- Node unhidden

	--callbacks.show id:#OnCameraPossibleChangeEvent

	-- Here's the function that gets called when the callback fires
	function OnCameraPossibleChangeEvent = (	
		if (rlt_test != undefined) then
		(
			rlt_test.updateUI()	-- Call the update ui in the script
		)
	)

	-- Destroy previous versions of the script if already running
	try (destroyDialog rlt_test) catch()

	rollout rlt_test "Up-to-date Cameras"
	(
		multiListBox lst_cameras "Cameras:" height:20

		-- Update the listbox in the rollout
		fn updateUI = 
		(
			-- Get the visible cameras in the scene
			local visiblePhysicalCameras = for c in cameras where ((classof c == VRayPhysicalCamera) AND (c.isHidden == false)) collect c.name
			lst_cameras.items = visiblePhysicalCameras
		)

		on rlt_test open do 
		(
			updateUI()
		)

		on rlt_test close do 
		(
			callbacks.removeScripts id:#OnCameraPossibleChangeEvent
		)
	)
	createDialog rlt_test 250 350
)

```

---

_[View the full topic](https://forums.chaos.com/t/maxscript-callback-help/56982)._
