Get type of selected item/object ?


#1

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


#2

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


#3

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

#4

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


#5

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


#6

Hey

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

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



#7

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…


#8

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 :confused:

Ahh found it… its

if Classof aa.parent == Dummy do

;/


#9

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.


#10

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



#11

a good one Mr.Aaandres, but for newbie in maxscript it would be total disaster and contain little bit educative in his/her learning curve …it would be better to answer it with maxscript way of talk first, I think.IMHO.


#12

That is what @PePeTD, @vusta, @Heilandzack and you have done, very well as always.
Is there any problem with showing an alternative way after the ‘offitial’ way? Perhaps @Darius1989 finds it easier and clearer.

In fact, I don’t imagine DenisT, PolyTools3D or you using maxLINQ (except perhaps for some few commands), as you can do it easy with your knowhow and more specific for your needs.
I think maxLINQ can be a sweet tool for occasional scripters who need easy/quick results for their problems.


#13

You can also filter your selection using ObjectSets. Just search for that in the Max help doc.


select (for obj in geometry where obj.isSelected collect obj)


#14

for ob in obj do
(
print ( classof obj)
)


#15

go back to the original question which as I can guess is about to how get all Geometry objects from the list.

most solutions above give you the right answers with using some general methods.

but specifically in your case it (how aaandres already showed but in a fancy way :wink: ) could be:

geo_nodes = for node in nodes where isKindOf node GeometryClass collect node

there is a specific Geometry Object in the MAX system. It’s a Target Light’s target. It also goes into this list but can be filtered by several extra checks.