Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2007-02-21 14:17:17 +0300
committerCampbell Barton <ideasman42@gmail.com>2007-02-21 14:17:17 +0300
commitf71458b90483e33923e706e1b6aa6612dd0fd425 (patch)
tree7850f63e7ee8bb4462d7125041434fa35c358a8a
parent6831c0453371f7b90428686e74b485f76620cf9d (diff)
adding menu slot Armature
adding menu slot ScriptTemplate new script scripttemplate_mesh_edit is a template for an editmesh script. The function Text makeCurrent() is a dummy until I can get it working when the script runs from a menu.
-rw-r--r--release/scripts/armature_symmetry.py4
-rw-r--r--release/scripts/scripttemplate_mesh_edit.py93
-rw-r--r--source/blender/python/BPY_menus.c10
-rw-r--r--source/blender/python/BPY_menus.h2
-rw-r--r--source/blender/python/api2_2x/Text.c25
-rw-r--r--source/blender/python/api2_2x/Window.c1
-rw-r--r--source/blender/python/api2_2x/doc/Text.py7
-rw-r--r--source/blender/src/header_text.c36
-rw-r--r--source/blender/src/header_view3d.c40
9 files changed, 213 insertions, 5 deletions
diff --git a/release/scripts/armature_symmetry.py b/release/scripts/armature_symmetry.py
index 1e4484d0efc..b4b3e54516c 100644
--- a/release/scripts/armature_symmetry.py
+++ b/release/scripts/armature_symmetry.py
@@ -3,8 +3,8 @@
"""
Name: 'Armature Symmetry'
Blender: 242
-Group: 'Animation'
-Tooltip: 'Make an Armature symetrical'
+Group: 'Armature'
+Tooltip: 'Make an Armature symmetrical'
"""
__author__ = "Campbell Barton"
diff --git a/release/scripts/scripttemplate_mesh_edit.py b/release/scripts/scripttemplate_mesh_edit.py
new file mode 100644
index 00000000000..ca8077e3865
--- /dev/null
+++ b/release/scripts/scripttemplate_mesh_edit.py
@@ -0,0 +1,93 @@
+#!BPY
+"""
+Name: 'Mesh Editing'
+Blender: 243
+Group: 'ScriptTemplate'
+Tooltip: 'Add a new text for editing a mesh'
+"""
+
+from Blender import Text, Window
+
+script_data = '''
+#!BPY
+"""
+Name: 'My Mesh Script'
+Blender: 243
+Group: 'Mesh'
+Tooltip: 'Put some useful info here'
+"""
+
+# Add a licence here if you wish to re-distribute, we recommend the GPL
+
+from Blender import Scene, Mesh, Window, sys
+import BPyMessages
+
+def my_mesh_util(me):
+ # This function runs out of editmode with a mesh
+ # error cases are alredy checked for
+
+ # Remove these when writing your own tool
+ print me.name
+ print 'vert count', len(me.verts)
+ print 'edge count', len(me.edges)
+ print 'face count', len(me.faces)
+
+ # Examples
+
+ # Move selected verts on the x axis
+ """
+ for v in me.verts:
+ if v.sel:
+ v.co.x += 1.0
+ """
+
+ # Shrink selected faces
+ """
+ for f in me.faces:
+ if f.sel:
+ c = f.cent
+ for v in f:
+ v.co = (c+v.co)/2
+ """
+
+def main():
+
+ # Gets the current scene, there can be many scenes in 1 blend file.
+ sce = Scene.GetCurrent()
+
+ # Get the active object, there can only ever be 1
+ # and the active object is always the editmode object.
+ ob_act = sce.objects.active
+
+ if not ob_act or ob_act.type != 'Mesh':
+ BPyMessages.Error_NoMeshActive()
+ return
+
+
+ # Saves the editmode state and go's out of
+ # editmode if its enabled, we cant make
+ # changes to the mesh data while in editmode.
+ is_editmode = Window.EditMode()
+ if is_editmode: Window.EditMode(1)
+
+ Window.WaitCursor(1)
+ me = ob_act.getData(mesh=1)
+ t = sys.time()
+
+ # Run the mesh editing function
+ my_mesh_util(me)
+
+ # Timing the script is a good way to be aware on any speed hits when scripting
+ print 'My Script finished in %.2f seconds' % (sys.time()-t)
+ Window.WaitCursor(0)
+
+
+# This lets you can import the script without running it
+if __name__ == '__main__':
+ main()
+'''
+
+new_text = Text.New('mesh_template.py')
+new_text.write(script_data)
+new_text.makeCurrent()
+Window.RedrawAll() \ No newline at end of file
diff --git a/source/blender/python/BPY_menus.c b/source/blender/python/BPY_menus.c
index 2a53ba1adf1..9b4a5721d4c 100644
--- a/source/blender/python/BPY_menus.c
+++ b/source/blender/python/BPY_menus.c
@@ -105,6 +105,10 @@ static int bpymenu_group_atoi( char *str )
return PYMENU_VERTEXPAINT;
else if( !strcmp( str, "UVCalculation" ) )
return PYMENU_UVCALCULATION;
+ else if( !strcmp( str, "Armature" ) )
+ return PYMENU_ARMATURE;
+ else if( !strcmp( str, "ScriptTemplate" ) )
+ return PYMENU_SCRIPTTEMPLATE;
/* "Misc" or an inexistent group name: use misc */
else
return PYMENU_MISC;
@@ -173,6 +177,12 @@ char *BPyMenu_group_itoa( short menugroup )
case PYMENU_UVCALCULATION:
return "UVCalculation";
break;
+ case PYMENU_ARMATURE:
+ return "Armature";
+ break;
+ case PYMENU_SCRIPTTEMPLATE:
+ return "ScriptTemplate";
+ break;
case PYMENU_MISC:
return "Misc";
break;
diff --git a/source/blender/python/BPY_menus.h b/source/blender/python/BPY_menus.h
index d66f1acf1fc..dfa16853157 100644
--- a/source/blender/python/BPY_menus.h
+++ b/source/blender/python/BPY_menus.h
@@ -100,6 +100,8 @@ typedef enum {
PYMENU_WEIGHTPAINT,
PYMENU_VERTEXPAINT,
PYMENU_UVCALCULATION,
+ PYMENU_ARMATURE,
+ PYMENU_SCRIPTTEMPLATE,
PYMENU_HELP,/*Main Help menu items - prob best to leave for 'official' ones*/
PYMENU_HELPSYSTEM,/* Resources, troubleshooting, system tools */
PYMENU_HELPWEBSITES,/* Help -> Websites submenu */
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index ddfb1b0044f..b0f82bc8f49 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -43,6 +43,11 @@
#include "gen_utils.h"
#include "../BPY_extern.h"
+/* used only for makeCurrent, this may be deprecated when Blender.Base is implimented */
+#include "BIF_screen.h"
+#include "DNA_space_types.h"
+#include "DNA_screen_types.h"
+
#define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW
/*****************************************************************************/
@@ -106,6 +111,7 @@ static PyObject *Text_clear( BPy_Text * self );
static PyObject *Text_write( BPy_Text * self, PyObject * args );
static PyObject *Text_set( BPy_Text * self, PyObject * args );
static PyObject *Text_asLines( BPy_Text * self );
+static PyObject *Text_makeCurrent( BPy_Text * self );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -128,6 +134,8 @@ static PyMethodDef BPy_Text_methods[] = {
"(name, val) - Set attribute 'name' to value 'val'"},
{"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
"() - Return text buffer as a list of lines"},
+ {"makeCurrent", ( PyCFunction ) Text_makeCurrent, METH_NOARGS,
+ "() - display this text."},
{NULL, NULL, 0, NULL}
};
@@ -528,6 +536,23 @@ static PyObject *Text_asLines( BPy_Text * self )
return list;
}
+static PyObject *Text_makeCurrent( BPy_Text * self )
+{
+ /*
+ SpaceText *st= curarea->spacedata.first;
+
+ if( !self->text )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "This object isn't linked to a Blender Text Object" );
+
+ if(st->spacetype!=SPACE_TEXT)
+ Py_RETURN_NONE;
+
+ st->text = self->text;
+ */
+ Py_RETURN_NONE;
+}
+
/*****************************************************************************/
/* Function: Text_dealloc */
/* Description: This is a callback function for the BPy_Text type. It is */
diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c
index 1aae671708e..ae97ee8b8b4 100644
--- a/source/blender/python/api2_2x/Window.c
+++ b/source/blender/python/api2_2x/Window.c
@@ -363,7 +363,6 @@ struct PyMethodDef M_Window_methods[] = {
PyObject *M_Window_Redraw( PyObject * self, PyObject * args )
{
ScrArea *tempsa, *sa;
- SpaceText *st;
int wintype = SPACE_VIEW3D;
short redraw_all = 0;
diff --git a/source/blender/python/api2_2x/doc/Text.py b/source/blender/python/api2_2x/doc/Text.py
index edb88d0f3f0..ad37de8171c 100644
--- a/source/blender/python/api2_2x/doc/Text.py
+++ b/source/blender/python/api2_2x/doc/Text.py
@@ -125,3 +125,10 @@ class Text:
@rtype: list of strings
@return: A list of strings, one for each line in the buffer
"""
+
+ def makeCurrent():
+ """
+ Display this text in the current 3d view if any
+ @rtype: None
+ @return: None
+ """ \ No newline at end of file
diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c
index e370a1deb10..d14ee33354a 100644
--- a/source/blender/src/header_text.c
+++ b/source/blender/src/header_text.c
@@ -67,6 +67,7 @@
#include "BSE_filesel.h"
#include "BPY_extern.h"
+#include "BPY_menus.h"
#include "blendef.h"
#include "mydevice.h"
@@ -197,6 +198,37 @@ void do_text_buttons(unsigned short event)
}
}
+static void do_text_template_scriptsmenu(void *arg, int event)
+{
+ BPY_menu_do_python(PYMENU_SCRIPTTEMPLATE, event);
+
+ allqueue(REDRAWIMAGE, 0);
+}
+
+static uiBlock *text_template_scriptsmenu (void *args_unused)
+{
+ uiBlock *block;
+ BPyMenu *pym;
+ int i= 0;
+ short yco = 20, menuwidth = 120;
+
+ block= uiNewBlock(&curarea->uiblocks, "text_template_scriptsmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
+ uiBlockSetButmFunc(block, do_text_template_scriptsmenu, NULL);
+
+ /* note that we acount for the N previous entries with i+20: */
+ for (pym = BPyMenuTable[PYMENU_SCRIPTTEMPLATE]; pym; pym = pym->next, i++) {
+
+ uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19,
+ NULL, 0.0, 0.0, 1, i,
+ pym->tooltip?pym->tooltip:pym->filename);
+ }
+
+ uiBlockSetDirection(block, UI_RIGHT);
+ uiTextBoundsBlock(block, 60);
+
+ return block;
+}
+
/* action executed after clicking in File menu */
static void do_text_filemenu(void *arg, int event)
{
@@ -577,13 +609,15 @@ static uiBlock *text_filemenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "New|Alt N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Open...|Alt O", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
if(text) {
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reopen|Alt R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reopen|Alt R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save As...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Run Python Script|Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
}
+
+ uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c
index 66f69ac3a78..2b966aacc8b 100644
--- a/source/blender/src/header_view3d.c
+++ b/source/blender/src/header_view3d.c
@@ -3576,6 +3576,40 @@ static void do_view3d_edit_armaturemenu(void *arg, int event)
allqueue(REDRAWVIEW3D, 0);
}
+
+
+static void do_view3d_scripts_armaturemenu(void *arg, int event)
+{
+ BPY_menu_do_python(PYMENU_SCRIPTTEMPLATE, event);
+
+ allqueue(REDRAWIMAGE, 0);
+}
+
+static uiBlock *view3d_scripts_armaturemenu(void *args_unused)
+{
+ uiBlock *block;
+ BPyMenu *pym;
+ int i= 0;
+ short yco = 20, menuwidth = 120;
+
+ block= uiNewBlock(&curarea->uiblocks, "view3d_scripts_armaturemenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
+ uiBlockSetButmFunc(block, do_view3d_scripts_armaturemenu, NULL);
+
+ /* note that we acount for the N previous entries with i+20: */
+ for (pym = BPyMenuTable[PYMENU_ARMATURE]; pym; pym = pym->next, i++) {
+
+ uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20, menuwidth, 19,
+ NULL, 0.0, 0.0, 1, i,
+ pym->tooltip?pym->tooltip:pym->filename);
+ }
+
+ uiBlockSetDirection(block, UI_RIGHT);
+ uiTextBoundsBlock(block, 60);
+
+ return block;
+}
+
+
static uiBlock *view3d_edit_armaturemenu(void *arg_unused)
{
bArmature *arm= G.obedit->data;
@@ -3613,7 +3647,11 @@ static uiBlock *view3d_edit_armaturemenu(void *arg_unused)
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBlockBut(block, view3d_edit_armature_parentmenu, NULL, ICON_RIGHTARROW_THIN, "Parent", 0, yco-=20, 120, 19, "");
-
+
+ uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+
+ uiDefIconTextBlockBut(block, view3d_scripts_armaturemenu, NULL, ICON_RIGHTARROW_THIN, "Scripts", 0, yco-=20, 120, 19, "");
+
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
}