我有一个关于我在Blender中使用的Python类的问题。基本上,我想知道类是如何工作的,因为有些属性是在我没有特别编写self.value = something
的情况下记录的。代码如下:
class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Save/Load animation"
saving = bpy.props.BoolProperty(name="Save ? Else load.")
path_to_anim = bpy.props.StringProperty(name="Path to folder")
anim_name = bpy.props.StringProperty(name="Animation name:")
# path_to_anim += "/home/mehdi/Blender/Scripts/"
def execute(self, context):
# print('This is execute with: Saving: {} Name:{}'.format(self.saving, self.path_to_anim))
if self.saving:
self.launch_save()
message = 'Animation {} saved at {}'.format(self.anim_name, self.path_to_anim)
else:
self.launch_load()
message = 'Animation {} loaded'.format(self.anim_name)
self.report({'INFO'}, message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def launch_load(self):
full_path = self.path_to_anim + self.anim_name
target_armature = Humanoid(bpy.data.objects['Armature'])
load_all(full_path, target_armature, 'LastLoaded')
def launch_save(self):
full_path = self.path_to_anim + self.anim_name
source_armature = Humanoid(bpy.data.objects['Armature'])
curves = source_armature.get_curves()
save_all(curves, source_armature,full_path)
现在,为什么saving
、path_to_anim
和anim_name
被认为是属性(我可以在execute()
和launch()
中调用它们),即使我没有编写self.saving = saving
谢谢
这是因为
saving
、path_to_anim
和anim_name
是类属性。它们是为类而不是为特定实例定义的。它们在实例之间共享。下面是进一步解释class-instance-attributes-python的链接相关问题 更多 >
编程相关推荐