Notifications
Clear all

[Closed] MaxScript questions coming from a Maya user

1) What is the difference between these method for getting the current selection for a loop?

for obj in $ do -- method 1
for obj in selection do -- method 2
for obj in $ as array do -- method 3
for obj in selection as array do --method 4

2) If I for example print a variable of the selection, I will just get:

$Editable_Poly:obj01 @ [0.000000,0.000000,0.000000]

I will get this regardless of whether I’ve selected faces, vertices or the object. I’m guessing this ($Editable_Poly) is just that class related to the type of object I’ve selected?

3) I’m coming from Python in Maya, and in Python use can use the dir-function to print all available commands on an object. Is there something similar in MaxScript?

4) In Maya, if you for example want to get all of the faces of an object, you can just use cmds.ls(selection + ‘.f
[li]’, flatten=True), then you can perform actions on the faces without actually selecting them. While in 3dsMax it seems like you actually have to select everything you want to work with. In all of the scripts I’ve seen, people goes into modify mode, change the subobjectlevel forth and back all the time. This seems both messy, tedious, and will naturally go a lot slower than working with objects without actually selecting the different components all the time. Is this really the case? Or is there some way to work with the mesh without actually doing every single step as you would when doing it manually?[/li]

5) Again, in Python, if I want to see if a variable contains any data, I can just use if variable: do something. In 3dsMax you can do if variableName != undefined do (bla bla). Or in some cases you can do if variableName.count > 1 do (bla bla). The problem is that I have to use the different checks based on what kind of data the variable contains. If for example the variableName is empty, the count-method will throw an error.

6) The last one, this isn’t really MaxScript related, but how come objects seem to be able to share the same name? I can have houndreds of objects with the same name. Is that the case, or does Max hide the “real” name of the objects?

14 Replies
1 Reply
(@lonerobot)
Joined: 11 months ago

Posts: 0

Already some good answers here from Heilandzack but I’ll just add mine also to clarify things further.

The best way to see the difference here is to try it, $ is a reserved variable for the current selection, as is selection, but they will perform differently. If you attempt to iterate over the $ variable, you will have to have something actually selected, other wise you with throw an error. If you do the same over selection when there is no object selected, it will iterate over and empty array. For this reason, selection is always preferable to using $.
.


for obj in $ do print obj.name
-- No "map" function for undefined
for obj in selection do print obj.name
OK

The syntax is…


show <variable> -- to show the properties
showmethods <variable> -- to get the functions
getpropnames <variable>

also,

getinterface <variable> -- for interfaces (another form of scripted access)

If you are using maya python, you’ll be used to parsing strings to interact with objects like with getAttr and setAttr. These are not nodes (or objects). Maxscript is almost always giving you the node or node collection, meaning you don’t need to know the object name or have the node selected to interact with it. There are some exceptions, where certain modifiers need to be active in the mod panel and in subobject mode in order to work (skin for example)

I learned python before I looked at python in maya, and coming from maxscript was easy. If you know any OO languages then you’ll find maxscript easy and powerful to use.

Good luck and feel free to contact me if you are unsure of anything.

I’ll just try my luck here. If i’m wrong in some points, correct me guys

From the Maxscript help:

getCurrentSelection()

Returns the current selection as an array. This is similar to selection as array, however selection as array returns a copy of the selection.

I don’t know the exact difference between $ and selection, but in cases they return different values. Personally i use $ if i have one selected object and selection to loop through my selected objects paired with “where classof myObject == wantedClass” to filter for the requested object class.

I will get this regardless of whether I’ve selected faces, vertices or the object. I’m guessing this ($Editable_Poly) is just that class related to the type of object I’ve selected?
yes that’s right. There are different methods for editpoly modifier, editable poly object, editable mesh object, etc.

  1. I’m coming from Python in Maya, and in Python use can use the dir-function to print all available commands on an object. Is there something similar in MaxScript?
    There are some ways. You can use $.showproperties and $.showmethods. Turning on the Macrorecorder in the Maxscript listener can also give you Information when changing things the manual way.

In all of the scripts I’ve seen, people goes into modify mode, change the subobjectlevel forth and back all the time. This seems both messy, tedious, and will naturally go a lot slower than working with objects without actually selecting the different components all the time. Is this really the case? Or is there some way to work with the mesh without actually doing every single step as you would when doing it manually?
Imitating the manual way is not the best way to do it. As i said before, there are alot different methods for any class of geometry, find more Information about that in the Maxscript help. As an example:

polyop.getVertSelection <Poly poly>

Returns the current vertex selection as a bitarray

polyop.setVertSelection <Poly poly> <vertlist>

Sets the current vertex selection based on

About question Nr. 5, have a look at classof() in the maxscript help. This doesn’t only apply to variables, it also applies to Objects/Nodes.

  1. The last one, this isn’t really MaxScript related, but how come objects seem to be able to share the same name? I can have houndreds of objects with the same name. Is that the case, or does Max hide the “real” name of the objects?
    You can have Objects with the same name, however you still have Object GUID’s or so-called handles.

As an example:

$.inode.handle

Returns the unique object handle

maxops.getnodebyhandle x

Returns the object with the given handle

Anyway, Maxscript help is very useful, although not complete.

I apologize for my english, since it’s not my first language.
And no warranties for the correctness of my answers, there are guys way better than me.

 lo1

Agreeing with what Pete wrote, $ was only introduced so you wouldn’t have to write ‘selection’ for quick listener commands. You would be wise never to use it in an actual script.

I’ll have to disagree on that one. MAXScript is one of the most structurally incoherent languages I’ve come across, what I assume is a result of over 20 years of gradual development, and unfortunately mirrors the utter chaos that is the 3dsmax SDK.

Some operations are done via global methods and variables you just kind of have to know about in advance. My least favorite are the type of global commands which can take multiple types of inputs – e.g. “copy”. Were it really an OO language, ‘copy’ would be a method of ‘Array’ or ‘Mesh’.

Some operations are built using the function publishing system, and some are done via Paramblocks.

Another example is callbacks. Can anyone explain why we need all of the following mechanisms:
[ul]
[li]General Event Callback System
[/li][li]Node Event System
[/li][li]Time Change Callback
[/li][li]Viewport Redraw Callback
[/li][li]‘When’ Construct
[/li][/ul]

Couldn’t we just have one and register all the different events through it?

It’s a powerful language indeed, but it’s very evident it was developed over a long period of time by different people.

5 Replies
(@lonerobot)
Joined: 11 months ago

Posts: 0

You make good points Rotem.

I kind of feel like that about Python too!

Recently, I spent some time away from Max and Maxscript to learn a bit of Maya and python and coming back I was struck at how easy and accessible it is. I think you can use languages in two ways – quick and dirty scripting to solve a problem, and more in-depth structured approach for more advanced systems. I’m also sure that if it wasn’t accessible, I’d have remained an animator.

I agree there are inconsistencies (like most languages) but I don’t think I really got Maxscript until I learned some dotnet. I certainly used it like a scripting language for many years. Perhaps that is more to do with the fact that a more structured approach forces you to think of it more like a programming language. Maxscript isn’t OO, but it does at least tip it’s hat towards it.

(@gandhics)
Joined: 11 months ago

Posts: 0

Totally agree.
Try to get the material of an object.

In Maxscript, it would be

o.material

Try to do same thing in Maya.

(@denist)
Joined: 11 months ago

Posts: 0

you can do the same in maya using pymel. but… the price is very high.

(@denist)
Joined: 11 months ago

Posts: 0

no, we can’t.

first of all these callback mechanisms use absolutely different sets of events. they are watching(monitoring) different parts of the system, and each part is responsible for its own events firing.
second that some events firing is not guarantied at all. for example redraw callback is a part of viewport renderer system, and custom renderer should support it but doesn’t have to.

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

That’s exactly the issue. If each part would instead implement some IEventSource interface instead of reinventing the wheel there would be no problem.

Heilandzack: Dude, your english is flawless! Thank you man! Awesome

LoneRobot: Ah I get it now, thank you very much sir! You filled in perfectly on what Heilandzack wrote!

Thank you both so much! I really appreciate you guys taking the time to give so thorough explanations! You rock!

Interesting discussion!

Just one more question, still a bit dumbfounded here. Lets say I want a list of all of the edges of an object without having max actually selecting them, I’ve searched around and tried to find out how to do this, but ALL scripts I find do select the darn edges, then it stores the selection.

Coming from Maya, I basicly want to do as much as possible without having max actually perform all of the steps you would do if you were doing it manually. It’s just a lot slower. I know you can disable the viewport from updating while the script is running, but it just seems so messy!

if it’s a polygon object, you can just call

polyop.getNumEdges <Poly poly>

In practise, to select ALL the edges without selecting the object, going into subobject etc, etc would be

polyop.setEdgeSelection <Poly poly> #{1..(polyop.getNumEdges <Poly poly>)}

as you are simply passing the edge count as a bitarray. The key to this is you can set and get vert and edge selections without having to perform the steps manually through code. Meshes are slightly different, but you can look at the meshOp structure to find a similar approach.

Also this can help


delete objects
obj = converttopoly (sphere())
edges_count = obj.edges.count
edges_list = #{1..edges_count}
obj.selectededges = edges_list
-- select obhect only to see result
select obj
subobjectLevel = 2

Lets say I want a list of all of the edges of an object without having max actually selecting them, I’ve searched around and tried to find out how to do this, but ALL scripts I find do select the darn edges, then it stores the selection.

you can also use the name value #all when you want “apply” a function to all the elements of a mesh. for example…


delete objects;
b = box();
 converttopoly b;
polyop.chamferedges b #all 4.0;

Ah I finally get it! What was confusing me was that the commands had “polyop.setEdgeSelection”, I thought that meant that max actually selected it, but it doesn’t look like it does. Thank you :applause: