Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

Trying to select geometry using script.
show user profile  jpedleham
Its so simple. It works if i type it in the listener but as soon as i put it into a script the code halts and throws the error -- No ""select"" function for undefined. Ive tried 'select all' 'select objects' and i even get this error when using collapsestack($) within a script.
Am i doing something wrong?

if selection.count >= 1 then
local selectedGeom = selection as array
local newMat = multisubmaterial() = "newMat"
newMat.count = 0
meditMaterials[1] = newMat

addModifier selectedGeom[1] (Materialmodifier ())
selectedGeom[1].modifiers[#Material].materialID = 1
newMat.material[1] = selectedGeom[1].material
selectedGeom[1].material = newMat

for i in 2 to selectedGeom.count do
doesMatExist = findItem newMat.material selectedGeom[i].material

--print doesMatExist
if doesMatExist == 0 then
addModifier selectedGeom[i] (Materialmodifier ())
selectedGeom[i].modifiers[#Material].materialID = newMat.material.count+1
newMat.material[newMat.material.count+1] = selectedGeom[i].material
selectedGeom[i].material = newMat
addModifier selectedGeom[i] (Materialmodifier ())
selectedGeom[i].modifiers[#Material].materialID = doesMatExist
selectedGeom[i].material = newMat
select all

read 464 times
11/25/2014 9:11:00 PM (last edit: 11/25/2014 9:11:00 PM)
show user profile  Garp
Replace select all with select objects.

Are you using an old version of max? I see some deprecated code there.

read 442 times
11/26/2014 5:40:57 AM (last edit: 11/26/2014 5:42:24 AM)
show user profile  jpedleham
Im using design 2014 but its code i found online and am adaptting for my needs. im a massive beginner at maxscripting thoug.h. the code works for what i need it to do for now anyway. Your suggestion worked by the way thanks! I tried it before but i think i had left it out of the brackets which seems to affect it. I assume in maxscript the first bracket means the beginning of the script?
read 421 times
11/26/2014 2:57:12 PM (last edit: 11/26/2014 2:57:12 PM)
show user profile  Garp
Glad it worked. Here is the best place I know of to get started with mxs.

> I assume in maxscript the first bracket means the beginning of the script?

It's always a good idea to enclose the entire script in its own block. Otherwise, any top-level variable is a global variable since it's declared at global scope (even if explicitely declared local).

read 417 times
11/26/2014 3:08:07 PM (last edit: 11/26/2014 3:08:07 PM)
show user profile  jpedleham
Ah thats great thanks i saw this on the scriptspot news so ill definitely give it a go!
Thats good to know about the brackets too. better to begin with good practices rather than have to implement them later on.
read 409 times
11/26/2014 4:15:35 PM (last edit: 11/26/2014 4:15:35 PM)
show user profile  reeves1984
I'd like to suggest learning python rather than doing it in in maxscript as it's much more useful for you in general, but..

I'm not sure it's that practical to learn like that with lack of resources

Simon Reeves - VFX Artist & Blog
twitter <-- I work here

read 401 times
11/26/2014 5:09:03 PM (last edit: 11/26/2014 5:09:03 PM)
show user profile  Dub.
Python is soooo not ready for prime time in Max. It's a great language to learn, but I wouldn't recommend it for use in Max for a beginner.

read 381 times
11/27/2014 3:43:16 AM (last edit: 11/27/2014 3:43:16 AM)
show user profile  reeves1984
yeah there you go :)

Simon Reeves - VFX Artist & Blog
twitter <-- I work here

read 360 times
11/28/2014 2:31:27 PM (last edit: 11/28/2014 2:31:27 PM)
#Maxforums IRC
Open chat window