Similar to my
MEL Questions thread from a while ago (thanks everyone for helping me on that btw
), Im spending some time learning Maxscript and have some questions I'd like to ask.
Only one question for the time being (but more to follow):
1. Is their a universal way to open options windows for specific tools? For example, If I wanted to use the connect tool I could use something like:
$.connectEdgeSegments = 1
to make an edge connection with a specified number of segments or
$.EditablePoly.ConnectEdges ()
to connect edges based on the previous settings used in the tool. But how would I go about opening the options window that contains segments/slide/pinch values? Is their a universal way to do this across all standard poly modeling tools? The listener doesn't record this action and I'm finding the Maxscript help to be far less user friendly then Mayas.
edit: oh just fyi, I'm using Max2009 x64.
Replies
See Editable_Poly Properties for all the other settings you're looking for. A little piece of advice, in the reference don't trust the Index, perform a Search.
For methods related to connecting edges, see
EditablePoly Interface - Connect
EditablePoly Interface - UI Commands - buttonOp #ConnectEdges method
If you want to set these parameters for each Editable Poly in the scene you need to loop over every single valid node and do it like:
So something like this:
Yea, Bryan that's exactly what I was after. Sorry for not replying earlier, but didn't want to have to bump the thread with a double post later.
Anyhow, got two new questions I'd like to ask:
2. How would you determin the type of modifier the user has selected, and whats the best approach to dealing with Edit Poly modifiers (so that a function works on both Editable Poly and Edit Poly)? Is it best to just iterate down through the stack until reaching it / hitting the bottom, performing the appropriate action and then returning to the originally selected sub object level, or is their a faster way?
3. Max seems to give a return value for every "if" statement, even if its false (in which case it returns "undefined"). Is this alright? In MEL it would simply ignore such cases and give no return as it was generally not needed. Giving dozens of "undefined" returns for a simple script seems odd. This may be a dumb question, but I'm wondering if its something I should be concerned with.
3. hmm what's returning undefined after an if statement? a function? If it's a function and you set a return value for the 'If' statement and no catch return statement for the 'Else' it'll return undefined when 'Else' is run.
2.
The Base Object, like an Editable Poly, can be accessed with the syntax:
Ref: "General Node Properties"
The Modifiers in the Stack, like Edit Poly Modifier, are grouped in a collection called Modifiers, so you can get a pointer them with the syntax:
Ref: "Modifier Common Properties, Operators, and Methods"
The currently active modifier/base object can be retrieved with: then you need to check its class to determine its nature.
Ref: "Modify Panel"
If you want to write a function that works seamlessly on both EditablePoly and EditPolyModifier, you need to get the currently active EditObject in the Modifier Stack, determine its nature and execute the specific code. If none of them is active, you got two choices: one let the function fail (do nothing), two activate first suitable Edit Object in the Stack and run the proper code.
To do that you must cycle over the Modifiers array from the position you currently are and one by one scan for the EditPoly Modifier until reach the bottom, the Base Object (in reverse, because first modifier is the lowest in the stack and you must scan it from top to bottom). While scanning you need to turn off the modifiers because the geometry pipeline evaluation must be stopped at the right Modifier/BaseObject. In other words what you you see in viewport is the actual geometry. In example, if you got a box, made by 8 verts and apply a TurboSmooth it becomes a 26 verts box. If you activate the baseObject but have the Show End Result active and query the number of vertices, you got still 26. after the function you need to turn back on the modifiers. The most clever way to do that is to save their state into an array while scanning and then revert their state to the saved one.
You can take a look at the two functions I coded to perform these actions on the stack for the Editable Poly as Base Object on IllusionCatalyst web site, page MaxScript, under "Editable Poly data from underlying Mesh", functions modViewOff() and modViewOn(). They're not the most updated, but do the job.
Keep in mind that when you deal with Editable Poly Modifiers, they MUST be the currently active Edit Object in the stack, or most of the function on them don't return any value. It means you can't perform anything by simply writing such as: unless it is the currently active Edit Object. You set the Edit object with:
About the general coding strategy to deal with both EditablePoly and EditPolyModifier, I usually build a wrapper. In this case a structure, which is initialized by taking the current node, then running functions such as modViewOff/On() and getting the BaseObject, the current Edit Object and the current Mesh. The the structure mimes the common polyOp structure and have functions which can execute the proper code depending on the object initialized. When you develop your code, rather than calling polyOp, or methods for the Edit Poly Modifier, you simply call that struct's methods, like: and it does the job returning what you want.
3.
I'm not completely sure about your question. I get it in this way: every if statement returns a value you can use to assign to a variable like: This is a perfectly legal way to use the if statement but quite unusual in my experience. More often you simply use the statement like it is supposed to:
If it is not what you mean, please post a little sample of your code.
You can see how the call to PolyWrapper methods is the same for both Editable Poly and Edit Poly Modifiers. You need to reinit the structure every time the scene/selection/stack has changed before calling its methods.