View Full Version : Arrays only work with more than 1 object..
3rd Dimentia 08-15-2007, 01:29 PM I'm writing a script that does things to objects. What it does isn't important. What's important is that I have 2 buttons, 1 that does this action to all objects. Which is working fine. The other button does stuff only to selected objects.
I'm doing this by converting the selection to an array and doing the modification to the items in the Array which works fine. BUT when there is only 1 object selected, maxscript errors saying that it can't convert the selection to an array. So the way I got around that was to have an if/then/else to test whether there are more than 1 objects selected and then it goes on as normal, but if there is only 1 selected, then it does the modification in a different way that doesn't involve an array. What I'm keen to know is, is this the best way to go about this? It seems that it's a bit long winded... sort of like this post. :)
Thanks.
|
|
erilaz
08-15-2007, 01:37 PM
This by itself works fine:
newArray = selection as array
Even if there is nothing selected, it will still create a blank array.
If your code is different to this, can you show what you are using to convert the selection?
3rd Dimentia
08-15-2007, 01:47 PM
ah, thank you. I was using:
newarray = $ as array
Which worked fine until I only had 1 object selected, which would then return:
>> MAXScript Rollout Handler Exception: -- Unable to convert: $Editable_Mesh:Torus01 @ [46.438747,0.000000,0.854701] to type: Array <<
I guess there is a difference in what $ means when there is only 1 object selected.. but SELECTION would mean the same thing either way.
Cheers for that
erilaz
08-15-2007, 02:05 PM
ah, thank you. I was using:
newarray = $ as array
to which I was getting
>> MAXScript Rollout Handler Exception: -- Unable to convert: $Editable_Mesh:Torus01 @ [46.438747,0.000000,0.854701] to type: Array <<
I guess there is a difference in what $ means when there is only 1 object selected.. but SELECTION would mean the same thing either way.
Cheers for that
Ah, right. Yes, that would be correct. The $ is assigned an individual node on it's own (in order for ease of access to properties etc, such as $.wirecolor etc). Max automatically generates $ as an array on more than one selection, so array access would be required then.
I guess you could say that for single nodes:
$ = selection[1]
Whereas multiple selections:
$ = selection[n...]
Probably not the best way to explain it, but you get the gist! :D
3rd Dimentia
08-15-2007, 02:17 PM
If you keep answering my maxscript questions like this, I think I might just email you directly. :)
Thanks again.
Cg.
erilaz
08-15-2007, 02:36 PM
If you keep answering my maxscript questions like this, I think I might just email you directly. :)
Thanks again.
Cg.
If you're the same Chris from maxpro, you could! :D
3rd Dimentia
08-15-2007, 02:45 PM
If you're the same Chris from maxpro, you could! :D
Yup, that's me. I'm tempted to send you my ICQ or MSN contact. hehe..
focomoso
08-15-2007, 07:50 PM
If you keep answering my maxscript questions like this, I think I might just email you directly. :)
Can I ask that you don't? I mean, feel free to email each other, but having the discussions out in the open helps more more people than if you just ask each other in private. Usually, if one person's having a problem, many others are having the same problem as well.
erilaz
08-15-2007, 11:04 PM
Can I ask that you don't? I mean, feel free to email each other, but having the discussions out in the open helps more more people than if you just ask each other in private. Usually, if one person's having a problem, many others are having the same problem as well.
A very good point James! Will do.:)
CGTalk Moderation
08-15-2007, 11:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.