forked from bartvdbraak/blender
style changes for operator scripts & some pep8 edits.
This commit is contained in:
parent
6065390f4c
commit
4f4eeb826a
@ -16,7 +16,7 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
@ -111,7 +111,8 @@ class MeshMirrorUV(bpy.types.Operator):
|
||||
|
||||
#for i, v in enumerate(mesh.vertices):
|
||||
vmap = {}
|
||||
for mirror_a, mirror_b in (mirror_gt, mirror_lt), (mirror_lt, mirror_gt):
|
||||
for mirror_a, mirror_b in ((mirror_gt, mirror_lt),
|
||||
(mirror_lt, mirror_gt)):
|
||||
for co, i in mirror_a.items():
|
||||
nco = (-co[0], co[1], co[2])
|
||||
j = mirror_b.get(nco)
|
||||
@ -120,7 +121,8 @@ class MeshMirrorUV(bpy.types.Operator):
|
||||
|
||||
active_uv_layer = mesh.uv_textures.active.data
|
||||
fuvs = [(uv.uv1, uv.uv2, uv.uv3, uv.uv4) for uv in active_uv_layer]
|
||||
fuvs_cpy = [(uv[0].copy(), uv[1].copy(), uv[2].copy(), uv[3].copy()) for uv in fuvs]
|
||||
fuvs_cpy = [(uv[0].copy(), uv[1].copy(), uv[2].copy(), uv[3].copy())
|
||||
for uv in fuvs]
|
||||
|
||||
# as a list
|
||||
faces = mesh.faces[:]
|
||||
|
@ -28,9 +28,22 @@ class SelectPattern(bpy.types.Operator):
|
||||
bl_label = "Select Pattern"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen=32, default="*")
|
||||
case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default=False)
|
||||
extend = BoolProperty(name="Extend", description="Extend the existing selection", default=True)
|
||||
pattern = StringProperty(
|
||||
name="Pattern",
|
||||
description="Name filter using '*' and '?' wildcard chars",
|
||||
maxlen=32,
|
||||
default="*",
|
||||
)
|
||||
case_sensitive = BoolProperty(
|
||||
name="Case Sensitive",
|
||||
description="Do a case sensitive compare",
|
||||
default=False,
|
||||
)
|
||||
extend = BoolProperty(
|
||||
name="Extend",
|
||||
description="Extend the existing selection",
|
||||
default=True,
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
@ -39,7 +52,8 @@ class SelectPattern(bpy.types.Operator):
|
||||
if self.case_sensitive:
|
||||
pattern_match = fnmatch.fnmatchcase
|
||||
else:
|
||||
pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
|
||||
pattern_match = (lambda a, b:
|
||||
fnmatch.fnmatchcase(a.upper(), b.upper()))
|
||||
|
||||
obj = context.object
|
||||
if obj and obj.mode == 'POSE':
|
||||
@ -98,14 +112,19 @@ class SelectHierarchy(bpy.types.Operator):
|
||||
bl_label = "Select Hierarchy"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
direction = EnumProperty(items=(
|
||||
('PARENT', "Parent", ""),
|
||||
('CHILD', "Child", "")),
|
||||
name="Direction",
|
||||
description="Direction to select in the hierarchy",
|
||||
default='PARENT')
|
||||
direction = EnumProperty(
|
||||
items=(('PARENT', "Parent", ""),
|
||||
('CHILD', "Child", ""),
|
||||
),
|
||||
name="Direction",
|
||||
description="Direction to select in the hierarchy",
|
||||
default='PARENT')
|
||||
|
||||
extend = BoolProperty(name="Extend", description="Extend the existing selection", default=False)
|
||||
extend = BoolProperty(
|
||||
name="Extend",
|
||||
description="Extend the existing selection",
|
||||
default=False,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
@ -163,7 +182,12 @@ class SubdivisionSet(bpy.types.Operator):
|
||||
level = IntProperty(name="Level",
|
||||
default=1, min=-100, max=100, soft_min=-6, soft_max=6)
|
||||
|
||||
relative = BoolProperty(name="Relative", description="Apply the subsurf level as an offset relative to the current level", default=False)
|
||||
relative = BoolProperty(
|
||||
name="Relative",
|
||||
description=("Apply the subsurf level as an offset "
|
||||
"relative to the current level"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
@ -215,7 +239,8 @@ class SubdivisionSet(bpy.types.Operator):
|
||||
mod = obj.modifiers.new("Subsurf", 'SUBSURF')
|
||||
mod.levels = level
|
||||
except:
|
||||
self.report({'WARNING'}, "Modifiers cannot be added to object: " + obj.name)
|
||||
self.report({'WARNING'},
|
||||
"Modifiers cannot be added to object: " + obj.name)
|
||||
|
||||
for obj in context.selected_editable_objects:
|
||||
set_object_subd(obj)
|
||||
@ -224,23 +249,37 @@ class SubdivisionSet(bpy.types.Operator):
|
||||
|
||||
|
||||
class ShapeTransfer(bpy.types.Operator):
|
||||
'''Copy another selected objects active shape to this one by applying the relative offsets'''
|
||||
'''Copy another selected objects active shape to this one by ''' \
|
||||
'''applying the relative offsets'''
|
||||
|
||||
bl_idname = "object.shape_key_transfer"
|
||||
bl_label = "Transfer Shape Key"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
mode = EnumProperty(items=(
|
||||
('OFFSET', "Offset", "Apply the relative positional offset"),
|
||||
('RELATIVE_FACE', "Relative Face", "Calculate the geometricly relative position (using faces)."),
|
||||
('RELATIVE_EDGE', "Relative Edge", "Calculate the geometricly relative position (using edges).")),
|
||||
name="Transformation Mode",
|
||||
description="Method to apply relative shape positions to the new shape",
|
||||
default='OFFSET')
|
||||
|
||||
use_clamp = BoolProperty(name="Clamp Offset",
|
||||
description="Clamp the transformation to the distance each vertex moves in the original shape.",
|
||||
default=False)
|
||||
mode = EnumProperty(
|
||||
items=(('OFFSET',
|
||||
"Offset",
|
||||
"Apply the relative positional offset",
|
||||
),
|
||||
('RELATIVE_FACE',
|
||||
"Relative Face",
|
||||
"Calculate relative position (using faces).",
|
||||
),
|
||||
('RELATIVE_EDGE',
|
||||
"Relative Edge",
|
||||
"Calculate relative position (using edges).",
|
||||
),
|
||||
),
|
||||
name="Transformation Mode",
|
||||
description="Relative shape positions to the new shape method",
|
||||
default='OFFSET',
|
||||
)
|
||||
use_clamp = BoolProperty(
|
||||
name="Clamp Offset",
|
||||
description=("Clamp the transformation to the distance each "
|
||||
"vertex moves in the original shape."),
|
||||
default=False,
|
||||
)
|
||||
|
||||
def _main(self, ob_act, objects, mode='OFFSET', use_clamp=False):
|
||||
|
||||
@ -272,13 +311,16 @@ class ShapeTransfer(bpy.types.Operator):
|
||||
orig_shape_coords = me_cos(ob_act.active_shape_key.data)
|
||||
|
||||
orig_normals = me_nos(me.vertices)
|
||||
# orig_coords = me_cos(me.vertices) # the actual mverts location isnt as relyable as the base shape :S
|
||||
# the actual mverts location isnt as relyable as the base shape :S
|
||||
# orig_coords = me_cos(me.vertices)
|
||||
orig_coords = me_cos(me.shape_keys.key_blocks[0].data)
|
||||
|
||||
for ob_other in objects:
|
||||
me_other = ob_other.data
|
||||
if len(me_other.vertices) != len(me.vertices):
|
||||
self.report({'WARNING'}, "Skipping '%s', vertex count differs" % ob_other.name)
|
||||
self.report({'WARNING'},
|
||||
("Skipping '%s', "
|
||||
"vertex count differs") % ob_other.name)
|
||||
continue
|
||||
|
||||
target_normals = me_nos(me_other.vertices)
|
||||
@ -395,7 +437,10 @@ class ShapeTransfer(bpy.types.Operator):
|
||||
|
||||
if 1: # swap from/to, means we cant copy to many at once.
|
||||
if len(objects) != 1:
|
||||
self.report({'ERROR'}, "Expected one other selected mesh object to copy from")
|
||||
self.report({'ERROR'},
|
||||
("Expected one other selected "
|
||||
"mesh object to copy from"))
|
||||
|
||||
return {'CANCELLED'}
|
||||
ob_act, objects = objects[0], [ob_act]
|
||||
|
||||
@ -429,11 +474,14 @@ class JoinUVs(bpy.types.Operator):
|
||||
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
||||
|
||||
if not mesh.uv_textures:
|
||||
self.report({'WARNING'}, "Object: %s, Mesh: '%s' has no UVs\n" % (obj.name, mesh.name))
|
||||
self.report({'WARNING'},
|
||||
"Object: %s, Mesh: '%s' has no UVs"
|
||||
% (obj.name, mesh.name))
|
||||
else:
|
||||
len_faces = len(mesh.faces)
|
||||
|
||||
uv_array = array.array('f', [0.0] * 8) * len_faces # seems to be the fastest way to create an array
|
||||
# seems to be the fastest way to create an array
|
||||
uv_array = array.array('f', [0.0] * 8) * len_faces
|
||||
mesh.uv_textures.active.data.foreach_get("uv_raw", uv_array)
|
||||
|
||||
objects = context.selected_editable_objects[:]
|
||||
@ -454,7 +502,8 @@ class JoinUVs(bpy.types.Operator):
|
||||
else:
|
||||
uv_other = mesh_other.uv_textures.active
|
||||
if not uv_other:
|
||||
uv_other = mesh_other.uv_textures.new() # should return the texture it adds
|
||||
# should return the texture it adds
|
||||
uv_other = mesh_other.uv_textures.new()
|
||||
|
||||
# finally do the copy
|
||||
uv_other.data.foreach_set("uv_raw", uv_array)
|
||||
@ -482,7 +531,11 @@ class MakeDupliFace(bpy.types.Operator):
|
||||
|
||||
SCALE_FAC = 0.01
|
||||
offset = 0.5 * SCALE_FAC
|
||||
base_tri = Vector((-offset, -offset, 0.0)), Vector((offset, -offset, 0.0)), Vector((offset, offset, 0.0)), Vector((-offset, offset, 0.0))
|
||||
base_tri = (Vector((-offset, -offset, 0.0)),
|
||||
Vector((+offset, -offset, 0.0)),
|
||||
Vector((+offset, +offset, 0.0)),
|
||||
Vector((-offset, +offset, 0.0)),
|
||||
)
|
||||
|
||||
def matrix_to_quat(matrix):
|
||||
# scale = matrix.median_scale
|
||||
@ -498,7 +551,10 @@ class MakeDupliFace(bpy.types.Operator):
|
||||
linked.setdefault(data, []).append(obj)
|
||||
|
||||
for data, objects in linked.items():
|
||||
face_verts = [axis for obj in objects for v in matrix_to_quat(obj.matrix_world) for axis in v]
|
||||
face_verts = [axis for obj in objects
|
||||
for v in matrix_to_quat(obj.matrix_world)
|
||||
for axis in v]
|
||||
|
||||
faces = list(range(len(face_verts) // 3))
|
||||
|
||||
mesh = bpy.data.meshes.new(data.name + "_dupli")
|
||||
@ -535,7 +591,8 @@ class MakeDupliFace(bpy.types.Operator):
|
||||
|
||||
|
||||
class IsolateTypeRender(bpy.types.Operator):
|
||||
'''Hide unselected render objects of same type as active by setting the hide render flag'''
|
||||
'''Hide unselected render objects of same type as active ''' \
|
||||
'''by setting the hide render flag'''
|
||||
bl_idname = "object.isolate_type_render"
|
||||
bl_label = "Restrict Render Unselected"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
@ -16,102 +16,107 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
from mathutils import Vector
|
||||
|
||||
def GlobalBB_LQ(bb_world):
|
||||
|
||||
|
||||
# Initialize the variables with the 8th vertex
|
||||
left, right, front, back, down, up =\
|
||||
bb_world[7][0],\
|
||||
bb_world[7][0],\
|
||||
bb_world[7][1],\
|
||||
bb_world[7][1],\
|
||||
bb_world[7][2],\
|
||||
bb_world[7][2]
|
||||
|
||||
left, right, front, back, down, up = (bb_world[7][0],
|
||||
bb_world[7][0],
|
||||
bb_world[7][1],
|
||||
bb_world[7][1],
|
||||
bb_world[7][2],
|
||||
bb_world[7][2],
|
||||
)
|
||||
|
||||
# Test against the other 7 verts
|
||||
for i in range (7):
|
||||
|
||||
|
||||
# X Range
|
||||
val = bb_world[i][0]
|
||||
if val < left:
|
||||
left = val
|
||||
|
||||
|
||||
if val > right:
|
||||
right = val
|
||||
|
||||
|
||||
# Y Range
|
||||
val = bb_world[i][1]
|
||||
if val < front:
|
||||
front = val
|
||||
|
||||
|
||||
if val > back:
|
||||
back = val
|
||||
|
||||
|
||||
# Z Range
|
||||
val = bb_world[i][2]
|
||||
if val < down:
|
||||
down = val
|
||||
|
||||
|
||||
if val > up:
|
||||
up = val
|
||||
|
||||
|
||||
return (Vector((left, front, up)), Vector((right, back, down)))
|
||||
|
||||
def GlobalBB_HQ(obj):
|
||||
|
||||
|
||||
matrix_world = obj.matrix_world.copy()
|
||||
|
||||
|
||||
# Initialize the variables with the last vertex
|
||||
|
||||
|
||||
verts = obj.data.vertices
|
||||
|
||||
|
||||
val = verts[-1].co * matrix_world
|
||||
|
||||
left, right, front, back, down, up =\
|
||||
val[0],\
|
||||
val[0],\
|
||||
val[1],\
|
||||
val[1],\
|
||||
val[2],\
|
||||
val[2]
|
||||
|
||||
|
||||
left, right, front, back, down, up = (val[0],
|
||||
val[0],
|
||||
val[1],
|
||||
val[1],
|
||||
val[2],
|
||||
val[2],
|
||||
)
|
||||
|
||||
# Test against all other verts
|
||||
for i in range (len(verts)-1):
|
||||
|
||||
|
||||
vco = verts[i].co * matrix_world
|
||||
|
||||
|
||||
# X Range
|
||||
val = vco[0]
|
||||
if val < left:
|
||||
left = val
|
||||
|
||||
|
||||
if val > right:
|
||||
right = val
|
||||
|
||||
|
||||
# Y Range
|
||||
val = vco[1]
|
||||
if val < front:
|
||||
front = val
|
||||
|
||||
|
||||
if val > back:
|
||||
back = val
|
||||
|
||||
|
||||
# Z Range
|
||||
val = vco[2]
|
||||
if val < down:
|
||||
down = val
|
||||
|
||||
|
||||
if val > up:
|
||||
up = val
|
||||
|
||||
return (Vector((left, front, up)), Vector((right, back, down)))
|
||||
|
||||
return Vector((left, front, up)), Vector((right, back, down))
|
||||
|
||||
|
||||
def align_objects(align_x, align_y, align_z, align_mode, relative_to, bb_quality):
|
||||
def align_objects(align_x,
|
||||
align_y,
|
||||
align_z,
|
||||
align_mode,
|
||||
relative_to,
|
||||
bb_quality):
|
||||
|
||||
cursor = bpy.context.scene.cursor_location
|
||||
|
||||
@ -131,12 +136,12 @@ def align_objects(align_x, align_y, align_z, align_mode, relative_to, bb_quality
|
||||
return False
|
||||
|
||||
for obj, bb_world in objs:
|
||||
|
||||
|
||||
if bb_quality:
|
||||
GBB = GlobalBB_HQ(obj)
|
||||
else:
|
||||
GBB = GlobalBB_LQ(bb_world)
|
||||
|
||||
|
||||
Left_Front_Up = GBB[0]
|
||||
Right_Back_Down = GBB[1]
|
||||
|
||||
@ -194,12 +199,12 @@ def align_objects(align_x, align_y, align_z, align_mode, relative_to, bb_quality
|
||||
|
||||
for obj, bb_world in objs:
|
||||
bb_world = [Vector(v[:]) * obj.matrix_world for v in obj.bound_box]
|
||||
|
||||
|
||||
if bb_quality:
|
||||
GBB = GlobalBB_HQ(obj)
|
||||
else:
|
||||
GBB = GlobalBB_LQ(bb_world)
|
||||
|
||||
|
||||
Left_Front_Up = GBB[0]
|
||||
Right_Back_Down = GBB[1]
|
||||
|
||||
@ -339,7 +344,9 @@ class AlignObjects(bpy.types.Operator):
|
||||
|
||||
bb_quality = BoolProperty(
|
||||
name="High Quality",
|
||||
description="Enables high quality calculation of the bounding box for perfect results on complex shape meshes with rotation/scale (Slow)",
|
||||
description=("Enables high quality calculation of the "
|
||||
"bounding box for perfect results on complex "
|
||||
"shape meshes with rotation/scale (Slow)"),
|
||||
default=True)
|
||||
|
||||
align_mode = EnumProperty(items=(
|
||||
@ -374,7 +381,12 @@ class AlignObjects(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
align_axis = self.align_axis
|
||||
ret = align_objects('X' in align_axis, 'Y' in align_axis, 'Z' in align_axis, self.align_mode, self.relative_to, self.bb_quality)
|
||||
ret = align_objects('X' in align_axis,
|
||||
'Y' in align_axis,
|
||||
'Z' in align_axis,
|
||||
self.align_mode,
|
||||
self.relative_to,
|
||||
self.bb_quality)
|
||||
|
||||
if not ret:
|
||||
self.report({'WARNING'}, "No objects with bound-box selected")
|
||||
|
@ -16,7 +16,7 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
@ -93,40 +93,69 @@ class RandomizeLocRotSize(bpy.types.Operator):
|
||||
bl_label = "Randomize Transform"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
random_seed = IntProperty(name="Random Seed",
|
||||
description="Seed value for the random generator",
|
||||
default=0, min=0, max=1000)
|
||||
|
||||
use_delta = BoolProperty(name="Transform Delta",
|
||||
description="Randomize delta transform values instead of regular transform", default=False)
|
||||
|
||||
use_loc = BoolProperty(name="Randomize Location",
|
||||
description="Randomize the location values", default=True)
|
||||
|
||||
loc = FloatVectorProperty(name="Location",
|
||||
description="Maximun distance the objects can spread over each axis",
|
||||
default=(0.0, 0.0, 0.0), min=-100.0, max=100.0, subtype='TRANSLATION')
|
||||
|
||||
use_rot = BoolProperty(name="Randomize Rotation",
|
||||
description="Randomize the rotation values", default=True)
|
||||
|
||||
rot = FloatVectorProperty(name="Rotation",
|
||||
description="Maximun rotation over each axis",
|
||||
default=(0.0, 0.0, 0.0), min=-180.0, max=180.0, subtype='TRANSLATION')
|
||||
|
||||
use_scale = BoolProperty(name="Randomize Scale",
|
||||
description="Randomize the scale values", default=True)
|
||||
|
||||
scale_even = BoolProperty(name="Scale Even",
|
||||
description="Use the same scale value for all axis", default=False)
|
||||
random_seed = IntProperty(
|
||||
name="Random Seed",
|
||||
description="Seed value for the random generator",
|
||||
min=0,
|
||||
max=1000,
|
||||
default=0,
|
||||
)
|
||||
use_delta = BoolProperty(
|
||||
name="Transform Delta",
|
||||
description=("Randomize delta transform values "
|
||||
"instead of regular transform"),
|
||||
default=False,
|
||||
)
|
||||
use_loc = BoolProperty(
|
||||
name="Randomize Location",
|
||||
description="Randomize the location values",
|
||||
default=True,
|
||||
)
|
||||
loc = FloatVectorProperty(
|
||||
name="Location",
|
||||
description=("Maximun distance the objects "
|
||||
"can spread over each axis"),
|
||||
min=-100.0,
|
||||
max=100.0,
|
||||
default=(0.0, 0.0, 0.0),
|
||||
subtype='TRANSLATION',
|
||||
)
|
||||
use_rot = BoolProperty(
|
||||
name="Randomize Rotation",
|
||||
description="Randomize the rotation values",
|
||||
default=True,
|
||||
)
|
||||
rot = FloatVectorProperty(
|
||||
name="Rotation",
|
||||
description="Maximun rotation over each axis",
|
||||
min=-180.0,
|
||||
max=180.0,
|
||||
default=(0.0, 0.0, 0.0),
|
||||
subtype='TRANSLATION',
|
||||
)
|
||||
use_scale = BoolProperty(
|
||||
name="Randomize Scale",
|
||||
description="Randomize the scale values",
|
||||
default=True,
|
||||
)
|
||||
scale_even = BoolProperty(
|
||||
name="Scale Even",
|
||||
description="Use the same scale value for all axis",
|
||||
default=False,
|
||||
)
|
||||
|
||||
'''scale_min = FloatProperty(name="Minimun Scale Factor",
|
||||
description="Lowest scale percentage possible",
|
||||
default=0.15, min=-1.0, max=1.0, precision=3)'''
|
||||
|
||||
scale = FloatVectorProperty(name="Scale",
|
||||
description="Maximum scale randomization over each axis",
|
||||
default=(0.0, 0.0, 0.0), min=-100.0, max=100.0, subtype='TRANSLATION')
|
||||
scale = FloatVectorProperty(
|
||||
name="Scale",
|
||||
description="Maximum scale randomization over each axis",
|
||||
min=-100.0,
|
||||
max=100.0,
|
||||
default=(0.0, 0.0, 0.0),
|
||||
subtype='TRANSLATION',
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
from math import radians
|
||||
|
@ -16,7 +16,7 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
@ -30,8 +30,15 @@ class AddPresetBase():
|
||||
# bl_label = "Add a Python Preset"
|
||||
bl_options = {'REGISTER'} # only because invoke_props_popup requires.
|
||||
|
||||
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="")
|
||||
remove_active = bpy.props.BoolProperty(default=False, options={'HIDDEN'})
|
||||
name = bpy.props.StringProperty(
|
||||
name="Name",
|
||||
description="Name of the preset, used to make the path name",
|
||||
maxlen=64,
|
||||
)
|
||||
remove_active = bpy.props.BoolProperty(
|
||||
default=False,
|
||||
options={'HIDDEN'},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def as_filename(name): # could reuse for other presets
|
||||
@ -54,7 +61,10 @@ class AddPresetBase():
|
||||
|
||||
filename = self.as_filename(name)
|
||||
|
||||
target_path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", self.preset_subdir), create=True)
|
||||
target_path = os.path.join("presets", self.preset_subdir)
|
||||
target_path = bpy.utils.user_resource('SCRIPTS',
|
||||
target_path,
|
||||
create=True)
|
||||
|
||||
if not target_path:
|
||||
self.report({'WARNING'}, "Failed to create presets path")
|
||||
@ -95,7 +105,9 @@ class AddPresetBase():
|
||||
filepath = bpy.utils.preset_find(preset_active, self.preset_subdir)
|
||||
|
||||
if not filepath:
|
||||
filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True)
|
||||
filepath = bpy.utils.preset_find(preset_active,
|
||||
self.preset_subdir,
|
||||
display_name=True)
|
||||
|
||||
if not filepath:
|
||||
return {'CANCELLED'}
|
||||
@ -133,8 +145,15 @@ class ExecutePreset(bpy.types.Operator):
|
||||
bl_idname = "script.execute_preset"
|
||||
bl_label = "Execute a Python Preset"
|
||||
|
||||
filepath = bpy.props.StringProperty(name="Path", description="Path of the Python file to execute", maxlen=512, default="")
|
||||
menu_idname = bpy.props.StringProperty(name="Menu ID Name", description="ID name of the menu this was called from", default="")
|
||||
filepath = bpy.props.StringProperty(
|
||||
name="Path",
|
||||
description="Path of the Python file to execute",
|
||||
maxlen=512,
|
||||
)
|
||||
menu_idname = bpy.props.StringProperty(
|
||||
name="Menu ID Name",
|
||||
description="ID name of the menu this was called from",
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
from os.path import basename
|
||||
@ -182,7 +201,10 @@ class AddPresetSSS(AddPresetBase, bpy.types.Operator):
|
||||
preset_menu = "MATERIAL_MT_sss_presets"
|
||||
|
||||
preset_defines = [
|
||||
"material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material)"
|
||||
("material = "
|
||||
"bpy.context.material.active_node_material "
|
||||
"if bpy.context.material.active_node_material "
|
||||
"else bpy.context.material")
|
||||
]
|
||||
|
||||
preset_values = [
|
||||
@ -306,7 +328,11 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
|
||||
bl_label = "Operator Preset"
|
||||
preset_menu = "WM_MT_operator_presets"
|
||||
|
||||
operator = bpy.props.StringProperty(name="Operator", maxlen=64, options={'HIDDEN'})
|
||||
operator = bpy.props.StringProperty(
|
||||
name="Operator",
|
||||
maxlen=64,
|
||||
options={'HIDDEN'},
|
||||
)
|
||||
|
||||
# XXX, not ideal
|
||||
preset_defines = [
|
||||
@ -322,12 +348,15 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
|
||||
properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
|
||||
|
||||
prefix, suffix = self.operator.split("_OT_", 1)
|
||||
operator_rna = getattr(getattr(bpy.ops, prefix.lower()), suffix).get_rna().bl_rna
|
||||
op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
|
||||
operator_rna = op.get_rna().bl_rna
|
||||
del op
|
||||
|
||||
ret = []
|
||||
for prop_id, prop in operator_rna.properties.items():
|
||||
if (not (prop.is_hidden or prop.is_skip_save)) and prop_id not in properties_blacklist:
|
||||
ret.append("op.%s" % prop_id)
|
||||
if not (prop.is_hidden or prop.is_skip_save):
|
||||
if prop_id not in properties_blacklist:
|
||||
ret.append("op.%s" % prop_id)
|
||||
|
||||
return ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user