Tag: Tutorials

  • Next power of 2..

    I came across this little snippet of code* to find the next power of 2 and found it quite helpful – from what I understand it's also very efficient compared to other methods.

     

    public int NextPowerOfTwo(int inInt)
    {
     inInt--;
     inInt = ( inInt >> 1 ) | inInt;
     inInt = ( inInt >> 2 ) | inInt;
     inInt = ( inInt >> 4 ) | inInt;
     inInt = ( inInt >> 8 ) | inInt;
     inInt = ( inInt >> 16 ) | inInt;
     inInt++; // Val is now the next highest power of 2.
     return inInt;
    }

     

    Link to original article regarding technique and actually a more detailed explanation of the method – Acius' Snippets.

  • Maya Technical Art FAQ

     A collection of commonly asked questions for Maya (mel and python)

  • Useful string expressions (mel)

    Collection of useful string expressions for mel

    (more…)

  • How do I key an attribute that’s constrained?

    This solution only realy applies to ‘constrained’ attributes and not expression or other forms of driven control.

  • Change layer visbility through script

    How to chage the layer visibility (or any other property) through Python script

    (more…)

  • You’ve got Threads in my Mel! (Timer Event Objects in Maya)

    There’s been many times when I wanted to latch a command onto a  timer that runs independently of the main thread – still allowing control and interaction with maya while the timer is ticking.

    The best example of this is an auto scene backup script.  Most, if not all, auto scene backup scripts out there latch onto some arbitrary events in the scriptJob command and execute the backup time check when these are triggered (selection change, tool change etc).

    This typically does the job but can lead to some funny behavior depending on the events you’ve attached the backup to.

     


    How could it be better?

    In any other programming language that supports threads or even attaching timers to UI elements (ala maxScript) this would be very simple and is also simple enough problem inside a maya plugin – spawn a new thread, wait the given time then execute the command.

    However I figured with Python’s implementation into Maya and it’s native ability for threading I should be able to achieve this without having to develop or distribute a compiled plugin.

     

    It turns out it’s very simple.

    (more…)

  • Sourcing a Python script through Mel

    So you want to do something python that’s not supported in Mel but are unsure how exactly to link the two.

    (more…)

  • Nesting multiple command and procedure calls (mel)

    There are really three core ways to call a command or procedure in mel.  Most scripts use a combination of all three however of the two that will allow you to store the result there’s only one which supports nesting (embedded command or procedure calls in the arguments of another command/procedure).

    (more…)