Notifications
Clear all

[Closed] Get type of selected item/object ?

Hey

I must be barking the wrong Tree but how can I get type of selected object?

I’m trying

for ob in obj do
(
	print classOf ob 
)

But I must be doing something wrong…

Regards
Dariusz

14 Replies

(
local fmt = format  , clsOf = classOf 
for i in selection do
    (
           fmt "Object Name  : % | Class : %
" (i.name) (clsOf i)
    )
)

Thank you!

Hmmm this gives me Edit_Poly or Cylinder… how can I get geometry?

I’m trying to filter my selection in to lights/cameras/geometry/dummies etc etc…

(
local fmt = format  , clsOf = classOf 
for i in selection do
    (
           --fmt "Object Name  : % | Class : %
" (i.name) (clsOf i)
			if clsOf i == Dummy do
			(
				print "DUMMY"
			)
			if i == Geometry do
			(
				print "GEO"
			)
    )
)

I dont know what your purpose is, but here


-- this 
rollout unnamedRollout "Untitled" width:162 height:300
(
	fn xobj obj = superclassOf obj == GeometryClass

	pickbutton btn1 "PickButton" pos:[20,22] width:81 height:57 filter:xobj 
 
)
CreateDialog unnamedRollout

or this


for i in selection do 
(
	case (superClassOf i ) of 
	(
		(GeometryClass)	 	: (format "object : % | superclass : %
"  (i.name) "this is GeometryClass")
		
		(light) 			: (format "object : % | superclass : %
"  (i.name) "this is light")
		
		(camera)			: (format "object : % | superclass : %
"  (i.name) "this is camera")
		
		(helper)			: (format "object : % | superclass : %
"  (i.name) "this is helper")
		
		(SpacewarpObject)	: (format "object : % | superclass : %
"  (i.name) "this is SpacewarpObject")
	)
	
)

Simple enough.


for obj in selection do
(
	-- print method
	print ("Object:" + obj.name + " classOf:" + (classOf obj as string) + " superClassOf:" + (superClassOf obj as string))
	-- format method
	format "Object:% classOf:% superClassOf:%
" obj.name (classOf obj) (superClassOf obj)
)

Hey

Thanks guys. But this maxscripts feels very off to me so far :- ( Simple commands are a struggle to me

What is wrong in this command ?

for i in selection do 
(
	case (superClassOf i ) of 
	(
		(GeometryClass)	 	: 
		(
			format "object : % | superclass : %
"  (i.name) "this is GeometryClass"
			print "GEO"
			if i.parent == helper:
			(
				print "DUMMY"
				print "GRR"
			)
			
			print "xxxxxxx"
		)
)
)

Same with this1, how can we do simple if statements? I’m lost :- (

aa = "test"

if aa == "test" :  
(
print "whh"
)

Or :


aa = $
if (ClassOf aa) == Cylinder :
( print "xx")


you’re confusing the syntax of an If statement with the syntax of a Case statement…

http://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__files_GUID_9294EF2F_B785_462A_B30E_19CDE2CE2809_htm

http://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__files_GUID_21F52D81_8D49_4CBC_A8C4_3E906E150439_htm

I’m a mxs noob myself but simply search “maxscript blah” gets me there most of the time for basic stuff…

So the Case statement is more like

if a == 10:
print “aa is 10”
elif a == 15:
elif a == 20:

No idea it feels off to me, still reading on it.

What about this, why does this not work ?
It prints “Found Cylinder” but never the Dummy :- (

aa = $

if Classof aa == Cylinder do 
	(
		if Classof aa.parent == Helper do
			(
				print "Found Parent Helper"
			)
		print "Found Cylinder"
	)

I really must be googling wrong or something. Its pretty normal to loop by type in python maya/other software.

If type(a) == something:
do stuff…

In max it feels like no1 uses it or its really backward implemented

Ahh found it… its

if Classof aa.parent == Dummy do

;/

There are case statements and if statements. An example of each below:

Case/of:

print "Ouput case statement"
for obj in objects do
(
	case (superClassOf obj) of
	(
		GeometryClass: print (obj.name + " is Gemoetry")
		helper: print (obj.name + " is a helper")
		default: print (obj.name + " is of another type")
	)
)



If:

print "output if statement"
for obj in objects do
(
	if (superClassOf obj == GeometryClass) then print (obj.name + " is Gemoetry")
	else if (superClassOf obj == helper) then print (obj.name + " is a helper")
	else print (obj.name + " is of another type")
)
	




And then there are superclasses and classes. Example below:

Superclasses:

GeometryClass 
Shape 
Light 
Camera 
Helper 
SpacewarpObject 
System



Classes:

Box
Cone
Sphere
GeoSphere
Cylinder
Pyramid
....



If you check for a superclass use superClassOf $
If you check for a class, use ClassOf $

Another tip:
Always use “if (true) then” instead of “if (true) do”
“then” will allow you to put an “else” later on, “do” will not.

If you want to go through[B] maxLINQ /B:

	groups = (_From objects).GroupBy("obj=>superClassOf obj")
	for g in groups do
	(
		hasDummyParent = (_From g)._Where("obj=>isKindOf obj.parent Helper")
		if hasDummyParent.count != 0 do format "hasDummyParent: %
" hasDummyParent
	)

In a beautiful way:

	groups = (_From objects).GroupBy("key:obj=>superClassOf obj")
	for g in groups do
	(
		hasDummyParent = (_From g.value)._Where("obj=>isKindOf obj.parent Helper")
		format "Class: %
" g.key
		format "hasDummyParent: %
" hasDummyParent
	)

If you just want geometry objects that have a Helper parent:

	geomHasDummyParent = (_From objects)._Where("obj=>(isKindOf obj GeometryClass) and (isKindOf obj.parent Helper)")
	for obj in geomHasDummyParent do format "geomHasDummyParent: %
" obj


Page 1 / 2