def move_verts(self,obj,ratio_x,ratio_y):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.reveal()
bpy.ops.object.mode_set(mode="OBJECT")
data = obj.data.vertices
if obj.data.shape_keys != None:
data = obj.data.shape_keys.key_blocks[0].data
for vert in data:
co_x = vert.co[0] * ratio_x
co_y = vert.co[2] * ratio_y
vert.co = Vector((co_x,0,co_y))
obj.coa_sprite_dimension = Vector((get_local_dimension(obj)[0],0,get_local_dimension(obj)[1]))
obj.coa_tiles_x = self.tiles_x
obj.coa_tiles_y = self.tiles_y
python类data()的实例源码
idproperty.py 文件源码
项目:Blender-WMO-import-export-scripts
作者: WowDevTools
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def layout_id_prop(layout, data, prop):
prop_obj = data.bl_rna.properties[prop]
prop_name = prop_obj.name
value_key = _create_value_key(prop_name)
ref_id = data.get(value_key, None)
field_name = json.loads(prop_obj.description)["field_name"]
row = layout.row(align=True)
row.prop_search(data, prop, bpy.context.scene, field_name)
if field_name == "objects":
op_props = row.operator("view3d.object_picker_operator", emboss=True, text="", icon="EYEDROPPER")
op_props.to_populate_data = repr(data)
op_props.to_populate_field = prop
op_props = row.operator(FindSelected.bl_idname, emboss=True, icon="VIEWZOOM")
op_props.to_populate_data = repr(data)
op_props.to_populate_field = prop
idproperty.py 文件源码
项目:Blender-WMO-import-export-scripts
作者: WowDevTools
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def create_getter(data_field, value_key):
def fn(self):
data = getattr(bpy.context.scene, data_field)
ob_id = self.get(value_key, None)
id_to_hash = ID_TO_HASH[data_field]
hash_to_name = HASH_TO_NAME[data_field]
ob_hash = id_to_hash.get(ob_id, None)
ob_name = hash_to_name.get(ob_hash, None)
exists = ob_name is not None and ob_name in data
if not exists:
for name, ob in data.items():
if ob_hash == hash(ob):
hash_to_name[ob_hash] = name
ob_name = name
break
if ob_name is None:
ob_name = ""
return ob_name
return fn
def load_text(self, context=None):
if self.text_file in bpy.data.texts:
if self.text_file == 'Text':
self.text_file = ''
return
text = text_remap(self.text_file)
try:
mod = importlib.import_module("svrx.nodes.script.{}".format(text))
importlib.reload(mod)
except Exception as err:
error.show(self, err, script=True)
else:
self.adjust_sockets()
self.color = READY_COLOR
self.use_custom_color = True
else:
pass # fail
def rna_backup_gen(data, include_props=None, exclude_props=None, root=()):
# only writable properties...
for p in data.bl_rna.properties:
pid = p.identifier
if pid in {'rna_type', }:
continue
path = root + (pid,)
if include_props is not None and path not in include_props:
continue
if exclude_props is not None and path in exclude_props:
continue
val = getattr(data, pid)
if val is not None and p.type == 'POINTER':
# recurse!
yield from rna_backup_gen(val, include_props, exclude_props, root=path)
elif data.is_property_readonly(pid):
continue
else:
yield path, val
def do_clear_previews(do_objects, do_groups, do_scenes, do_data_intern):
if do_data_intern:
bpy.ops.wm.previews_clear(id_type=INTERN_PREVIEW_TYPES)
if do_objects:
for ob in ids_nolib(bpy.data.objects):
ob.preview.image_size = (0, 0)
if do_groups:
for grp in ids_nolib(bpy.data.groups):
grp.preview.image_size = (0, 0)
if do_scenes:
for scene in ids_nolib(bpy.data.scenes):
scene.preview.image_size = (0, 0)
print("Saving %s..." % bpy.data.filepath)
bpy.ops.wm.save_mainfile()
def users_id(self):
"""ID data blocks which use this library"""
import bpy
# See: readblenentry.c, IDTYPE_FLAGS_ISLINKABLE,
# we could make this an attribute in rna.
attr_links = ("actions", "armatures", "brushes", "cameras",
"curves", "grease_pencil", "groups", "images",
"lamps", "lattices", "materials", "metaballs",
"meshes", "node_groups", "objects", "scenes",
"sounds", "speakers", "textures", "texts",
"fonts", "worlds")
return tuple(id_block
for attr in attr_links
for id_block in getattr(bpy.data, attr)
if id_block.library == self)
def makePolyLine(objName, curveName, cList):
#objName and curveName are strings cList is a list of vectors
curveData = bpy.data.curves.new(name=curveName, type='CURVE')
curveData.dimensions = '3D'
# objectData = bpy.data.objects.new(objName, curveData)
# objectData.location = (0,0,0) #object origin
# bpy.context.scene.objects.link(objectData)
polyline = curveData.splines.new('BEZIER')
polyline.bezier_points.add(len(cList)-1)
for num in range(len(cList)):
x, y, z = cList[num]
polyline.bezier_points[num].co = (x, y, z)
polyline.bezier_points[num].handle_left_type = polyline.bezier_points[num].handle_right_type = "AUTO"
# return objectData
return curveData
def avail(self,context):
datablock_type = bpy.context.scene.amth_datablock_types
if datablock_type == 'IMAGE_DATA':
where = []
for im in bpy.data.images:
if im.name not in {'Render Result', 'Viewer Node'}:
where.append(im)
elif datablock_type == 'MATERIAL':
where = bpy.data.materials
elif datablock_type == 'GROUP_VCOL':
where = []
for ob in bpy.data.objects:
if ob.type == 'MESH':
for v in ob.data.vertex_colors:
if v and v not in where:
where.append(v)
where = list(set(where))
items = [(str(i),x.name,x.name, datablock_type, i) for i,x in enumerate(where)]
items = sorted(list(set(items)))
return items
def execute(self,context):
datablock_type = bpy.context.scene.amth_datablock_types
if datablock_type == 'IMAGE_DATA':
where = []
for im in bpy.data.images:
if im.name not in {'Render Result', 'Viewer Node'}:
where.append(im)
elif datablock_type == 'MATERIAL':
where = bpy.data.materials
elif datablock_type == 'GROUP_VCOL':
where = []
for ob in bpy.data.objects:
if ob.type == 'MESH':
for v in ob.data.vertex_colors:
if v and v not in where:
where.append(v)
where = list(set(where))
bpy.context.scene.amth_list_users_for_x_name = where[int(self.list_type_select)].name
return {'FINISHED'}
def uptext(text):
source = text.source_text
if source in bpy.data.texts:
r = bpy.data.texts[source].as_string()
else:
r = source
base = len(r)
prog = text.scrambler_progress / 100.0
c = int(base * prog)
clean = r[:base - c]
scrambled = ""
for i in range(c):
scrambled += random.choice(text.characters)
text.body = clean + scrambled
# Typing Text #
def animate_text(scene):
objects = scene.objects
for obj in objects:
if obj.type == "FONT" and "runAnimation" in obj and obj.runAnimation:
endFrame = obj.startFrame + (len(obj.defaultTextBody) * obj.typeSpeed)
if obj.manualEndFrame:
endFrame = obj.endFrame
if scene.frame_current < obj.startFrame:
obj.data.body = ""
elif scene.frame_current >= obj.startFrame and scene.frame_current <= endFrame:
frameStringLength = (scene.frame_current - obj.startFrame) / obj.typeSpeed
obj.data.body = obj.defaultTextBody[0:int(frameStringLength)]
elif scene.frame_current > endFrame:
obj.data.body = obj.defaultTextBody
# Typewriter #
def draw(self, context):
layout = self.layout
layout.operator("mocap.samples", text='Samples to Beziers')
layout.operator('mocap.pathediting', text="Follow Path")
activeIsArmature = isinstance(context.active_object.data, bpy.types.Armature)
if activeIsArmature:
enduser_arm = context.active_object.data
selectBox = layout.box()
selectRetargets = selectBox.row()
selectRetargets.label("Retargeted Animations:")
selectRetargets.prop_search(enduser_arm, "active_mocap", enduser_arm, "mocapNLATracks")
stitchBox = layout.box()
stitchBox.label("Animation Stitching")
settings = enduser_arm.stitch_settings
stitchBox.prop_search(settings, "first_action", enduser_arm, "mocapNLATracks")
stitchBox.prop_search(settings, "second_action", enduser_arm, "mocapNLATracks")
stitchSettings = stitchBox.row()
stitchSettings.prop(settings, "blend_frame")
stitchSettings.prop(settings, "blend_amount")
stitchSettings.prop(settings, "second_offset")
stitchBox.prop_search(settings, "stick_bone", context.active_object.pose, "bones")
stitchBox.operator('mocap.animstitchguess', text="Guess Settings")
stitchBox.operator('mocap.animstitch', text="Stitch Animations")
def execute(self, context):
scene = context.scene
s_frame = scene.frame_start
e_frame = scene.frame_end
enduser_obj = context.active_object
performer_obj = [obj for obj in context.selected_objects if obj != enduser_obj]
if enduser_obj is None or len(performer_obj) != 1:
print("Need active and selected armatures")
else:
performer_obj = performer_obj[0]
s_frame, e_frame = performer_obj.animation_data.action.frame_range
s_frame = int(s_frame)
e_frame = int(e_frame)
if retarget.isRigAdvanced(enduser_obj) and not enduser_obj.data.advancedRetarget:
print("Recommended to use Advanced Retargeting method")
enduser_obj.data.advancedRetarget = True
else:
retarget.totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame)
return {'FINISHED'}
def side(self, nombre, offset):
bpy.ops.object.mode_set(mode="EDIT", toggle=0)
OBJECT = bpy.context.active_object
ODATA = bmesh.from_edit_mesh(OBJECT.data)
bpy.context.tool_settings.mesh_select_mode = (True, False, False)
for VERTICE in ODATA.verts[:]:
VERTICE.select = False
if nombre is False:
for VERTICES in ODATA.verts[:]:
if VERTICES.co[0] < (offset):
VERTICES.select = 1
else:
for VERTICES in ODATA.verts[:]:
if VERTICES.co[0] > (offset):
VERTICES.select = 1
ODATA.select_flush(False)
bpy.ops.object.mode_set(mode="EDIT", toggle=0)
def execute(self, context):
with open("%s_%s_SYM_TEMPLATE.xml" % (os.path.join(os.path.dirname(bpy.data.filepath),
bpy.context.scene.name), bpy.context.object.name)) as file:
ob = bpy.context.object
actgr = ob.vertex_groups.active
actind = ob.vertex_groups.active_index
ls = eval(file.read())
wdict = {left: actgr.weight(right) for left, right in ls.items()
for group in ob.data.vertices[right].groups if group.group == actind}
actgr.remove(
[vert.index for vert in ob.data.vertices if vert.co[0] <= 0])
for ind, weight in wdict.items():
actgr.add([ind], weight, 'REPLACE')
bpy.context.object.data.update()
return {'FINISHED'}
# ------------------------------------ RESYM MESH-------------------------
def SelDoubles(self, context):
bm = bmesh.from_edit_mesh(bpy.context.object.data)
for v in bm.verts:
v.select = 0
dictloc = {}
rd = lambda x: (round(x[0],4),round(x[1],4),round(x[2],4))
for vert in bm.verts:
dictloc.setdefault(rd(vert.co),[]).append(vert.index)
for loc, ind in dictloc.items():
if len(ind) > 1:
for v in ind:
bm.verts[v].select = 1
bpy.context.scene.objects.active = bpy.context.scene.objects.active
def draw(self, context):
layout = self.layout
adv_obj = context.scene.advanced_objects
layout.prop(adv_obj, "arrange_c_use_selected")
if not adv_obj.arrange_c_use_selected:
layout.prop(adv_obj, "arrange_c_select_type", expand=True)
if adv_obj.arrange_c_select_type == 'O':
layout.column(align=True).prop_search(
adv_obj, "arrange_c_obj_arranjar",
bpy.data, "objects"
)
elif adv_obj.arrange_c_select_type == 'G':
layout.column(align=True).prop_search(
adv_obj, "arrange_c_obj_arranjar",
bpy.data, "groups"
)
if context.object.type == 'CURVE':
layout.operator("object.arranjar_numa_curva", text="Arrange Objects")
def check_texture(img, mat):
# finds a texture from an image
# makes a texture if needed
# adds it to the material if it isn't there already
tex = bpy.data.textures.get(img.name)
if tex is None:
tex = bpy.data.textures.new(name=img.name, type='IMAGE')
tex.image = img
# see if the material already uses this tex
# add it if needed
found = False
for m in mat.texture_slots:
if m and m.texture == tex:
found = True
break
if not found and mat:
mtex = mat.texture_slots.add()
mtex.texture = tex
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
def replace_name(self):
# use the chosen material as a base one, check if there is a name
self.check_no_name = (False if self.mat_keep in {""} else True)
if self.check_no_name is True:
for mat in bpy.data.materials:
name = mat.name
if name == self.mat_keep:
try:
base, suffix = name.rsplit('.', 1)
# trigger the exception
num = int(suffix, 10)
self.mat_keep = base
mat.name = self.mat_keep
return
except ValueError:
if name not in self.mat_error:
self.mat_error.append(name)
return
return
def fixup_slot(self, slot):
if not slot.material:
return
base, suffix = self.split_name(slot.material)
if suffix is None:
return
try:
base_mat = bpy.data.materials[base]
except KeyError:
print("\n[Materials Utils Specials]\nLink to base names\nError:"
"Base material %r not found\n" % base)
return
slot.material = base_mat
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
ob = context.object
if (not c_data_has_materials()):
layout.label(text="*No Materials in the data*", icon="INFO")
elif (not ob):
layout.label(text="*No Objects to select*", icon="INFO")
else:
if ob.mode == 'OBJECT':
# show all used materials in entire blend file
for material_name, material in bpy.data.materials.items():
if (material.users > 0):
layout.operator("view3d.select_material_by_name",
text=material_name,
icon='MATERIAL_DATA',
).matname = material_name
elif ob.mode == 'EDIT':
# show only the materials on this object
mats = ob.material_slots.keys()
for m in mats:
layout.operator("view3d.select_material_by_name",
text=m,
icon='MATERIAL_DATA').matname = m
def check_mat_name_unique(name_id="Material_new"):
# check if the new name pattern is in materials' data
name_list = []
suffix = 1
try:
if c_data_has_materials():
name_list = [mat.name for mat in bpy.data.materials if name_id in mat.name]
new_name = "{}_{}".format(name_id, len(name_list) + suffix)
if new_name in name_list:
# KISS failed - numbering is not sequential
# try harvesting numbers in material names, find the rightmost ones
test_num = []
from re import findall
for words in name_list:
test_num.append(findall("\d+", words))
suffix += max([int(l[-1]) for l in test_num])
new_name = "{}_{}".format(name_id, suffix)
return new_name
except Exception as e:
print("\n[Materials Utils Specials]\nfunction: check_mat_name_unique\nError: %s \n" % e)
pass
return name_id
def execute(self, context):
value = self.value
data_path = self.data_path
# match the pointer type from the target property to bpy.data.*
# so we lookup the correct list.
data_path_base, data_path_prop = data_path.rsplit(".", 1)
data_prop_rna = eval("context.%s" % data_path_base).rna_type.properties[data_path_prop]
data_prop_rna_type = data_prop_rna.fixed_type
id_iter = None
for prop in bpy.data.rna_type.properties:
if prop.rna_type.identifier == "CollectionProperty":
if prop.fixed_type == data_prop_rna_type:
id_iter = prop.identifier
break
if id_iter:
value_id = getattr(bpy.data, id_iter).get(value)
exec("context.%s = value_id" % data_path)
return operator_path_undo_return(context, data_path)
def _values_store(self, context):
data_path_iter = self.data_path_iter
data_path_item = self.data_path_item
self._values = values = {}
for item in getattr(context, data_path_iter):
try:
value_orig = eval("item." + data_path_item)
except:
continue
# check this can be set, maybe this is library data.
try:
exec("item.%s = %s" % (data_path_item, value_orig))
except:
continue
values[item] = value_orig
def execute(self, context):
op_strings = []
tot = 0
for op_module_name in dir(bpy.ops):
op_module = getattr(bpy.ops, op_module_name)
for op_submodule_name in dir(op_module):
op = getattr(op_module, op_submodule_name)
text = repr(op)
if text.split("\n")[-1].startswith("bpy.ops."):
op_strings.append(text)
tot += 1
op_strings.append('')
textblock = bpy.data.texts.new("OperatorList.txt")
textblock.write('# %d Operators\n\n' % tot)
textblock.write('\n'.join(op_strings))
self.report({'INFO'}, "See OperatorList.txt textblock")
return {'FINISHED'}
# -----------------------------------------------------------------------------
# Add-on Operators
def prop_search(self, obj, layout, *args, **kwargs):
"""
Resolves and renders a :meth:`bpy.types.UIlayout.prop_search` connected to a registered property
on a GUI :class:`bpy.types.UILayout` object given a
reference to the (correct) object type.
In the example in :class:`PropertyGroupWrapper`:
.. code-block:: python
def draw(context, layout):
global_properties.gui_properties.selected_mesh.prop_search(context.scene, layout,
bpy.data,'objects', icon='VIEWZOOM', text='')
Additional positional arguments and keyword arguments are passed to :meth:`bpy.types.UIlayout.prop`
:param obj: A Blender object with additional properties defined by the wrapper classes.
:param layout: A :class:`bpy.types.UIlayout` reference.
"""
obj = getattr(obj,'RobotDesigner')
for i in self.reference[:-1]:
obj = getattr(obj,i)
layout.prop_search(obj, self.reference[-1], *args, **kwargs)
def draw(self, context):
mesh_type = global_properties.mesh_type.get(context.scene)
hide_bone = global_properties.display_mesh_selection.get(context.scene)
layout = self.layout
current_model = context.active_object
segment_names = [bone.name for bone in current_model.data.bones]
# for bone in sorted(segment_names, key=str.lower):
# x = muscles.SelectSegmentMuscle
# x.segment_name = bone
# layout.operator(x.bl_idname, text=bone).segment_name = bone
for root in [bone.name for bone in current_model.data.bones if bone.parent is None]:
layout.operator(muscles.SelectSegmentMuscle.bl_idname, text=root).segment_name = root
def recursion(children, level=0):
for bone in sorted([bone.name for bone in children], key=str.lower):
text = ' ' * level + '\__ ' + bone
layout.operator(muscles.SelectSegmentMuscle.bl_idname, text=text).segment_name = bone
recursion(current_model.data.bones[bone].children, level + 1)
recursion(current_model.data.bones[root].children)
def putMenu(cls,layout, context, text=None, **kwargs):
hide_obj = cls.show_connected.get(context.scene)
# Get selected meshes
selected = [i for i in bpy.context.selected_objects if i.type == cls.blender_type]
text = cls.text
if len(selected) == 1:
object = selected[0]
if object.parent_bone and not hide_obj == 'disconnected':
text = object.name + " --> " + object.parent_bone
elif not object.parent_bone and not hide_obj == 'connected':
text = object.name
layout.menu(cls.bl_idname, text=text)
row = layout.row(align=True)
cls.show_connected.prop(context.scene, row, expand=True, icon_only=True)
row.separator()
cls.quick_search.prop_search(bpy.context.scene, row,
bpy.data,'objects', icon='VIEWZOOM', text='')
#row.prop_search(bpy.context.scene.RobotEditor, cls.quick_search, bpy.data, 'objects',
# icon='VIEWZOOM', text='')
def draw(self, context):
current_model = context.active_object
layout = self.layout
for root in [bone.name for bone in current_model.data.bones if bone.parent is None]:
layout.operator(segments.SelectSegment.bl_idname, text=root).segment_name = root
def recursion(children, level=0):
for bone in sorted([bone.name for bone in children], key=str.lower):
text = ' ' * level + '\__ ' + bone
layout.operator(segments.SelectSegment.bl_idname, text=text).segment_name = bone
recursion(current_model.data.bones[bone].children, level + 1)
recursion(current_model.data.bones[root].children)