一半君的总结纸

听话只听一半君

#49 How do I run a MEL script as a background process?

Well, you can’t, really. As long as Maya is executing MEL commands it disallows user input.

Now, there are some sneaky ways around this. At H2O we’ve implemented a ProgressBar plug-in (just a simple “n% done” window with the typical growing bar) that can be used to track the workings of a time-consuming script. Because the plug-in implements the window in its own thread, a side-effect is that it is possible to manipulate Maya’s UI while the MEL script is twiddling the progress bar. This is risky, tho’, as if we select or delete something that the script is working on it could cause the script to come screeching to an unceremonious halt.

I suppose if you tried hard you could make a script function that executed in spits and spurts by controlling it via scriptJobs and the like:

// Set up a scriptJob to continue the script task whenever Maya is idle
int $backgroundJob = `scriptJob -idleEvent "continueMyScript()"`;

global proc continueMyScript()
{
  global string $whereWasI;

  eval $whereWasI;
}

global proc spitsAndSpurts( int $step )
{
  global string $whereWasI;

  switch ( $step )
  {
    case 1:
      // Do step 1 here
      $whereWasI = "spitsAndSpurts 2";
      break;

    case 2:
      // Do step 2 here
      $whereWasI = "spitsAndSpurts 3";
      break;

    // and so on...

    default:
      // Done!
      print( "spitsAndSpurts is DONE!\n" );
      $whereWasI = "";
      scriptJob -kill $backgroundJob;
  }
}

Again, a caution that if the MEL script is working on something within the scene, you can’t (well, shouldn’t) change anything until it’s done what it needs to do with it.

Tuesday, December 05, 2000

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: