djPFXUVs for maya now has a UI and does grass

david | python,rendering | Saturday, July 28th, 2012

A while back I posted a script called djPFXUVs that could be used to quickly re-layout uv's for paintFX leafs to help with the task of building and assigning more interesting textures. Today I thought I'd share an updated version of that script, which as you can see here, even has a UI.


Support for multiple uv sets

A new feature is the option to choose a source and optional target UV set, where the target can be either the source, any other existing set or a new one. This means textures for various material attributes do not need to be sharing the same uv's. You could use one uv set for diffuse color and another for reflectivity, and thus create even more variations amongst leave textures.

New Grass Layout Mode

UI showing grass mode

Grass Layout Mode does not create a tiled layout like the leaf modes. Instead each shell (ie each blade of grass) is scaled to the specified blade width and then randomly positioned along the U-axis in the primary uv quadrant. Here is an example showing before...


The nice thing about the way the original paintFX uvs are layed out is the way the tallest blades use the full V-axis while shorter blades use relatively less. djPFXUVs maintains this height relationship, so after grass layout with blade width = 0.5 we get something like this...


In the above image I just selected a few shells to give a clearer picture of what is happening. With thousands of blades of grass distributed randomly, all you'd see would just be a mass of lines.

Here is a snapshot of the hypershade showing a simple example of how you could take advantage of this new uv layout.

hypershade snapshot


colorMain is a rampTexture set to "U Ramp". Because blade of grassĀ  is randomly distributed somewhere in the U-axis, each blade will be textured with a narrow strip of this ramp and the gradation seen in this snapshot will be barely noticeable on a single blade. This ramp therefore can be thought of as a kind of probability distribution. The narrow brown strip to the right of the ramp means approximately 10% of the grass blades will get that brown color, the rest will be various shades of green.

colorBase is a rampTexture set to "V Ramp". I am using this to create a variation along the length of the grass. My grass will be browner near the base.

colorBaseMask is a rampTexture with some noise added.

I combine colorBase over colorMain using colorBaseMask in a layeredTexture (colorLayers) and the result is used as the color in a phong material. This is just a simple example. Nothing fancy. If you wanted photoreal grass you would need to make a bit more effort, but I think this example helps illustrate the idea behind grass layout mode.

Here is a quick render


You can find djPFXUVs on my downloads page. This is a python script. To use it you'll need to put somewhere in you scripts path, then run the following:

import djPFXUVs


  1. Amazing script! Thank you for doing this!

    Comment by Schmidt — October 9, 2012 @ 8:39 pm

  2. Hello, I came upon your fantastic script a little while ago, and it has been an absolute lifesaver so far! Unfortunately I recently ran into an issue that I so far have been unable to troubleshoot, and I was hoping that you might have a solution. As it stands, whenever the frame number changes in my scene, the UV's on my trees revert back to their original state before running the script. I would greatly appreciate any insight you might have regarding this problem. Thank you again for your otherwise amazingly helpful tool.

    Comment by BubbaRay — October 17, 2012 @ 7:51 am

  3. I've been asked this same questions a few times, and since I do have a workable solution I wrote it up in a blog post here...

    I'm glad you are getting some use from the script, by the way, and thanks for your kind words.


    Comment by david — October 17, 2012 @ 11:29 pm

  4. Thank you for doing this!

    Comment by antonyyen — December 20, 2012 @ 6:40 pm

  5. Hi David,

    Can you please tell where exactly we need to copy the script. I have tried but failed to run the script.
    I am copying the script at following place in my local drive

    C:\Program Files\Autodesk\Maya2013\scripts\others

    Let me know where I am wrong.


    Comment by truerswalia — October 4, 2013 @ 7:29 pm

  6. You probably need to set up your python sys.path to point to that folder. Better still, use a different folder. I always advise people not to use the maya install folders. You should use one of your local scripts folders, which on windows would be something like

    If you do want to use a folder that maya does not see by default you can easily add it to the system path with the following lines of python...

    import sys
    if p not in sys.path: sys.path.append(p)

    Comment by david — October 4, 2013 @ 10:00 pm

  7. Hi David,

    I have been using your script so often with Onyx trees. There are some trees which have leaves with a few different poly counts and UV layouts. The version of the script I have been using sometimes tears or stretches the UVs when placing them in the 3x3 grid. Is there a way to execute this script on these leaves to prevent the tearing.

    Thanks for all the support you have been providing!

    Comment by jferrucci10 — October 26, 2013 @ 3:19 pm

  8. I think that my script is making the assumption that the uv's start off inside one tile. Could it be that the onyx leaves are covering more than 1 tile? Thats the only thing I can think of that would explain the stretching. If you can send me a simple scene that demonstrates the problem I can probably figure out a workaround.

    Comment by david — October 27, 2013 @ 3:43 pm

  9. Very easy to use

    Comment by zss — December 23, 2013 @ 9:11 pm

  10. nice````

    Comment by yubaqi — November 5, 2014 @ 12:05 am

  11. Anyone willing to break it down to a newbie how to install this thing? I have just begun learning Maya and this was referenced in a tutorial that I purchased and cannot figure this out. I am using mac os.

    I have been entering the information explained above via the scripts editor. I have managed to seemingly get the script to load in the editor, and when I hit execute it spits out a long list of information indicating it is loaded. My trouble is figuring out what to do from there... once it was executed, I went ahead and tried to create a new shelf item. Whatever I create it flipped up to the shelf but when I click it nothing happens and it doesnt look like the shelf item in the tutorial I am working on. I cannot get the UI so that I can continue and use this script. I have placed a copy of the script in the /Library/Preferences/Maya...Scripts area, restarted maya, and made an invalid icon on my shelf that does nothing. Please help! Whenever I enter what the author mentioned to "run" at the end of this section, it just gives me an error (still trying to run it from the script editor panel...) Please help me! Thanks in advance.

    Comment by ididit86 — February 14, 2015 @ 11:01 pm

  12. With problems like this you need to provide a bit more info to get the help you need. First I need to know the steps you took to install and run the script. (Remember I do not have the tutorial). Second I need to see the error message that maya spits out in the script editor. Without that info I am just guessing.

    However, forget the shelf for a moment (you dont need it). To run the script all you need to do is the following...

    Put somewhere in you scripts path, then run the following in a python tab in the script editor:

    import djPFXUVs

    Its case-sensitive so make sure you get that right too.
    If you dont know where the scripts path is... then ask another mac user - because I dont know either, but google tells me /Users/Shared/Autodesk/Maya/(Version)/scripts where you replace (Version) with an appropriate version folder name.

    good luck

    Comment by david — February 15, 2015 @ 12:41 am

  13. Hi there,

    Been using the script for a while and it NEVER saves the UV's properly.

    If I create a tree/grass, set up my textures and run the script it will create the 3x3 UV layout perfectly fine.

    But if I close and re-open the file then all the UV's are set back to their Maya default and it is an absolute nightmare> I'm not going to waste my time re-running the script on every piece of foliage.

    Any ideas?

    Comment by sandford — March 26, 2015 @ 7:33 am

  14. Sounds to me like you kept the paintFX history. If so, changing frames or reopening the scene will recreate the UV's. Try deleting history before running the script.
    If that fixes your problem, but you also want to keep history, then you will need to use the attribute transfer workaround. Let me know. I can dig up an older comment where I explain this in full.


    Comment by david — March 26, 2015 @ 8:40 am

  15. Yeah the history is causing issues, never had this problem before but since I want to keep the animation enabled on my trees, could you have a search for that workaround?

    It would be much appreciated!

    PS: I had to register for your site via proxy server because the Sabre system was banning my IP instantly :/

    Comment by sandford — March 29, 2015 @ 3:52 am

  16. Here you go...

    The Sabre thing is probably beyond my control. I need it because my site got hacked so many times. Sorry for the incovenience. I guess it doesnt matter now that you found a workaround (ie proxy).

    Comment by david — March 29, 2015 @ 11:03 am

  17. Thanks for the workaround.

    Unfortunately saving out a file with trees like that murdered the file and Maya crashes and gets stuck loading the file on 98%.

    God, Maya sucks. File is only 330mb aswell. >_>

    Comment by sandford — March 30, 2015 @ 5:38 am

  18. Another approach is to simply break this complex task into 2 parts. In many (probably most) studios, this would be the standard workflow. Export a geo cache from the animation scene and apply the cache to matching geo in the render scene - except in the render scene, the history has been deleted and the uv's have been layed out before you import the cache.

    Comment by david — March 30, 2015 @ 10:38 pm

  19. hi there, i am newbie here. I was trying to run the script with Maya 2015 OSX, I have no idea where to start, any help would be great

    Comment by animamundi — May 31, 2015 @ 1:29 am

  20. I've never used OSX so some of my reply is guesswork.
    There is nothing too fancy about this python script so you cand just drop it in your scripts folder and restart maya, then run the commands I suggest in a python tab in the maya script editor. But since this was pretty much what the last sentence of my post suggested, I'm guessing you dont know what your scripts path is, or much about python. I'm going to email you some suggestions. Feel free to get back to me with some more questions via email.

    Comment by david — May 31, 2015 @ 10:42 pm

  21. hi
    Maya 2016 can not be installed on
    Please help me

    Comment by Vfx — July 26, 2015 @ 1:14 am

  22. It does work in 2016.
    If you are having problems, post the error message here and I will try to help you.

    Comment by david — July 26, 2015 @ 3:49 am

  23. error : # Error: Invalid Code Fragment: Found no executable Python code.

    If you install this script for Maya 2016 and Windows 8.1 let

    Comment by Vfx — July 27, 2015 @ 5:31 am

  24. A couple of questions, so I can figure out where help is needed....

    This script should be in your MAYA_SCRIPT_PATH or PYTHONPATH or sys.path
    Which folder did you put the .py file into?
    What code did you use to run it?
    Have you installed other python scripts that work?

    Comment by david — July 27, 2015 @ 9:36 am

  25. You've run it run Windows 8.1 in Maya 2016 ?

    You tell me how to install the

    Help me please

    Comment by Vfx — July 28, 2015 @ 2:34 am

  26. It's a warning

    # Error: Invalid Code Fragment: Found no executable Python code.

    help me

    tanx david

    Comment by Vfx — July 28, 2015 @ 7:49 am

  27. help me david

    It's a warning

    # Error: Invalid Code Fragment: Found no executable Python code.

    Comment by Vfx — August 4, 2015 @ 9:37 pm

  28. I would really like to help, but the error does not give me much to go on, unless you tell me what you did to get the error. Installing simple python scripts like this one should be easy if you know a bit of python, and only a little bit difficult if you are new to python.

    Try entering the following 2 lines of python code in a python tab of the script editor and tell me what it says...

    import sys
    print sys.path

    Comment by david — August 4, 2015 @ 10:28 pm

  29. hello david, I need some help.

    I tried to run your script and keep getting this error

    # Error: KeyError: file C:/Users/Andi/Documents/maya/2015-x64/scripts\ line 392: 1 #

    any tips ?

    Comment by draganneo — December 28, 2015 @ 4:01 pm

  30. I tried, but I am unable to reproduce this error. Can you send me the mesh where this is happening? Have you tried the script with different meshes? Try with a primitive cube with no history for example.


    Comment by david — December 28, 2015 @ 4:48 pm

  31. Hi david, my friend found the awesome script in your web. I really want to use it in my subject. But I'm not sure whether it is free or not. And I didn't find your email...Could you tell me what should we to notice? Are all of your script under a same license??????????

    Comment by loretta — May 20, 2016 @ 10:03 am

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress | Based on a theme by Roy Tanck