PDA

View Full Version : [MAXScript] Unable to Convert


Nukie
13-07-2007, 03:14 PM
Hi,

I have started learning MAXScript, and for that I'm following the tutorials that come with max. At this point I'm following the "How To" tutorials, and so far i'm at tutorial 5 "Selecting Non-Quad Polygons".

The tutorial itself is clear and it also works, but I thought "Lets try some things for myself" so instead of making a MacroScript I'm trying to create a rollout with 2 buttons: One for selecting the Non-Quads and one for deselecting them. Now this isnt so much of a problem and the rollout works, but the button (so far I'm still trying to get the "Select All" button to work) doesnt.

When I select my model (for testing I'm using a simple GeoSphere converted to Edit Poly) the script gives me the following error:

-- Unable to convert: true to type: Integer

The error highlights this line from the code:

polyop.setfaceselection base_obj face_selection

And here is the complete code:


rollout SelectNonQuads "Select all Non-Quad Polygons"
(
label lab "Select all Non-Quad Polygons"
button select "Select All" pos:[10,30]
button deselect "Deselect All" pos:[80,30]

on select pressed do
(
local face_selection = #()
local base_obj = $.baseobject
local num_faces = polyop.getnumfaces base_obj

for f = 1 to num_faces do
(
local num_face_verts = polyop.getfacedeg base_obj f
if num_face_verts != 4 do face_selection[f] = true
)

polyop.setfaceselection base_obj face_selection
max modify mode
modpanel.setcurrentobject base_obj
subobjectlevel = 4
)
)

createdialog SelectNonQuads width:160 height:60

Maybe worth to mention I'm not a die-hard programmer :p

Nukie
16-07-2007, 07:58 PM
230 pageviews and noone knows whats wrong? :(

Mr. Bluesummers-3DT
16-07-2007, 08:20 PM
Quick Reply
Hmm...I think its because part of your code is trying to access an integer to select faces, but it's not getting the right type of data.


if num_face_verts != 4 do face_selection[f] = true


I bet that's the offending line. It's setting a {true,false,true,false} bit array when the polyOp method is expecting a {1,2,3,...n} list of faces to select. I'm at work so I can't fix the code for you, but that's probably where the problem is!

P.S. Try to "append" the array with face f rather than setting a bit at f. Your new line should resemble

if num_face_verts != 4 do face_selection = append face_selection f

Mr. Bluesummers-3DT
17-07-2007, 02:34 AM
P.S.
MaxScript isn't discussed in this community as much as it should. I'm sorry so much time has passed since you posted!

Nukie
17-07-2007, 09:00 PM
Hey thanks man. No problem it took a while, I'm glad someone could help me. The code you gave me works perfectly.

Can you please explain me what the "append" part does? As I said I'm not a die hard programmer but I want to learn it.

Mr. Bluesummers-3DT
17-07-2007, 10:01 PM
Quick Reply
No worries. The help file says:

append <array> <value>
Append value to array, growing it as necessary. Returns the resulting array.

It takes the array you passed it, slams the <value> parameter onto the end, and returns the resulting array. Below are some lines about how that works:

--Let's have an array
thisArray = #("cherry", "grape", "lime")

--Let's append another flavor!
append thisArray "orange"

--Wo oh, append doesn't alter the array, it returns the result. We didn't catch it!
format "This array contains: %\n" thisArray

--Here's how we can catch the operation's result into the same array...
thisArray = append thisArray "orange"

--Just to double check.
format "This array contains: %\n" thisArray


The important thing to note here is that it doesn't modify the array directly; it returns the appended array. You have to assign it back into a variable, or it won't count. Not all array operations work like this, so it's important to keep the documentation handy when you're coding. :haha:

Happy scripting!

Mr. Bluesummers-3DT
17-07-2007, 10:05 PM
P.S.
Well, color me confused! It's not supposed to work like that, but I tested out that code block in Max8 and it appended the array without having to reassign. Wierd!

I guess you can go ahead and use

append thisArray "orange"

and count on it appending the array properly. *Shrug*

Nukie
18-07-2007, 12:52 AM
Thanks for clearing it up...