[Durian-svn] [1456] A small script that replaces all your currently selected objects with the currently active one .
dolf
institute at blender.org
Tue Mar 23 17:52:30 CET 2010
Revision: 1456
https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=1456
Author: dolf
Date: 2010-03-23 17:52:29 +0100 (Tue, 23 Mar 2010)
Log Message:
-----------
A small script that replaces all your currently selected objects with the currently active one.
I need this to replace all the dupligrouped buildings in the city with proper geometry.
Added Paths:
-----------
pro/scripts/ui/replace_by_active.py
Added: pro/scripts/ui/replace_by_active.py
===================================================================
--- pro/scripts/ui/replace_by_active.py (rev 0)
+++ pro/scripts/ui/replace_by_active.py 2010-03-23 16:52:29 UTC (rev 1456)
@@ -0,0 +1,94 @@
+'''
+
+Version: 1
+Date: 03-2010
+Author: Dolf J. Veenvliet (macouno)
+Web: alienhelpesk.com
+
+'''
+
+# ##### 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+import bpy;
+
+def main(context):
+
+ actOb = context.active_object
+ is_editmode = (actOb.mode == 'EDIT')
+
+ scene = context.scene
+
+ doObs = []
+
+ for ob in context.selected_objects:
+
+ if ob != actOb:
+
+ doObs.append(ob)
+ ob.selected = False
+
+ for ob in doObs:
+
+ scene.objects.active = actOb
+
+ bpy.ops.object.duplicate()
+
+ actOb = scene.objects.active
+
+ actOb.matrix = ob.matrix
+
+ name = ob.name
+
+ scene.objects.unlink(ob)
+
+ actOb.name = name
+
+ if is_editmode:
+ bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+
+class ReplaceByActive(bpy.types.Operator):
+
+ bl_idname = "object.replace_by_active"
+ bl_label = "Replace Selected by Active"
+ bl_register = True
+
+ def poll(self, context):
+ return context.active_object
+
+ def execute(self, context):
+ main(context)
+ return {'FINISHED'}
+
+# Add to the menu
+menu_func = (lambda self, context: self.layout.operator(ReplaceByActive.bl_idname))
+
+def register():
+ bpy.types.register(ReplaceByActive)
+ bpy.types.VIEW3D_MT_object_apply.append(menu_func)
+
+
+def unregister():
+ bpy.types.unregister(ReplaceByActive)
+ bpy.types.VIEW3D_MT_object_apply.remove(menu_func)
+
+if __name__ == "__main__":
+ bpy.ops.object.convert_to_active()
+ bpy.types.VIEW3D_MT_object_apply.append(menu_func)
More information about the Durian-svn
mailing list