ScriptSpot home

Forum topic · General Scripting

Select object by his properties

By Andrey · 2020-03-20

Description

Hello,
Tell me how to select an object by its property?
I need to select objects with a specific property :
- display as box
- backface cull
- trajectory
- vertex tricks
It is required to select one property at a time.
I need several buttons, each of which will be bound to one property of the object.
Is it possible?
Thanks :-)

Comments (10)
miauu

.

All those properties are common for all objects(geometry, shapes). So, if you have a script that will select all objects that have property display as box the script will select all objects. If you want to select only objects which property is ON then try this script:



(
	global rol_selObjsByProperty
	try(destroyDialog rol_selObjsByProperty)catch()
	rollout rol_selObjsByProperty "Select objects by property"
	(
		group "Selcet objects with"
		(
			button btn_selByDAB "Display as box" width:120
			button btn_selByBC "Backface cull" width:120
			button btn_selByT "Trajectory" width:120
			button btn_selByVT "Vertex tricks" width:120
		)
		
		function SelectByProperty property: =
		(
			objsToSelArr = #()
			for o in objects where (isProperty o property) do
			(
				if (getProperty o property) == true do
					append objsToSelArr o
			)
			select objsToSelArr
		)
		
		on btn_selByDAB pressed do
		(
			SelectByProperty property:#boxmode
		)
		on btn_selByBC pressed do
		(
			SelectByProperty property:#backfacecull
		)
		on btn_selByT pressed do
		(
			SelectByProperty property:#showTrajectory
		)
		on btn_selByVT pressed do
		(
			SelectByProperty property:#vertexTicks
		)
		
	)
	createdialog rol_selObjsByProperty 
)
Reply to miauu
Andrey

Excellent
Thank you very much!
Tell me, is animation an object property?
I assumed that with the help of the trajectory properties I could select all animated objects - I made a mistake.
Is it possible to select animated objects in a scene without adding trajectory properties?

Reply to Andrey
miauu

.

fn isNodeAnimated node =
(
animated = off
object = node
if iskindof node SubAnim do
(
animated = (node.keys != undefined) and (node.keys.count > 0)
object = node.object
)
if iskindof object maxwrapper do for ca in object.custattributes while not animated do animated = isNodeAnimated ca
for k=1 to node.numsubs while not animated do animated = isNodeAnimated node[k]
animated
)

fn findAnimatedNodes nodes: =
(
if nodes == unsupplied do nodes = objects as array
for node in nodes where (isNodeAnimated node) collect node
)
fn findAnimatedTransformNodes nodes: =
(
if nodes == unsupplied do nodes = objects as array
for node in nodes where (isNodeAnimated node.controller) collect node
)

Reply to miauu
Andrey

Interesting

I do not understand how this script works.
Please explain how to highlight the animation in the scene.

Reply to Andrey
miauu

.

Use the code below.

The findAnimatedTransformNodes checks if objects's controllers are animated.

The findAnimatedNodes check if the objcet itself is animated.
As the functions is called in the code all objects in the scene will be checked. If you want to check only certain object call the functions this way:
resArr = findAnimatedTransformNodes nodes:(selection as array)


(
	fn isNodeAnimated node =
	(
		animated = off
		object = node
		if iskindof node SubAnim do
		(
			animated = (node.keys != undefined) and (node.keys.count > 0)
			object = node.object
		)
		if iskindof object maxwrapper do for ca in object.custattributes while not animated do animated = isNodeAnimated ca
		for k=1 to node.numsubs while not animated do animated = isNodeAnimated node[k]
		animated
	)

	fn findAnimatedNodes nodes: =
	(
		if nodes == unsupplied do nodes = objects as array
		for node in nodes where (isNodeAnimated node) collect node
	)
	fn findAnimatedTransformNodes nodes: =
	(
		if nodes == unsupplied do nodes = objects as array
		for node in nodes where (isNodeAnimated node.controller) collect node
	)
	
	resArr1 = findAnimatedTransformNodes()
	print resArr1
select resArr1
	
	resArr2 = findAnimatedNodes()
	print resArr2
select resArr2
)
Reply to miauu
Andrey

Thank you very much!
I did not know how to add selection of objects to your solution.
Now everything works.

Reply to miauu
Andrey

Hello Miauu

Please tell me how to fix the script - selecting an object by its property?
I need to ignore hidden objects when highlighting.
Thanks for your help!

Reply to Andrey
miauu

.


(
	global rol_selObjsByProperty
	try(destroyDialog rol_selObjsByProperty)catch()
	rollout rol_selObjsByProperty "Select objects by property"
	(
		group "Selcet objects with"
		(
			button btn_selByDAB "Display as box" width:120
			button btn_selByBC "Backface cull" width:120
			button btn_selByT "Trajectory" width:120
			button btn_selByVT "Vertex tricks" width:120
		)
 
		function SelectByProperty property: =
		(
			objsToSelArr = #()
			for o in objects where o.isHidden == false and (isProperty o property) do
			(
				if (getProperty o property) == true do
					append objsToSelArr o
			)
			select objsToSelArr
		)
 
		on btn_selByDAB pressed do
		(
			SelectByProperty property:#boxmode
		)
		on btn_selByBC pressed do
		(
			SelectByProperty property:#backfacecull
		)
		on btn_selByT pressed do
		(
			SelectByProperty property:#showTrajectory
		)
		on btn_selByVT pressed do
		(
			SelectByProperty property:#vertexTicks
		)
 
	)
	createdialog rol_selObjsByProperty 
)
Reply to miauu
Andrey

Thank you

I did differently:
----------
function SelectByProperty property: =
(
objsToSelArr = #()
for o in objects where (isProperty o property) and not o.isHiddenInVpt do
(
if (getProperty o property) == true do
append objsToSelArr o
)
select objsToSelArr
)
----------
Both options work.