2

I'm looking for the simplest way to add a button and a text input field to Blender's UI so I can use some parameters in my Python script.

I've tried a few tutorials but...

This one uses the word self which throws me an error (name 'self' is not defined) http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface#Using_scene_properties_to_store_information

In this one I cannot really see where the actual code to add to UI is http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Operator.html

Plus a few others that I don't understand at all.

Val
  • 395
  • 1
  • 6
  • 14
  • Do you want to run your script right from the text editor with parameters from a panel or just the last operator settings? – stacker Jul 25 '14 at 14:42
  • what do you mean by 'last operator settings'? i guess, running from text editor is OK for me. i might think about improving it later on – Val Jul 25 '14 at 14:51
  • Last operator is the panel that is displayed in the 3D Tools panel after you invoked an operator e.g. Add/Mesh/Torus there you can setup the parameters for the last created object. If you need something like that see the example twisted.py http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface It still works with Blender 2.7 – stacker Jul 25 '14 at 16:28

2 Answers2

5

You basically need to combine two of the Templates in Text Editor that ship with Blender:

An Operator and a panel. In the panel's draw() method, you add an operator to the layout, which will be represented by a clickable button. Clicking it will run the operator's execute() method.

Here is an example how interface and actions play together:

http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Panels_and_Operators/Ping_Pong

CodeManX
  • 29,298
  • 3
  • 89
  • 128
  • the ping-pong example helped me. thx! – Val Jul 29 '14 at 11:54
  • how to use the Ping_Pong example ? Should I run it in script editor (I tried, I don't see any result) or try to install it as addon (It seems it does not install) ? ... maybe I just cannot find where it should appear ? – Prokop Hapala Oct 06 '16 at 08:40
  • 1
    aha I found it ... it is in Properties panel on Object tab ... as described here bl_space_type = "PROPERTIES" and bl_context = "object" after running it from script editor – Prokop Hapala Oct 06 '16 at 08:44
1

I'm not quite sure how to have a string/integer inputbox, but this hopefully should help you with some of your creations:

http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Addon_Custom_Property

Good luck my friend.

F1e4u8
  • 63
  • 6