level 6
mobilefzb
楼主
blender的脚本代码中,全局变量没有作用
本来想着在类之间进行数据传递的,但是似乎不行,即使是从bpy.context.active_object中取得的顶点数据,只要跳出一个函数那么它就被销毁了,一直没有找到传递数据的接口。
这段代码中vert_x的值是不会变化的,即使在创建面板的时候进行了改变。
vert_x = 0.0;
class VertexAlignSmoothFirstOperator(bpy.types.Operator):
"""hope to become a extend way of blender verties process tool
you can use it to mark a vertex as first to make all others
align to it"""
bl_idname = "object.vertex_align_smooth_first_operator";
bl_label = "Vertex Align Smooth First Operator";
@classmethod
def poll(self,context):
if context.active_object is not None :
obj = context.active_object;
if obj.mode == 'EDIT':
return True;
else :
return False;
def execute(self,context):
print(vert_x);
return {'FINISHED'};
class VertexAlignMergePanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_idname = "panel_vertex_align_merge";
bl_label = "Verties Align Merge Panel";
bl_space_type = "PROPERTIES";
bl_region_type = "WINDOW";
bl_context = "object";
def draw(self,context):
layout = self.layout;
vert_x = 1.2;
row = layout.row();
row.operator("object.vertex_align_smooth_first_operator","mark current vertex as first");
def register():
#align oprators
bpy.utils.register_class(VertexAlignSmoothFirstOperator);
#work panel
bpy.utils.register_class(VertexAlignMergePanel);
def unregister():
bpy.utils.unregister_class(VertexAlignSmoothFirstOperator);
bpy.utils.unregister_class(VertexAlignMergePanel);
if __name__ == "__main__":
register();
2014年01月14日 12点01分
1
本来想着在类之间进行数据传递的,但是似乎不行,即使是从bpy.context.active_object中取得的顶点数据,只要跳出一个函数那么它就被销毁了,一直没有找到传递数据的接口。
这段代码中vert_x的值是不会变化的,即使在创建面板的时候进行了改变。
vert_x = 0.0;
class VertexAlignSmoothFirstOperator(bpy.types.Operator):
"""hope to become a extend way of blender verties process tool
you can use it to mark a vertex as first to make all others
align to it"""
bl_idname = "object.vertex_align_smooth_first_operator";
bl_label = "Vertex Align Smooth First Operator";
@classmethod
def poll(self,context):
if context.active_object is not None :
obj = context.active_object;
if obj.mode == 'EDIT':
return True;
else :
return False;
def execute(self,context):
print(vert_x);
return {'FINISHED'};
class VertexAlignMergePanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_idname = "panel_vertex_align_merge";
bl_label = "Verties Align Merge Panel";
bl_space_type = "PROPERTIES";
bl_region_type = "WINDOW";
bl_context = "object";
def draw(self,context):
layout = self.layout;
vert_x = 1.2;
row = layout.row();
row.operator("object.vertex_align_smooth_first_operator","mark current vertex as first");
def register():
#align oprators
bpy.utils.register_class(VertexAlignSmoothFirstOperator);
#work panel
bpy.utils.register_class(VertexAlignMergePanel);
def unregister():
bpy.utils.unregister_class(VertexAlignSmoothFirstOperator);
bpy.utils.unregister_class(VertexAlignMergePanel);
if __name__ == "__main__":
register();