forked from bartvdbraak/blender
made python add mesh module respect blenders user settings for editmode and view align.
added sys.cleanpath() was a patch in the tracker but blender's internal path cleaning is now more general and can be used from python.
This commit is contained in:
parent
722f24d153
commit
4255f3c7ab
@ -16,13 +16,17 @@ def add_mesh_simple(name, verts, edges, faces):
|
|||||||
scn = bpy.data.scenes.active
|
scn = bpy.data.scenes.active
|
||||||
if scn.lib: return
|
if scn.lib: return
|
||||||
ob_act = scn.objects.active
|
ob_act = scn.objects.active
|
||||||
|
|
||||||
|
is_editmode = EditMode()
|
||||||
|
|
||||||
cursor = GetCursorPos()
|
cursor = GetCursorPos()
|
||||||
try: quat = Blender.Mathutils.Quaternion(GetViewQuat())
|
quat = None
|
||||||
except: quat = None
|
if is_editmode or Blender.Get('add_view_align'): # Aligning seems odd for editmode, but blender does it, oh well
|
||||||
|
try: quat = Blender.Mathutils.Quaternion(GetViewQuat())
|
||||||
|
except: pass
|
||||||
|
|
||||||
# Exist editmode for non mesh types
|
# Exist editmode for non mesh types
|
||||||
if ob_act and ob_act.type != 'Mesh' and EditMode():
|
if ob_act and ob_act.type != 'Mesh' and is_editmode:
|
||||||
EditMode(0)
|
EditMode(0)
|
||||||
|
|
||||||
# We are in mesh editmode
|
# We are in mesh editmode
|
||||||
@ -65,8 +69,9 @@ def add_mesh_simple(name, verts, edges, faces):
|
|||||||
# Mesh with no data, unlikely
|
# Mesh with no data, unlikely
|
||||||
me.edges.extend(edges)
|
me.edges.extend(edges)
|
||||||
me.faces.extend(faces)
|
me.faces.extend(faces)
|
||||||
|
|
||||||
EditMode(1)
|
if is_editmode or Blender.Get('add_editmode'):
|
||||||
|
EditMode(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@ -90,8 +95,9 @@ def add_mesh_simple(name, verts, edges, faces):
|
|||||||
ob_act.setMatrix(mat)
|
ob_act.setMatrix(mat)
|
||||||
|
|
||||||
ob_act.loc = cursor
|
ob_act.loc = cursor
|
||||||
|
|
||||||
EditMode(1)
|
if is_editmode or Blender.Get('add_editmode'):
|
||||||
|
EditMode(1)
|
||||||
|
|
||||||
|
|
||||||
def write_mesh_script(filepath, me):
|
def write_mesh_script(filepath, me):
|
||||||
|
@ -545,8 +545,12 @@ static PyObject *Blender_Get( PyObject * self, PyObject * value )
|
|||||||
else if(StringEqual( str, "compressfile" ))
|
else if(StringEqual( str, "compressfile" ))
|
||||||
ret = PyInt_FromLong( (U.flag & USER_FILECOMPRESS) >> 15 );
|
ret = PyInt_FromLong( (U.flag & USER_FILECOMPRESS) >> 15 );
|
||||||
else if(StringEqual( str, "mipmap" ))
|
else if(StringEqual( str, "mipmap" ))
|
||||||
ret = PyInt_FromLong( (U.gameflags & USER_DISABLE_MIPMAP) == 0 );
|
ret = PyInt_FromLong( (U.gameflags & USER_DISABLE_MIPMAP)!=0 );
|
||||||
else
|
else if(StringEqual( str, "add_view_align" ))
|
||||||
|
ret = PyInt_FromLong( ((U.flag & USER_ADD_VIEWALIGNED)!=0) );
|
||||||
|
else if(StringEqual( str, "add_editmode" ))
|
||||||
|
ret = PyInt_FromLong( ((U.flag & USER_ADD_EDITMODE)!=0) );
|
||||||
|
else
|
||||||
return EXPP_ReturnPyObjError( PyExc_AttributeError, "unknown attribute" );
|
return EXPP_ReturnPyObjError( PyExc_AttributeError, "unknown attribute" );
|
||||||
|
|
||||||
if (ret) return ret;
|
if (ret) return ret;
|
||||||
|
@ -58,6 +58,7 @@ static PyObject *M_sys_exists( PyObject * self, PyObject * value );
|
|||||||
static PyObject *M_sys_time( PyObject * self );
|
static PyObject *M_sys_time( PyObject * self );
|
||||||
static PyObject *M_sys_sleep( PyObject * self, PyObject * args );
|
static PyObject *M_sys_sleep( PyObject * self, PyObject * args );
|
||||||
static PyObject *M_sys_expandpath( PyObject *self, PyObject *value);
|
static PyObject *M_sys_expandpath( PyObject *self, PyObject *value);
|
||||||
|
static PyObject *M_sys_cleanpath( PyObject *self, PyObject *value);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* The following string definitions are used for documentation strings. */
|
/* The following string definitions are used for documentation strings. */
|
||||||
@ -120,10 +121,13 @@ static char M_sys_expandpath_doc[] =
|
|||||||
(path) - the string path to convert.\n\n\
|
(path) - the string path to convert.\n\n\
|
||||||
Note: internally Blender paths can contain two special character sequences:\n\
|
Note: internally Blender paths can contain two special character sequences:\n\
|
||||||
- '//' (at start) for base path directory (the current .blend's dir path);\n\
|
- '//' (at start) for base path directory (the current .blend's dir path);\n\
|
||||||
- '#' (at ending) for current frame number.\n\n\
|
- '#' characters in the filename will be replaced by the frame number.\n\n\
|
||||||
This function expands these to their actual content, returning a valid path.\n\
|
This function expands these to their actual content, returning a valid path.\n\
|
||||||
If the special chars are not found in the given path, it is simply returned.";
|
If the special chars are not found in the given path, it is simply returned.";
|
||||||
|
|
||||||
|
static char M_sys_cleanpath_doc[] =
|
||||||
|
"(path) - Removes parts of a path that are not needed paths such as '../foo/../bar/' and '//./././'";
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Python method structure definition for Blender.sys module: */
|
/* Python method structure definition for Blender.sys module: */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -139,6 +143,7 @@ struct PyMethodDef M_sys_methods[] = {
|
|||||||
{"sleep", M_sys_sleep, METH_VARARGS, M_sys_sleep_doc},
|
{"sleep", M_sys_sleep, METH_VARARGS, M_sys_sleep_doc},
|
||||||
{"time", ( PyCFunction ) M_sys_time, METH_NOARGS, M_sys_time_doc},
|
{"time", ( PyCFunction ) M_sys_time, METH_NOARGS, M_sys_time_doc},
|
||||||
{"expandpath", M_sys_expandpath, METH_O, M_sys_expandpath_doc},
|
{"expandpath", M_sys_expandpath, METH_O, M_sys_expandpath_doc},
|
||||||
|
{"cleanpath", M_sys_cleanpath, METH_O, M_sys_cleanpath_doc},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -396,3 +401,24 @@ static PyObject *M_sys_expandpath( PyObject * self, PyObject * value )
|
|||||||
|
|
||||||
return PyString_FromString(expanded);
|
return PyString_FromString(expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *M_sys_cleanpath( PyObject * self, PyObject * value )
|
||||||
|
{
|
||||||
|
char *path = PyString_AsString(value);
|
||||||
|
char cleaned[FILE_MAXDIR + FILE_MAXFILE];
|
||||||
|
int trailing_slash = 0;
|
||||||
|
if (!path)
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||||
|
"expected string argument" );
|
||||||
|
if (strstr(path, "/") || strstr(path, "\\")) {
|
||||||
|
trailing_slash = 1;
|
||||||
|
}
|
||||||
|
BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE);
|
||||||
|
BLI_cleanup_file(NULL, cleaned);
|
||||||
|
|
||||||
|
if (trailing_slash) {
|
||||||
|
BLI_add_slash(cleaned);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PyString_FromString(cleaned);
|
||||||
|
}
|
||||||
|
@ -153,7 +153,7 @@ def expandpath (path):
|
|||||||
Internally, Blender recognizes two special character sequences in paths:
|
Internally, Blender recognizes two special character sequences in paths:
|
||||||
- '//' (used at the beginning): means base path -- the current .blend file's
|
- '//' (used at the beginning): means base path -- the current .blend file's
|
||||||
dir;
|
dir;
|
||||||
- '#' (used at the end): means current frame number.
|
- '#' characters in the filename will be replaced by the frame number.
|
||||||
The expanded string can be passed to generic python functions that don't
|
The expanded string can be passed to generic python functions that don't
|
||||||
understand Blender's internal relative paths.
|
understand Blender's internal relative paths.
|
||||||
@note: this function is also useful for obtaining the name of the image
|
@note: this function is also useful for obtaining the name of the image
|
||||||
@ -165,3 +165,12 @@ def expandpath (path):
|
|||||||
@rtype: string
|
@rtype: string
|
||||||
@return: the expanded (if necessary) path.
|
@return: the expanded (if necessary) path.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def cleanpath (path):
|
||||||
|
"""
|
||||||
|
Clean the given 'path' by removing unneeded components such as "/./" and "/test/../"
|
||||||
|
@type path: string
|
||||||
|
@param path: a path name.
|
||||||
|
@rtype: string
|
||||||
|
@return: the cleaned (if necessary) path.
|
||||||
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user