2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Do you want to run your script right from the text editor with parameters from a panel or just the last operator settings? $\endgroup$
    – stacker
    Commented Jul 25, 2014 at 14:42
  • $\begingroup$ 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 $\endgroup$
    – Val
    Commented Jul 25, 2014 at 14:51
  • $\begingroup$ 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 wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/… It still works with Blender 2.7 $\endgroup$
    – stacker
    Commented Jul 25, 2014 at 16:28

2 Answers 2

5
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ the ping-pong example helped me. thx! $\endgroup$
    – Val
    Commented Jul 29, 2014 at 11:54
  • $\begingroup$ 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 ? $\endgroup$ Commented Oct 6, 2016 at 8:40
  • 1
    $\begingroup$ 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 $\endgroup$ Commented Oct 6, 2016 at 8:44
1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .