PDA

View Full Version : How to automate changing from Editable Poly to Editable Mesh?


TechnicallyArtistic
07-19-2011, 07:06 PM
So I've got a crap ton of models to export. Skinned meshes on a rig. It's just the mesh that needs to be selected to export, but for the export file, it wants the mesh to be Editable Mesh rather than Editable Poly.

I'm trying to figure out how to automate this, but the code the macro recorder spits out isn't particularly helpful when you run it again. I don't need the selection to be automated, because the meshes are all named different things. But everything after that, yeah.

Right now the code it spits out is
$.modifiers[#Skin].mirrorEnabled = off
modPanel.setCurrentObject $.baseObject
modPanel.addModToSelection (Edit_Mesh ()) ui:on
deleteModifier $ 1
maxOps.CollapseNodeTo $ 2 off
$.modifiers[#Skin].cross_radius = 69.1181
$.modifiers[#Skin].mirrorEnabled = off


The steps I'm doing are in the modify panel selecting Editable Poly under the Skin modifier. Adding an Editable Mesh modifier on top of that. Then right clicking on the Editable Mesh modifier and click Collapse To.

So how the hell do you go about automatic stuff like this in Max, and what is the Macro Recorder good at if it cant' recreate the steps it just recorded?

denisT
07-19-2011, 07:48 PM
So I've got a crap ton of models to export. Skinned meshes on a rig. It's just the mesh that needs to be selected to export, but for the export file, it wants the mesh to be Editable Mesh rather than Editable Poly.


do you need to export skin data?
actually you don't need to convert poly to mesh to get an object's mesh data. any geometry object has property #mesh. is exactly the same data as you will get converting a poly to the mesh.

TechnicallyArtistic
07-19-2011, 08:19 PM
Its this old md5export script I'm using and it wants editable mesh to export the file. Not sure what's differnt between the two but I'm asuming they built in the check for a reason. Up to now I've been converting it by hand to get them to export.

I'm not super savy in max script so its taking a long time to modify the basics right now so I thought that would be the easier fix and replace the check with a converter rather than an error meesage.

Oh, and yeah, I've got to export out animation and skin data too.

denisT
07-19-2011, 08:44 PM
Its this old md5export script I'm using and it wants editable mesh to export the file. Not sure what's differnt between the two but I'm asuming they built in the check for a reason. Up to now I've been converting it by hand to get them to export.


if you need just export the meshes and don't have to really convert them to mesh you can apply the "Turn To Mesh" modifier to every not mesh object (skinned or not skinned). the Exporter has to eat it.

for the applying of the modifier you can use a script...
something like:

for node in Geometry where not iskindof node Editable_Mesh do addmodifier node (Turn_To_Mesh())


after export you can delete the modifier.

TechnicallyArtistic
07-19-2011, 09:04 PM
It doesn't like that either.
I need to get the skin data with that, and to do that, I believe it has to be collapsed under the skin modifier from what I've seen to get it to export without the error message.

I think it's adding the editable mesh under the skin modifier and collapsing it still.

denisT
07-19-2011, 09:30 PM
It doesn't like that either.
I need to get the skin data with that, and to do that, I believe it has to be collapsed under the skin modifier from what I've seen to get it to export without the error message.

I think it's adding the editable mesh under the skin modifier and collapsing it still.

i hate stupid tools (this exporter for example) and i will help you to fight...
here is a to_mesh converter:

mapped fn _turntomesh node =
(
out = off
for k=1 to node.modifiers.count while not out where (out = iskindof node.modifiers[k] Skin) do
(
addmodifier node (Turn_To_Mesh()) before:k
maxOps.CollapseNodeTo node (k+1) off
)
if not out and not iskindof node Editable_Mesh and canconvertto node Editable_Mesh do converttomesh node
node
)
_turntomesh Geometry


modify the code if you need to turn to mesh selectively.

TechnicallyArtistic
07-19-2011, 09:39 PM
Ok, I figured it out. I'm just bad still at telling what's what in this program.

The code is in there. It's just spitting out a bunch of other extra stuff.

modPanel.setCurrentObject $.baseObject
modPanel.addModToSelection (Edit_Mesh ()) ui:on
maxOps.CollapseNodeTo $ 2 off

TechnicallyArtistic
07-20-2011, 06:19 PM
So your code works better than mine in that it works with any panel open and mine only works with the Modifier panel open.

But when I put it into the script and replace it with mine, it seems to get stuck in a loop sometimes, but not all the time and I don't know why. When it does it seems to maybe loop in that part of the script like 10-20 times (I'm guessing this part because it doesn't do it with the code I used.) before it gets to the save window. It'll still work but it keeps it from being faster than doing it manually.

Any idea why it goes into the loop or how to maybe stop it but allow it to run to the next part where it actually saves the file out? Here's the code right now in that part with your bit in there.

function md5export = (
cursel = GetCurrentSelection()
mesh = cursel[1]
if mesh == undefined do
(
messagebox "no object selected"
return undefined
)
if (((classof mesh.baseobject) as string) != "Editable_mesh") do
(
mapped fn _turntomesh node =
(
out = off
for k=1 to node.modifiers.count while not out where
(out = iskindof node.modifiers[k] Skin) do
(
addmodifier node (Turn_To_Mesh()) before:k
maxOps.CollapseNodeTo node (k+1) off
)
if not out and not iskindof node Editable_Mesh and
canconvertto node Editable_Mesh do converttomesh node
node
)
_turntomesh Geometry



)
if g_export_anim_only then
(
TempFilenameOnly = getFilenameFile (maxFilePath + maxFileName)
trimmedStr = trimright TempFilenameOnly "vV1234567890"
trimmedStr = trimright trimmedStr "_"
animfilename = getsavefilename filename:trimmedStr caption:"Save MD5anim" types:"MD5anim (*.md5anim)|*.md5anim"
if animfilename != undefined do
(
animfile = createfile animfilename
if (animfile != undefined) do
(
md5 = md5exportobj mesh
-- format "%" (md5[1] as string) to:outfile
format "%" (md5[2] as string) to:animfile
-- format "%\n" (md5[1] as string)
-- format "%\n" (md5[2] as string)
-- close outfile
close animfile
)
)

)
else
(
TempFilenameOnly = getFilenameFile (maxFilePath + maxFileName)
trimmedStr = trimright TempFilenameOnly "vV1234567890"
trimmedStr = trimright trimmedStr "_"
outfilename = getsavefilename filename:trimmedStr caption:"Save MD5" types:"MD5mesh (*.md5mesh)|*.md5mesh"
if outfilename != undefined do
(
outfile=createfile outfilename
animfilename = copy outfilename
endindx = findstring animfilename ".md5mesh"
animfilename = replace animfilename endindx 8 ".md5anim"
animfilename = getsavefilename caption:"Save MD5anim" filename:animfilename types:"MD5anim (*.md5anim)|*.md5anim"
if animfilename != undefined then animfile = createfile animfilename
if (outfile!= undefined and animfile != undefined) do
(
md5 = md5exportobj mesh
format "%" (md5[1] as string) to:outfile
format "%" (md5[2] as string) to:animfile
-- format "%\n" (md5[1] as string)
-- format "%\n" (md5[2] as string)
close outfile
close animfile
)
)
)
)




And just for the hell of it, here's the part I figured out, where I've got to have to Modify panel open or it converts the skin modifier to editable mesh rather than the editable poly modifier.

function md5export = (
cursel = GetCurrentSelection()
mesh = cursel[1]
if mesh == undefined do
(
messagebox "no object selected"
return undefined
)
if (((classof mesh.baseobject) as string) != "Editable_mesh") do
(
modPanel.setCurrentObject $.baseObject
modPanel.addModToSelection (Edit_Mesh ()) ui:on
maxOps.CollapseNodeTo $ 2 off


)
if g_export_anim_only then
(
TempFilenameOnly = getFilenameFile (maxFilePath + maxFileName)
trimmedStr = trimright TempFilenameOnly "vV1234567890"
trimmedStr = trimright trimmedStr "_"
animfilename = getsavefilename filename:trimmedStr caption:"Save MD5anim" types:"MD5anim (*.md5anim)|

*.md5anim"
if animfilename != undefined do
(
animfile = createfile animfilename
if (animfile != undefined) do
(
md5 = md5exportobj mesh
-- format "%" (md5[1] as string) to:outfile
format "%" (md5[2] as string) to:animfile
-- format "%\n" (md5[1] as string)
-- format "%\n" (md5[2] as string)
-- close outfile
close animfile
)
)

)
else
(
TempFilenameOnly = getFilenameFile (maxFilePath + maxFileName)
trimmedStr = trimright TempFilenameOnly "vV1234567890"
trimmedStr = trimright trimmedStr "_"
outfilename = getsavefilename filename:trimmedStr caption:"Save MD5" types:"MD5mesh (*.md5mesh)|*.md5mesh"
if outfilename != undefined do
(
outfile=createfile outfilename
animfilename = copy outfilename
endindx = findstring animfilename ".md5mesh"
animfilename = replace animfilename endindx 8 ".md5anim"
animfilename = getsavefilename caption:"Save MD5anim" filename:animfilename types:"MD5anim

(*.md5anim)|*.md5anim"
if animfilename != undefined then animfile = createfile animfilename
if (outfile!= undefined and animfile != undefined) do
(
md5 = md5exportobj mesh
format "%" (md5[1] as string) to:outfile
format "%" (md5[2] as string) to:animfile
-- format "%\n" (md5[1] as string)
-- format "%\n" (md5[2] as string)
close outfile
close animfile
)
)
)
)

denisT
07-21-2011, 01:05 AM
my code works fine. there is nothing wrong with it. the problem is - you don't know how to use it.
i never post the final solutions, i give a direction. you have to solve the problem yourself.
go to the mxs help... check what Geometry is. catch how a mapped function works.

TechnicallyArtistic
07-21-2011, 01:55 AM
Ok, so anybody else who works on deadlines have any insight? I'd love to look through all that stuff and really dig deep into Max script right now, but at the moment my goal is to get all those files exported as quickly as possible so I can really asses what we have in the next week or so that came from this Shanghai drop and I've spent two days modifying this script now trying to wrap my head around everything in it. I'm looking through the some 300 pages the help doc brings up right now when searching for either of those terms, but I have no idea what it is I'm looking for right now and why that part is looping.

My script right now can get me working quickly enough, but only works with the modifier panel open, which if it came down to it is what I'll use because its getting the work done tons faster. I'd love to get it idiot proof though so it didn't mater which window you had up, in case somebody else has to use thing thing after me, but I can't budget a timeline to figure out what all these terms mean. I'm trying to learn just enough to get it working right now so I can get done.

Love the teach the man to fish concept, but not on a week timeline, so has anybody got something slightly more specific to look into rather than general help files? Because right now I don't know what that code bit does or understand the structure of it enough to know what I'm looking for because before the other week, I've never done Max Script. Or if you could put it in Mel script terms, I might get it then, but I'm no programer when it comes to scripting for sure in any program.

denisT
07-21-2011, 02:47 AM
that's interesting. i'm great in MEL. how can it help in your case?

SnipeyX
07-21-2011, 03:04 AM
Go to the maxscript help and go to the index tab. He's referencing "geometry - objectset" and "mapped function definition". I use index 98% of the time instead of search, gets me close to what I need faster without the 300 pages of results, of course in this case, "geometry" was a particularly oft-used term. :)

The geometry keyword is all nodes in the scene that are geometry class. By putting his function into the script that iterates across everything in the scene, you're getting weird results, going over everything as many times as you have objects.

Just run his script separate, prior to export. That will autoconvert everything to editmesh for you, then you should be able to run your regular export script. Should get you pretty close, if not the whole way there I think.

TechnicallyArtistic
07-21-2011, 05:06 AM
Ah. Thanks. That makes more sense. That makes the help file a little more useful though it still seems hard to find specific things, though that's probably more because I don't know what they're called. I'm still not sure what I'm supposed to be seeing out of either of those help options that would help me solve it though. I can't even tell how either of those things are being used in that bit.

Ok, so knowing that it does every object, that isn't what I need anyway. Just the selected object.
But, I think I got what I need now because I can actually find stuff in this thing now. I just figured out how to script it to switch over to the modify panel, so it should do what it needs to now.

Thanks for the tip.

SnipeyX
07-21-2011, 05:36 AM
It sounds like you're beyond wanting to use denisT's code, but since I'm just sitting here watching a progressbar for a bit, I'll try to walk through it some and elaborate what I can. This is also helpful for me to try and understand, as I'm not at expert level with this stuff either.

denisT's code is two overall pieces. 1) A function definition and 2)a single line that calls that function.

He referenced it as a mapped function, which the help file page explains in detail what it does. We know it's a mapped function because the definition syntax fn functionNameHere = () begins with the keyword mapped in his code. So that means we can supply it an array of objects, and it will automatically iterate over that array. Looking at that syntax, the function's name is "_turntomesh" and it uses a parameter which he called "node". Again, since this is a mapped function, that parameter becomes a variable which the function's inner code will use to reference the current element from the array that is passed to it.

The "geometry" keyword is an object set, as mentioned in the help, as is just an array of every geometry object in the scene. In this case that is the array that is passed to our mapped function. If you don't want everything, just change that line so it says _turntomesh selection as array, or make your own array of whatever and call the function with _turntomesh myArray.

The short version of what his function actually does, is puts a turn to mesh modifier underneath the skin modifier and then does a 'collapseTo' to that modifier. that's the for loop part. The if statement after that says if there isn't a skin modifier and it's not already an edit mesh, and it is an object type that can be converted to an edit mesh, then convert it.

Hope that helps.

CGTalk Moderation
07-21-2011, 05:36 AM
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.