[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36710] trunk/blender/release/scripts: move generic bpy helper modules into bpy_extras.

Matt Ebb matt at mke3.net
Sat Jun 4 03:15:16 CEST 2011


Hi Campbell - just a heads up, this commit wasn't mentioned here:

http://wiki.blender.org/index.php/Dev:2.5/Py/API/Updates

It has the effect of breaking compatibility since you now need to import
bpy_extras.io_utils rather than just io_utils. This makes it difficult
(well, messy, with a try/except) to support 2.57 and current svn versions.

What's the policy on this sort of thing now that 2.57 is out? I thought
there would be less breakage happening now ;)

cheers

Matt



On Mon, May 16, 2011 at 5:51 PM, Campbell Barton <ideasman42 at gmail.com>wrote:

> Revision: 36710
>
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36710
> Author:   campbellbarton
> Date:     2011-05-16 07:51:02 +0000 (Mon, 16 May 2011)
> Log Message:
> -----------
> move generic bpy helper modules into bpy_extras.
>
> Modified Paths:
> --------------
>    trunk/blender/release/scripts/startup/bl_operators/add_mesh_torus.py
>    trunk/blender/release/scripts/templates/operator_export.py
>    trunk/blender/release/scripts/templates/operator_mesh_add.py
>
> Added Paths:
> -----------
>    trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
>    trunk/blender/release/scripts/modules/bpy_extras/io_utils.py
>    trunk/blender/release/scripts/modules/bpy_extras/mesh_utils.py
>    trunk/blender/release/scripts/modules/bpy_extras/object_utils.py
>    trunk/blender/release/scripts/modules/bpy_extras/view3d_utils.py
>
> Removed Paths:
> -------------
>    trunk/blender/release/scripts/modules/add_object_utils.py
>    trunk/blender/release/scripts/modules/image_utils.py
>    trunk/blender/release/scripts/modules/io_utils.py
>    trunk/blender/release/scripts/modules/mesh_utils.py
>    trunk/blender/release/scripts/modules/view3d_utils.py
>
> Deleted: trunk/blender/release/scripts/modules/add_object_utils.py
> ===================================================================
> --- trunk/blender/release/scripts/modules/add_object_utils.py   2011-05-16
> 07:48:43 UTC (rev 36709)
> +++ trunk/blender/release/scripts/modules/add_object_utils.py   2011-05-16
> 07:51:02 UTC (rev 36710)
> @@ -1,116 +0,0 @@
> -# ##### BEGIN GPL LICENSE BLOCK #####
> -#
> -#  This program is free software; you can redistribute it and/or
> -#  modify it under the terms of the GNU General Public License
> -#  as published by the Free Software Foundation; either version 2
> -#  of the License, or (at your option) any later version.
> -#
> -#  This program is distributed in the hope that it will be useful,
> -#  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -#  GNU General Public License for more details.
> -#
> -#  You should have received a copy of the GNU General Public License
> -#  along with this program; if not, write to the Free Software Foundation,
> -#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> -#
> -# ##### END GPL LICENSE BLOCK #####
> -
> -# <pep8 compliant>
> -
> -import bpy
> -import mathutils
> -
> -
> -def add_object_align_init(context, operator):
> -    space_data = context.space_data
> -    if space_data.type != 'VIEW_3D':
> -        space_data = None
> -
> -    # location
> -    if operator and operator.properties.is_property_set("location"):
> -        location =
> mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location))
> -    else:
> -        if space_data:  # local view cursor is detected below
> -            location =
> mathutils.Matrix.Translation(space_data.cursor_location)
> -        else:
> -            location =
> mathutils.Matrix.Translation(context.scene.cursor_location)
> -
> -        if operator:
> -            operator.properties.location = location.to_translation()
> -
> -    # rotation
> -    view_align = (context.user_preferences.edit.object_align == 'VIEW')
> -    view_align_force = False
> -    if operator:
> -        if operator.properties.is_property_set("view_align"):
> -            view_align = view_align_force = operator.view_align
> -        else:
> -            operator.properties.view_align = view_align
> -
> -    if operator and operator.properties.is_property_set("rotation") and
> not view_align_force:
> -        rotation =
> mathutils.Euler(operator.properties.rotation).to_matrix().to_4x4()
> -    else:
> -        if view_align and space_data:
> -            rotation =
> space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
> -        else:
> -            rotation = mathutils.Matrix()
> -
> -        # set the operator properties
> -        if operator:
> -            operator.properties.rotation = rotation.to_euler()
> -
> -    return location * rotation
> -
> -
> -def object_data_add(context, obdata, operator=None):
> -
> -    scene = context.scene
> -
> -    # ugh, could be made nicer
> -    for ob in scene.objects:
> -        ob.select = False
> -
> -    obj_new = bpy.data.objects.new(obdata.name, obdata)
> -
> -    base = scene.objects.link(obj_new)
> -    base.select = True
> -
> -    if context.space_data and context.space_data.type == 'VIEW_3D':
> -        base.layers_from_view(context.space_data)
> -
> -    obj_new.matrix_world = add_object_align_init(context, operator)
> -
> -    obj_act = scene.objects.active
> -
> -    # XXX
> -    # caused because entering editmodedoes not add a empty undo slot!
> -    if context.user_preferences.edit.use_enter_edit_mode:
> -        if not (obj_act and obj_act.mode == 'EDIT' and obj_act.type ==
> obj_new.type):
> -            _obdata = bpy.data.meshes.new(obdata.name)
> -            obj_act = bpy.data.objects.new(_obdata.name, _obdata)
> -            obj_act.matrix_world = obj_new.matrix_world
> -            scene.objects.link(obj_act)
> -            scene.objects.active = obj_act
> -            bpy.ops.object.mode_set(mode='EDIT')
> -            bpy.ops.ed.undo_push(message="Enter Editmode")  # need empty
> undo step
> -    # XXX
> -
> -    if obj_act and obj_act.mode == 'EDIT' and obj_act.type ==
> obj_new.type:
> -        bpy.ops.mesh.select_all(action='DESELECT')
> -        bpy.ops.object.mode_set(mode='OBJECT')
> -
> -        obj_act.select = True
> -        scene.update()  # apply location
> -        #scene.objects.active = obj_new
> -
> -        bpy.ops.object.join()  # join into the active.
> -        bpy.data.meshes.remove(obdata)
> -
> -        bpy.ops.object.mode_set(mode='EDIT')
> -    else:
> -        scene.objects.active = obj_new
> -        if context.user_preferences.edit.use_enter_edit_mode:
> -            bpy.ops.object.mode_set(mode='EDIT')
> -
> -    return base
>
> Copied: trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
> (from rev 36708, trunk/blender/release/scripts/modules/image_utils.py)
> ===================================================================
> --- trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
>                     (rev 0)
> +++ trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
> 2011-05-16 07:51:02 UTC (rev 36710)
> @@ -0,0 +1,27 @@
> +# ##### BEGIN GPL LICENSE BLOCK #####
> +#
> +#  This program is free software; you can redistribute it and/or
> +#  modify it under the terms of the GNU General Public License
> +#  as published by the Free Software Foundation; either version 2
> +#  of the License, or (at your option) any later version.
> +#
> +#  This program is distributed in the hope that it will be useful,
> +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#  GNU General Public License for more details.
> +#
> +#  You should have received a copy of the GNU General Public License
> +#  along with this program; if not, write to the Free Software Foundation,
> +#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> +#
> +# ##### END GPL LICENSE BLOCK #####
> +
> +# <pep8 compliant>
> +
> +
> +def image_load(filepath, dirpath, place_holder=False, recursive=False,
> convert_callback=None):
> +    import bpy
> +    try:
> +        return bpy.data.images.load(filepath)
> +    except RuntimeError:
> +        return bpy.data.images.new("Untitled", 128, 128)
>
> Copied: trunk/blender/release/scripts/modules/bpy_extras/io_utils.py (from
> rev 36708, trunk/blender/release/scripts/modules/io_utils.py)
> ===================================================================
> --- trunk/blender/release/scripts/modules/bpy_extras/io_utils.py
>                      (rev 0)
> +++ trunk/blender/release/scripts/modules/bpy_extras/io_utils.py
>  2011-05-16 07:51:02 UTC (rev 36710)
> @@ -0,0 +1,304 @@
> +# ##### BEGIN GPL LICENSE BLOCK #####
> +#
> +#  This program is free software; you can redistribute it and/or
> +#  modify it under the terms of the GNU General Public License
> +#  as published by the Free Software Foundation; either version 2
> +#  of the License, or (at your option) any later version.
> +#
> +#  This program is distributed in the hope that it will be useful,
> +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#  GNU General Public License for more details.
> +#
> +#  You should have received a copy of the GNU General Public License
> +#  along with this program; if not, write to the Free Software Foundation,
> +#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> +#
> +# ##### END GPL LICENSE BLOCK #####
> +
> +# <pep8 compliant>
> +
> +import bpy
> +from bpy.props import StringProperty, BoolProperty, EnumProperty
> +
> +
> +class ExportHelper:
> +    filepath = StringProperty(name="File Path", description="Filepath used
> for exporting the file", maxlen=1024, default="", subtype='FILE_PATH')
> +    check_existing = BoolProperty(name="Check Existing",
> description="Check and warn on overwriting existing files", default=True,
> options={'HIDDEN'})
> +
> +    # subclasses can override with decorator
> +    # True == use ext, False == no ext, None == do nothing.
> +    check_extension = True
> +
> +    def invoke(self, context, event):
> +        import os
> +        if not self.filepath:
> +            blend_filepath = context.blend_data.filepath
> +            if not blend_filepath:
> +                blend_filepath = "untitled"
> +            else:
> +                blend_filepath = os.path.splitext(blend_filepath)[0]
> +
> +            self.filepath = blend_filepath + self.filename_ext
> +
> +        context.window_manager.fileselect_add(self)
> +        return {'RUNNING_MODAL'}
> +
> +    def check(self, context):
> +        check_extension = self.check_extension
> +
> +        if check_extension is None:
> +            return False
> +
> +        filepath = bpy.path.ensure_ext(self.filepath, self.filename_ext if
> check_extension else "")
> +
> +        if filepath != self.filepath:
> +            self.filepath = filepath
> +            return True
> +
> +        return False
> +
> +
> +class ImportHelper:
> +    filepath = StringProperty(name="File Path", description="Filepath used
> for importing the file", maxlen=1024, default="", subtype='FILE_PATH')
> +
> +    def invoke(self, context, event):
> +        context.window_manager.fileselect_add(self)
> +        return {'RUNNING_MODAL'}
> +
> +
> +# Axis conversion function, not pretty LUT
> +# use lookup tabes to convert between any axis
> +_axis_convert_matrix = (
> +    ((-1.0, 0.0, 0.0), (0.0, -1.0, 0.0), (0.0, 0.0, 1.0)),
> +    ((-1.0, 0.0, 0.0), (0.0, 0.0, -1.0), (0.0, -1.0, 0.0)),
> +    ((-1.0, 0.0, 0.0), (0.0, 0.0, 1.0), (0.0, 1.0, 0.0)),
> +    ((-1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, -1.0)),
> +    ((0.0, -1.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, -1.0)),
> +    ((0.0, -1.0, 0.0), (0.0, 0.0, -1.0), (1.0, 0.0, 0.0)),
> +    ((0.0, -1.0, 0.0), (0.0, 0.0, 1.0), (-1.0, 0.0, 0.0)),
> +    ((0.0, -1.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 1.0)),
> +    ((0.0, 0.0, -1.0), (-1.0, 0.0, 0.0), (0.0, 1.0, 0.0)),
> +    ((0.0, 0.0, -1.0), (0.0, -1.0, 0.0), (-1.0, 0.0, 0.0)),
> +    ((0.0, 0.0, -1.0), (0.0, 1.0, 0.0), (1.0, 0.0, 0.0)),
> +    ((0.0, 0.0, -1.0), (1.0, 0.0, 0.0), (0.0, -1.0, 0.0)),
> +    ((0.0, 0.0, 1.0), (-1.0, 0.0, 0.0), (0.0, -1.0, 0.0)),
> +    ((0.0, 0.0, 1.0), (0.0, -1.0, 0.0), (1.0, 0.0, 0.0)),
> +    ((0.0, 0.0, 1.0), (0.0, 1.0, 0.0), (-1.0, 0.0, 0.0)),
> +    ((0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)),
> +    ((0.0, 1.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0)),
> +    ((0.0, 1.0, 0.0), (0.0, 0.0, -1.0), (-1.0, 0.0, 0.0)),
> +    ((0.0, 1.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0)),
> +    ((0.0, 1.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, -1.0)),
> +    ((1.0, 0.0, 0.0), (0.0, -1.0, 0.0), (0.0, 0.0, -1.0)),
> +    ((1.0, 0.0, 0.0), (0.0, 0.0, -1.0), (0.0, 1.0, 0.0)),
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>


More information about the Bf-committers mailing list