BlenderCN论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1045|回复: 2

请教一个创建界面的问题

[复制链接]
发表于 2014-3-16 23:41:32 | 显示全部楼层 |阅读模式
  1. # 创建Panel

  2. #必要模块引用
  3. import bpy
  4. # from math import radians #degrees #, sqrt
  5. from math import pi
  6. import mathutils
  7. # from mathutils import Vector
  8. from bpy.props import EnumProperty, BoolProperty, IntProperty, FloatVectorProperty


  9. class MyTool(bpy.types.Panel):
  10.     """Creates a Panel in the Object properties window"""
  11.     bl_label = "My Tools"
  12.     bl_idname = "OBJECT_PT_hello"
  13.     bl_space_type = 'PROPERTIES'
  14.     bl_region_type = 'WINDOW'
  15.     bl_context = "object"

  16.     advanced = BoolProperty (name = "Advanced Options", default = False, description = "Show advanced options")
  17.     subject = EnumProperty (items=(("0", "Object", "Align Objects"), ("1", "Pivot", "Align Objects Pivot"), ("2", "Cursor", "Align Cursor To Active")), name = "Align To", description = "What will be moved")

  18.     def draw(self, context):
  19.         layout = self.layout

  20.         obj = context.object

  21.         row = layout.row()
  22.         row.operator("mesh.primitive_plane_add")

  23.         row = layout.row()
  24.         row.label(text="Active object is: " + obj.name)
  25.         row = layout.row()
  26.         row.prop(obj, "name")

  27.         row0 = layout.row()
  28.         row0.prop(self, 'subject', expand =True)
  29.         row1 = layout.row()
  30.         row1.prop(self, 'advanced')


  31. def register():
  32.     bpy.utils.register_class(MyTool)

  33. def unregister():
  34.     bpy.utils.unregister_class(MyTool)

  35. if __name__ == "__main__":
  36.     register()
复制代码
为什么创建不了advanced和subject这两个选择控件,怎样才能让它们显示出来
发表于 2014-3-21 11:30:06 | 显示全部楼层
panel 不能包含自定义的变量,如果是一个点击动作激发的事物因该属于一个operate,哪怕只是一个值的变化。
回复 支持 反对

使用道具 举报

发表于 2014-3-21 13:31:34 | 显示全部楼层
本帖最后由 imdjs 于 2014-3-21 13:51 编辑

这样写应该就可以了,把advanced 与subject 添加到Scene或其它物体的属性。
row.operator("mesh.primitive_plane_add")这句其实也是可以的,不过通常情况是把function 绑定到Operator类 再把类id添加到panel。
m.jpg


  1. bl_info = {
  2.     "name": "MyTool",
  3.     "author": "---",
  4.     "version": (1, '1'),
  5.     "blender": (2, 60, 0),
  6.     "location": "View3D > Mesh Object > Properties >MyTool",
  7.     "description": "MyTool",
  8.     "wiki_url": "",
  9.     "tracker_url": "",
  10.     "category": "Object"
  11. }
  12. # 创建Panel
  13. #必要模块引用
  14. import bpy
  15. # from math import radians #degrees #, sqrt
  16. from math import pi
  17. import mathutils
  18. # from mathutils import Vector
  19. from bpy.props import EnumProperty, BoolProperty, IntProperty, FloatVectorProperty

  20. class MyTool(bpy.types.Panel):
  21.     """Creates a Panel in the Object properties window"""
  22.     bl_label = "My Tools"
  23.     bl_idname = "OBJECT_PT_hello"
  24.     bl_space_type = 'PROPERTIES'
  25.     bl_region_type = 'WINDOW'
  26.     bl_context = "object"
  27.     @classmethod
  28.     def poll(cls, context):
  29.         return True ;
  30.         
  31.     def draw(self, context):
  32.         layout = self.layout
  33.         obj = context.object
  34.         row = layout.row()
  35.         row.operator("mesh.primitive_plane_add")
  36.         row = layout.row()
  37.         row.label(text="Active object is: " + obj.name)
  38.         row = layout.row()
  39.         row.prop(obj, "name")
  40.         row0 = layout.row()
  41.         row0.prop(context.scene, 'subject', expand =True)
  42.         row1 = layout.row()
  43.         row1.prop(context.scene, 'advanced')

  44. def register():
  45.     bpy.utils.register_class(MyTool)
  46.    
  47.     bpy.types.Scene.advanced = BoolProperty (name = "Advanced Options", default = False, description = "Show advanced options")
  48.     bpy.types.Scene.subject = EnumProperty (items=(("0", "Object", "Align Objects"), ("1", "Pivot", "Align Objects Pivot"), ("2", "Cursor", "Align Cursor To Active")), name = "Align To", description = "What will be moved")
  49. def unregister():
  50.     bpy.utils.unregister_class(MyTool)
  51.     del bpy.types.Scene.advanced;
  52.     del bpy.types.Scene.subject;
  53. if __name__ == "__main__":
  54.     register()

复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Blender最新中文教学视频|Blender头条|小黑屋|手机版|Archiver|Blender中国 ( 蜀ICP备17002929号 )360网站安全检测平台

GMT+8, 2019-12-12 05:44 , Processed in 0.016487 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表