ScriptSpot

Forum topic · General Scripting

Detecting Max object types

By coyote808 · 2013-03-13

Description

I think a really simple question. Writing a script that manipulates Max text objects - including changing the text. For error checking i need to be able to tell if the selected object is a text object. If it's a mesh object like Sphere001, or Plane001, the script will die as

$.text

is undefined for those object types.

I'm looking for a conditional test that i can wrap around all my text control commands.

if ($ is a text object) then
(
do all the text stuff
)
else
(
warn user to select text object
)

Thanks!

Comments (4)

to continue

barigazy · 2013-03-13

other conditional tests:


if getclassname selection[1] == "Text" do...

You can also use unique text shape properties for checking like

obj = selection[1] -- define variable selection
if isProperty obj "kerning" do...
--or
if isProperty obj "leading" do...
--etc.

to collect all text "stuffs" ;)

barigazy · 2013-03-13


if selection.count != 0 do
(
	if iskindof (txt=selection[1]) text then
	(
		clearlistener()
		local props = getpropnames txt
		for i = 1 to props.count do format ("$"+txt.name+"."+props[i] as string + " = %\n") (getProperty txt props[i])
	)
	else messageBox "You need to pick text shape first!" title:"Warning" beep:off
)

Then open the listener to see the result

if classof $ == text then

miauu · 2013-03-13


if classof $ == text then ...
if isKindOF $ text then ...

or you can use


	if classof $.baseobject == text then ...
	if isKindOF $.baseobject text then ..

Thanks!

coyote808 · 2013-03-13

This forum is really a huge help to newbies. The Max Script docs are complete but there's so much detail. It's hard to know what to search for.

Thanks again - to both responders!