In this Blender 2.5 video tutorial we’ll be writing a script that creates a custom menu to which we can add operators, enums and sub-menus, as well as taking a look at registering a hotkey for it through Python.

You must be logged in to upload images. Register

Discussion

29 Responses to “Scripting a Custom Tool Menu”
  1. Posts: 256

    This was up on the citzen site as early as Thursday so I’ve already had a chance to watch it. It inspired me to much around in the python console and explore the api a little hands on. I found out the other day that you can use python with Gimp as well so I have even more reason to get more proficient with it. Thanks again for taking the time to make these!

    #
    1
    Jul 25, 2011 at 7:41 am
    • Posts: 59

      As early as thursday?! :( lol

      Great to see the continuation of more Python scripting tutorials.

      I’m now an official Patrick Boelens fan! lol
      :D

      #
      1.1
      Jul 25, 2011 at 7:59 am
      • Posts: 256

        My mistake. It was Friday. I know I watched it before the weekend. Here is my proof.

        http://www.picpaste.com/Screenshot-39dl0CsQ.png

        The second part to the sci fi panel is on there as well. I have no reason to lie. Guess it pays to be a citzen.

        #
        1.1.1
        Jul 25, 2011 at 10:34 am
      • Posts: 91

        second part is out!!!!!! i want it now!!!! lol

        #
        1.1.2
        Jul 25, 2011 at 5:55 pm
  2. Posts: 71

    Awesome Patrick. These are great.

    #
    2
    Jul 25, 2011 at 9:50 am
  3. Johnathan Hauck
    Posts: 11

    I think I might put this to use to put the special, and 3 context menus into one.
    Seems like they should all be under one key lol.

    #
    3
    Jul 25, 2011 at 11:10 am
  4. B M
    Posts: 15

    I’m getting the menu header, but not the menu. It displays just “Custom Menu” and nothing else.

    #
    4
    Jul 25, 2011 at 1:05 pm
    • Posts: 225

      Hey BM,

      If you’re not seeing anything, but not getting any errors either you probably made a small typo somewhere. If you’re still stuck please feel free to upload your script to pastebin.com or pasteall.org and post the link here so I can take a look at it.

      #
      4.1
      Jul 25, 2011 at 1:21 pm
  5. Svcam04
    Posts: 21

    Patrick. Any recommendations for good beginning python books?

    #
    5
    Jul 25, 2011 at 5:01 pm
  6. Posts: 9

    Hey, just a random question:
    why do you guys use Vimeo and not youtube?
    just asking ^^

    #
    6
    Jul 26, 2011 at 12:07 am
    • Posts: 2949

      Vimeo tends to have much better video quality and allows us to designate which domains the video can be embedded on.

      -Jonathan

      #
      6.1
      Jul 26, 2011 at 8:27 am
  7. Campbell Barton (ideasman42)
    Posts: 1

    Nice tutorial,

    Now menu ID’s are displayed as python tooltips, committed revision 38723.

    Also added 2 menu templates.

    #
    7
    Jul 26, 2011 at 4:22 am
  8. Zecc
    Posts: 1

    Rather than write:

    km.keymap_items.new('wm.call_menu', 'O', 'PRESS', False, True, False, True)

    You can write:

    km.keymap_items.new('wm.call_menu', 'O', 'PRESS', shift=True, alt=True)

    Python allows you to specify only the arguments which values you want to change, and leave out the ones you want to leave with their default values. It’s clearer that way.

    #
    8
    Jul 26, 2011 at 6:03 am
  9. Couldn’t you save the script as a .py file and install it as an addon to Blender?

    #
    9
    Jul 26, 2011 at 6:07 am
    • Posts: 256

      In one of the other python tutorials on here he shows how to register your script as an add on. I forget which one he does it in though.

      #
      9.1
      Jul 26, 2011 at 7:01 am
  10. Posts: 8

    Thanks for another helpful scripting tutorial. ^^

    #
    10
    Jul 26, 2011 at 8:44 pm
  11. Posts: 71

    Hey Patrick. Really liking the Python tuts. Here’s an idea for one, since you were looking, modifying a node or created your own node. Maybe that’s going to deep eh?

    #
    11
    Jul 27, 2011 at 10:47 am
  12. eppo
    Posts: 1

    Hello!
    Thanks for nice coding tutorials!
    Out of curiosity – after checking object mesh data export/import one, realised that there should be mirriads of floating point math operations going on under the hood of Blender (surprise…) – does python there make use of cdecimal lib (http://www.bytereef.org/mpdecimal/index.html)?
    Couldn’t find answer to this and no – i’m not anyhow related… They talk 12 times speedup tho.

    #
    12
    Jul 29, 2011 at 11:55 am
    • Posts: 225

      Hey Eppo,

      Nice find! But no, this seems to be an optional module, as the site says “cdecimal is a fast drop-in replacement for the decimal module in Python’s standard library”. =)

      #
      12.1
      Jul 30, 2011 at 7:30 am
  13. Gary Parkin
    Posts: 109

    Patrick, is there any way to have the scrip wait until a “go” button is pressed before running the script?
    My script seems to run every time I change a value in my too parameters.

    Thanks

    #
    13
    Aug 10, 2011 at 2:27 pm
    • Gary Parkin
      Posts: 109

      That should have been TOOL parameters. Every time I change a setting that updates the classes parameter, the class runs.

      #
      13.1
      Aug 10, 2011 at 2:28 pm
  14. Gary Parkin
    Posts: 109

    Someone pointed me to this e-book too. It contains the steps to create an addon that can be attached to any menu.
    And how to find all of the menu object names.
    http://airplanes3d.net/pydev-000_e.xml

    #
    14
    Sep 13, 2011 at 1:08 pm
  15. skeptika
    Posts: 1

    Can’t get this script to do anything, double checked for typos. Is there somewhere to download this script or cut ‘n paste it? It doesn’t error, it just does nothing.

    #
    15
    Nov 24, 2011 at 4:22 pm
  16. Posts: 49

    Hey David

    Thank You For Tutorial… And i have one problem by “Run Script”.I don’t know this error.Can You Help Me?

    http://d1202.hizliresim.com/u/3/2d5sk.png (Error)

    #
    16
    Feb 3, 2012 at 10:05 am

Leave a Comment

You must be logged in to post a comment.