Spline selection problem

Hi
My problem is when you press the button in my script and if a spline shape is selected i want it to go to subobjectLevel = 1
if its a polygon object or a mesh object or any other object other then a spline shape i want it to say messageBox "You must select a shape "
this is what i tried no luck

On ON3 pressed do
(
objs = getCurrentSelection();
(
if (classOf objs == SplineShape ) then
subobjectLevel = 1
else
messageBox "You must select a shape..."
)
)

Thanks in advance!!!!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
martinmalamud's picture

Hi ! If you want to write

Hi !
If you want to write more than one instruction after a then, you need to add parentheses.
The script must be:

On ON1 pressed do
(
objs = getCurrentSelection();
if (objs.count > 0) then
(
(
if ((classOf objs[1] == SplineShape) or (classOf objs[1] == Line)) then
(
max modify mode --( This is my error )
subobjectLevel = 1
)
else
messageBox "You must select a shapegggggg..."

)
)

Regards.

Martin

Anubis's picture

Hi Martin, I receive a

Hi Martin, I receive a message from you and reply to it but your mail server return an error, so I'll reply here again. In the mail you send me different code. There was "then" context without brackets. Shortly, if "then" or any other context sensitive statement has more than 1 command, then it contain body *must* be inside closed (round) brackets, e.g.:

-- next would be wrong 'cause the Max dont know where the "then" context end:
if isShapeObject $ then
	max modify mode
	subobjectLevel = 1
else
	messageBox "You must select a shape..."
 
-- next would be correct:
if isShapeObject $ then
(
	max modify mode
	subobjectLevel = 1
)
else
	messageBox "You must select a shape..."
 
-- the next code is also correct:
if isShapeObject $ then (
	max modify mode
	subobjectLevel = 1
) else (messageBox "You must select a shape...")

And in the current code that you post here, I see one open bracket that is not closed:

On ON1 pressed do
(
	objs = getCurrentSelection();
	if (objs.count > 0) then
	(
		--( -- what do this here? REMOVE this bracket!
		if ((classOf objs[1] == SplineShape) or (classOf objs[1] == Line)) then
		(
			max modify mode
			subobjectLevel = 1
		)
		else
			messageBox "You must select a shapegggggg..."
	)
)

And one suggestion as well - when post a script code in the forum use [ CODE ] tags [ /CODE ] ;-)

my recent MAXScripts RSS (archive here)

Mrjacks2o's picture

Thanks allot!!!! i finally

Thanks allot!!!! i finally got this script working normally without any errors

Armen

Anubis's picture

You can use the isShapeObject

You can use the isShapeObject function as well (to simplify the code).

on myBtn pressed do
(
    if selection.count == 1 do (
        if isShapeObject $ then
            subobjectLevel = 1
        else
            messageBox "You must select a shape..."
    )
)

my recent MAXScripts RSS (archive here)

Mrjacks2o's picture

thanks for the help guys it

thanks for the help guys it worked but quick question for Anubis
I was trying to add 1 more line of script but it gives me an error how would i
add lets say 2 - 3 more lines of script without getting an error

On ON1 pressed do
if selection.count == 1 do
(
if isShapeObject $ then
max modify mode ( i added this and got am error )
subobjectLevel = 1
else
messageBox "You must select a shape..."
)

martinmalamud's picture

There are a few problems in

There are a few problems in your script.
This one runs:

(
objs = getCurrentSelection();
if (objs.count > 0) then
(
(
if ((classOf objs[1] == SplineShape) or (classOf objs[1] == Line)) then
subobjectLevel = 1
else
messageBox "You must select a shape..."
)
else
messageBox "You must select a shape..."
)

1-objs is an array, you want to know about the first element in such array ( objs[1] )
2-if you create a line the class if "line"
3-what happend if nothing is selected ( objs.count > 0 )

I hope this solve your problem !

Mrjacks2o's picture

Thanks for the help guys it

Thanks for the help guys it worked Great same question for your script how can i add another line of script without getting an error thanks

On ON1 pressed do
(
objs = getCurrentSelection();
if (objs.count > 0) then
(
(
if ((classOf objs[1] == SplineShape) or (classOf objs[1] == Line)) then
max modify mode ( This is my error )
subobjectLevel = 1
else
messageBox "You must select a shapegggggg..."
)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.