Remove specific type of object from scene...

I would like to know how I can create a script that specifically deletes a certain object from the scene.

Example: I accidentally select a space warp or particle view or something and I want to be able to click a button that automatically finds particle view and removes it from my scene.
Here's my lousy attempt:

(
on press return (Particle_View.current!=undefined)
on execute do
(
if( Particle_View:Particle View.current==undefined ) then true
else Particle_View.current.DeleteSelected()
)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
denisT's picture

the fastest way is: if (pfs

the fastest way is:
if (pfs = getclassinstances PF_Source).count > 0 do delete pfs

Anubis's picture

Are you test your code? if

Are you test your code?
if (pfs = getclassinstances PF_Source).count > 0 do delete pfs

First "pfs" variable is local to the IF scope and become undefined for the delete ops, so the well known error appear: -- No "delete" function for undefined

But that not is all, try this:

PF_Source();PF_Source() -- create 2 PF just for test
pfs = getclassinstances PF_Source -- collect to var
-->#(PF Source , PF Source )
delete pfs
--> Runtime error: operation requires a collection of nodes, got: PF Source 

my recent MAXScripts RSS (archive here)

Mr.T's picture

Thanks Anubis, this for loop

Thanks Anubis, this for loop is way more efficient and get rid of the Array.

Anubis's picture

the fast way to delete all

the fast way to delete all PF_Source in the scene:
for i in objects where classOf i == PF_Source do delete i

my recent MAXScripts RSS (archive here)

Scribblez's picture

thank you very much guys.

thank you very much guys. I'm going to experiment with these and see if I can't learn something :)

Mr.T's picture

Here is a version which ask

Here is a version which ask for user if he wants to delete the PF_Source with its name in the querybox.

(
try(destroyDialog DoDeletePF_Source)catch()
 
rollout DoDeletePF_Source "Delete PF_Source from Scene"
 
(
	button deleteButton "Delete All PF_Source" width:200 height:20
 
	on deleteButton pressed do
	(
		allPF_Source=#()
		for obj in $* do (if classOf obj == PF_Source then append allPF_Source obj)
 
		for f = 1 to allPF_Source.count do
		(
			querystring = "Delete " + allPF_Source[f].name + " ?"
 
			q = querybox querystring title:"Confirme Delete"
			if q then
			(
				delete allPF_Source[f]
				completeRedraw()
			) 			
		)
	)
)	
createDialog DoDeletePF_Source 240 40 --create a Dialog from the rollout	
)
Mr.T's picture

I'm not sureif I understood

I'm not sureif I understood correctly, but you could loop through each scene object and make an array with only the PF_Source. Then  in a for loop you could delete every object in the array. It's not really clean I'm no maxscript pro but this seems to work.

allPF_Source=#()
for obj in $* do (if classOf obj == PF_Source then append allPF_Source obj)
 
for f = 1 to allPF_Source.count do
(
	delete allPF_Source[f]
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.