ScriptSpot

Forum topic · General Scripting

Spline selection problem

By Mrjacks2o · 2010-05-13

Description

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

martinmalamud · 2010-05-25

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 · 2010-05-25

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

Mrjacks2o · 2010-05-25

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

Armen

Anubis · 2010-05-18

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

Mrjacks2o · 2010-05-25

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 · 2010-05-15

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 · 2010-05-25

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