Bake all MASH instancers script

771 views
Skip to first unread message

Steve Davy

unread,
Apr 18, 2018, 8:50:48 PM4/18/18
to Maya Group

Trying to create a simple utility to bake all MASH instancers in a scene at once. However, the MASHBakeStillMEL bake process ends with the newly created group of baked instances being selected, meaning the original array is dropped. This is what I have so far, which works but only on the first instancer and then errors out with  "Select an instancer node".

Can anyone point me in the right direction? I guess it's necessary to store the original array and reselect the contents in order, running the loop each time. But I have no idea how to do that.

{
proc bakeAllInstancers()
{
$instancers = `ls -type "instancer"`;
select -r $instancers;

for($instancer in $instancers) 
{
MASHBakeStillMEL;
}
}
bakeAllInstancers();
}

Cosku Ozdemir

unread,
Apr 18, 2018, 8:55:47 PM4/18/18
to maya...@googlegroups.com
Almost there!
You're already storing the array with the first command, so you need to select them individually in the loop:

proc bakeAllInstancers()
{
$instancers = `ls -type "instancer"`;

for($instancer in $instancers) 
{
select -r $instancer;
MASHBakeStillMEL;
}
}
bakeAllInstancers();
}




--
You received this message because you are subscribed to the Google Groups "maya_he3d" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maya_he3d+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony Enos

unread,
Apr 19, 2018, 2:02:31 AM4/19/18
to maya...@googlegroups.com
I think you may have a syntax error. I don't think variable "$instancer" isn't going to be recognized unless you've declared it somewhere. You have "for($instancer in $instancers) ". Usually, that is written as "(for $node in $instancers)". In any case, it looks like it needs to iterate through the array like I have it below instead. It wasn't working as a "for-in" loop. I tend to declare my arrays as I have it below, though it may not matter. I added a print command so you can see what's getting baked; works for me with multiple instancers from what i can tell:
proc bakeAllInstancers()


{
    {
    
    string $instancers[] = `ls -type "instancer"`;
    select $instancers;
    for( $i=0; $i<size($instancers); ++$i )
        {
        select $instancers[$i];
        print ("baking " + $instancers[$i] + " " + "\n");
        MASHBakeStillMEL;
        }
    }
}

bakeAllInstancers();


On Wed, Apr 18, 2018 at 5:50 PM, Steve Davy <stevi...@hotmail.com> wrote:

Anthony Enos

unread,
Apr 19, 2018, 2:15:19 AM4/19/18
to maya...@googlegroups.com
Sorry there was a parenthesis typo in my explanation, and a couple of pointless gaps in the code ... meant to say usually it's written as "for($node in $instancers)" rather than  "for($instancer in $instancers) ". Again, working  version below:


proc bakeAllInstancers()
{
    {
    string $instancers[] = `ls -type "instancer"`;
    select $instancers;
    for( $i=0; $i<size($instancers); ++$i )
        {
        select $instancers[$i];
        print ("baking " + $instancers[$i] + " " + "\n");
        MASHBakeStillMEL;
        }
    }
}
bakeAllInstancers();


Steve Davy

unread,
Apr 19, 2018, 1:46:22 PM4/19/18
to maya...@googlegroups.com

Well, thanks both for the replies but I can't even get it to run once now with either suggestion, getting this error:


# Error: RuntimeError: file <maya console> line 1: Error occurred during execution of MEL script
file: C:/Program Files/Autodesk/Maya2018/plug-ins/MASH/scripts/MASHCreateUI.mel line 386: RuntimeError: file C:\Program Files\Autodesk\Maya2018\plug-ins\MASH\scripts\MASHbakeInstancer.py line 25: Object 'bakeCbTranslate' not found.

This is weird as my script was at least running successfully once yesterday, but stopping after the first bake.

So far as my variable $instancer not being declared, I've always understood that with a for-in loop this is simply interpreted as container for each object in the array (in this case $instancers), so it doesn't matter what it's called. Are you saying that's not the case? Pretty sure I've written little loops this way before and it's worked fine.




From: maya...@googlegroups.com <maya...@googlegroups.com> on behalf of Anthony Enos <antho...@gmail.com>
Sent: Wednesday, April 18, 2018 11:15 PM
To: maya...@googlegroups.com
Subject: Re: [maya_he3d] Bake all MASH instancers script
 
To unsubscribe from this group and stop receiving emails from it, send an email to maya_he3d+...@googlegroups.com.

Jason Brummett

unread,
Apr 19, 2018, 3:51:30 PM4/19/18
to maya...@googlegroups.com
Hey Steve, about the second part.  I too understand that within a closed loop that that variable is simply a 'foo' placeholder to hold a temporary value and doesn't matter.  I'd like to know if I'm wrong about that as well.

Anthony Enos

unread,
Apr 19, 2018, 4:12:34 PM4/19/18
to maya...@googlegroups.com
My bad as far as the $node thing. I'm wrong. Looks like you can use whatever you want. I think I just originally started creating "for-in" loops based on some specific examples, and assumed that was the way it had to be. As far as the script itself, I think the issue has something to do with the "clear memory" function being turned on by default... this is a dumb workaround for now, but select one instance, and click on the "bake instancer to objects". Then uncheck "clear memory", and just run the script. There must be a flag for clearing the memory without having to launch the window. Sorry again about the misinformation as far as the 'foo' placeholder.

bobrobertuma

unread,
Apr 19, 2018, 6:11:04 PM4/19/18
to maya...@googlegroups.com




Sent from my Virgin Mobile PhoZzzzune.

Ian Waters

unread,
Apr 20, 2018, 3:01:45 AM4/20/18
to maya...@googlegroups.com
The baking script, is *cough* not able to work without the UI. 

You’d need to load up the UI, then you can run your script.

Steve Davy

unread,
Apr 20, 2018, 1:42:47 PM4/20/18
to maya...@googlegroups.com

I had wondered about that, but didn't test it. Thanks Ian, works now:


{
proc bakeAllInstancers()
{
$instancers = `ls -type "instancer"`;

for($instancer in $instancers) 
{
select -r $instancer;
MASHBakeGUI;
MASHBakeStillMEL;
}
}
bakeAllInstancers();
}




From: maya...@googlegroups.com <maya...@googlegroups.com> on behalf of Ian Waters <water...@gmail.com>
Sent: Friday, April 20, 2018 12:01 AM
Reply all
Reply to author
Forward
0 new messages