ScriptSpot

Forum topic · General Scripting

Remove specific type of object from scene...

By Scribblez · 2009-12-16

Description

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 (7)

denisT · 2009-12-26

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

Are you test your code? if

Anubis · 2009-12-26

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 

Mr.T · 2009-12-18

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

Anubis · 2009-12-17

the fast way to delete all PF_Source in the scene:

for i in objects where classOf i == PF_Source do delete i

Scribblez · 2009-12-18

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

Mr.T · 2009-12-17

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 · 2009-12-17

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]
)