Notifications
Clear all

[Closed] small selection script problem

macroScript test category:"tobyatwork"
(

rollout picnanobj "Select an object to rotate randomly" width:162 height:152
(
	pickbutton btn1 "pick one object" pos:[17,57] width:128 height:24 toolTip:"select object type"
	label lbl1 "Pick Objects" pos:[18,23] width:126 height:14
	
	local newSel=#()
	on btn1 picked obj do
	(
		btn1.text = obj.name
		pickedobj = obj
		for pickedobj in geometry where (classof pickedobj==obj) do
		(
			append newSel $*
		)
		select newSel
		
		for obj in selection do
		(
			rotate_x = 0 as integer
			rotate_y = 0 as integer
			rotate_z = (random -360 360) as integer
			rotate obj (eulerangles (rotate_x) (rotate_y) (rotate_z))
		)
	)

)

createDialog picnanobj width:162 height:152
)




What this script should do is, selecting all objects in that scene, depending on the type of the picked object. But somehow,no objects are selected. I guess, sth might be wrong within the for-clause, but up to now, I cannot find a solution for that.

Does anyone know, how to get around this?

edit: Got it

3 Replies

Hi brow, I´ve just changed 2 lines and I think it´s working now.


  for pickedobj in geometry where (classof pickedobj == classOF obj) do
   (
 	  append newSel pickedobj
   )
 
 
 rdg

Hi tobi,

you shoudl take a look at collections:

newSel = for currObj in geometry where classof currObj == classof obj collect currObj

It is also a good practice to store your dialog in a global variable.
That way you can try to destroy it -> result is no duplicate dialogs cluttering your workspace

Example and Explaination by Bobo:
http://forums.cgsociety.org/showthread.php?f=98&t=219175&highlight=destroyDialog

Georg

I’ll have a look at this, thank you rdg

This is, what I came up with:

macroScript test category:"tobyatwork"
(

rollout picnanobj "Select an object to rotate randomly" width:162 height:152
(
	pickbutton btn1 "pick one object" pos:[17,57] width:128 height:24 toolTip:"select object type"
	label lbl1 "Pick Objects" pos:[18,23] width:126 height:14
	
	
	on btn1 picked obj do
	(
		btn1.text = obj.name
		pickedobj = obj
		local newSel=#()
		for pickedobj in geometry where (classof pickedobj == classof obj) do
		(
			append newSel pickedobj
		)
		select newSel
		
		for obj in selection do
		(
			rotate_x = 0 as integer
			rotate_y = 0 as integer
			rotate_z = (random -360 360) as integer
			rotate obj (eulerangles (rotate_x) (rotate_y) (rotate_z))
		)
	)

)

createDialog picnanobj width:162 height:152
)