[Bf-extensions-cvs] [0dd81953] master: initial commit ktools by kjartan tysdal
meta-androcto
noreply at git.blender.org
Sat May 13 11:15:24 CEST 2017
Commit: 0dd819533b3fb2523f591361d8d19b94d0402194
Author: meta-androcto
Date: Sat May 13 19:14:55 2017 +1000
Branches: master
https://developer.blender.org/rBAC0dd819533b3fb2523f591361d8d19b94d0402194
initial commit ktools by kjartan tysdal
===================================================================
A ktools.py
===================================================================
diff --git a/ktools.py b/ktools.py
new file mode 100644
index 00000000..7816c060
--- /dev/null
+++ b/ktools.py
@@ -0,0 +1,2522 @@
+# ##### 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 #####
+
+
+
+
+bl_info = {
+ 'name': "Kjartans Scripts",
+ 'author': "Kjartan Tysdal",
+ 'location': '"Shift+Q" and also in EditMode "W-Specials/ KTools"',
+ 'description': "Adds my personal collection of small handy scripts (mostly modeling tools)",
+ 'category': "Mesh",
+ 'blender': (2, 7, 6),
+ 'version': (0, 2, 8),
+ 'wiki_url': 'http://www.kjartantysdal.com/scripts',
+}
+
+
+import bpy, bmesh
+from bpy.props import StringProperty, IntProperty, FloatProperty, EnumProperty, BoolProperty, BoolVectorProperty, FloatVectorProperty
+
+def testPrint():
+
+ print('Hello')
+
+
+def checkScale(): # check if scale is 0 on any of the axis, if it is then set it to 0.01
+
+ y = -1
+ for x in bpy.context.object.scale:
+ y += 1
+ if x == 0.0:
+ bpy.context.object.scale[y] = 0.01
+
+
+#Adds "Lattice to Selection" to the Addon
+class lattice_to_selection(bpy.types.Operator):
+ """Add a lattice deformer to the selection"""
+ bl_idname = "object.lattice_to_selection"
+ bl_label = "Lattice to Selection"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ apply_rot = BoolProperty(name = "Local", description = "Orient the lattice to the active object", default = True)
+ parent_to = BoolProperty(name = "Parent to Lattice", description = "Parents all the objects to the Lattice", default = False)
+ move_first = BoolProperty(name = "First in Modifier Stack", description = "Moves the lattice modifier to be first in the stack", default = False)
+ interpolation = bpy.props.EnumProperty(items= (('KEY_LINEAR', 'Linear', 'Linear Interpolation'),
+ ('KEY_CARDINAL', 'Cardinal', 'Cardinal Interpolation'),
+ ('KEY_CATMULL_ROM', 'Catmull Rom', 'Catmull Rom Interpolation'),
+ ('KEY_BSPLINE', 'BSpline', 'BSpline Interpolation')),
+ name = "Interpolation", default = 'KEY_BSPLINE')
+ seg_u = IntProperty( name = "Lattice U", default = 2, soft_min = 2)
+ seg_v = IntProperty( name = "Lattice V", default = 2, soft_min = 2 )
+ seg_w = IntProperty( name = "Lattice W", default = 2, soft_min = 2 )
+
+ def execute(self, context):
+
+ apply_rot = not self.apply_rot # Global vs Local
+ parent_to = self.parent_to # Parents all the objects to the Lattice
+ move_first = self.move_first # moves the lattice modifier to be first in the stack
+ interpolation = self.interpolation
+
+ # check if there exists an active object
+ if bpy.context.scene.objects.active:
+ active_obj = bpy.context.scene.objects.active.name
+ else:
+ for x in bpy.context.selected_objects:
+ if bpy.data.objects[x.name].type == 'MESH':
+ bpy.context.scene.objects.active = bpy.data.objects[x.name]
+ active_obj = bpy.context.scene.objects.active.name
+ break
+
+
+
+ if bpy.data.objects[active_obj].type != 'MESH':
+ self.report({'ERROR'}, "Make sure the active object is a Mesh")
+ return {'CANCELLED'}
+
+ mode = bpy.context.active_object.mode
+
+
+ if mode == 'OBJECT':
+
+
+ # check if object type is not MESH and then deselect it
+ for x in bpy.context.selected_objects:
+ if bpy.data.objects[x.name].type != 'MESH':
+ bpy.data.objects[x.name].select = False
+
+
+ org_objs = bpy.context.selected_objects
+
+
+ bpy.ops.object.duplicate()
+
+ # remove any modifiers
+ if bpy.context.object.modifiers:
+ for x in bpy.context.object.modifiers:
+ bpy.ops.object.modifier_remove(modifier=x.name)
+
+ if len(bpy.context.selected_objects) > 1:
+ bpy.ops.object.join()
+
+ # create tmp:object and store its location, rotation and dimensions
+ bpy.ops.object.transform_apply(location=False, rotation=apply_rot, scale=True)
+ bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
+
+ lattice_loc = bpy.context.object.location
+ lattice_rot = bpy.context.object.rotation_euler
+ bbox_size = bpy.context.object.dimensions
+ tmp_obj = bpy.context.object.name
+
+ # create the lattice object with the lattice_loc and rot
+ bpy.ops.object.add(radius=1, type='LATTICE', view_align=False, enter_editmode=False, location=lattice_loc, rotation=lattice_rot)
+
+ lattice_obj = bpy.context.object
+
+ # set dimensions / bounding box size
+ bpy.context.object.scale = bbox_size
+
+ bpy.ops.object.select_all(action='DESELECT')
+
+ # select and delete the tmp_object
+ bpy.data.objects[tmp_obj].select = True
+ bpy.ops.object.delete(use_global=False)
+
+ # select all the original objects and assign the lattice deformer
+ for i in org_objs:
+ if bpy.data.objects[i.name].type == 'MESH' :
+ bpy.context.scene.objects.active = bpy.data.objects[i.name]
+ bpy.data.objects[i.name].select = True
+
+ bpy.ops.object.modifier_add(type='LATTICE')
+ lattice_name = bpy.context.object.modifiers[len(bpy.context.object.modifiers)-1].name
+ bpy.context.object.modifiers[lattice_name].object = lattice_obj
+ if move_first == True:
+ for x in bpy.context.object.modifiers:
+ bpy.ops.object.modifier_move_up(modifier=lattice_name)
+ else:
+ bpy.data.objects[i.name].select = True
+
+
+ if parent_to:
+
+ bpy.data.objects[lattice_obj.name].select = True
+ bpy.context.scene.objects.active = bpy.data.objects[lattice_obj.name]
+
+ bpy.ops.object.parent_set(type='OBJECT', keep_transform=True)
+ else:
+
+ bpy.ops.object.select_all(action='DESELECT')
+ bpy.data.objects[lattice_obj.name].select = True
+ bpy.context.scene.objects.active = bpy.data.objects[lattice_obj.name]
+
+
+ bpy.context.object.data.interpolation_type_u = interpolation
+ bpy.context.object.data.interpolation_type_v = interpolation
+ bpy.context.object.data.interpolation_type_w = interpolation
+
+ bpy.context.object.data.points_u = self.seg_u
+ bpy.context.object.data.points_v = self.seg_v
+ bpy.context.object.data.points_w = self.seg_w
+
+ checkScale()
+
+
+ elif mode == 'EDIT':
+
+
+
+ org_objs = bpy.context.selected_objects
+
+ # Add vertex group and store its name in a variable
+ bpy.ops.object.vertex_group_assign_new()
+ v_id = len(bpy.context.object.vertex_groups)-1
+ bpy.context.object.vertex_groups[v_id].name = 'tmp_lattice_to_selection'
+ v_group = bpy.context.object.vertex_groups[v_id].name
+
+
+ bpy.ops.mesh.duplicate()
+ bpy.ops.mesh.separate(type='SELECTED')
+
+ bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
+
+ for x in bpy.context.selected_objects:
+ if x not in org_objs:
+ tmp_obj = x.name
+ print(tmp_obj)
+
+ bpy.ops.object.select_all(action='DESELECT')
+
+ bpy.context.scene.objects.active = bpy.data.objects[tmp_obj]
+ bpy.data.objects[tmp_obj].s
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list