目标

  • [x] 总结Blender插件之属性bpy.props

总结

bpy.props

bpy.props模块用来扩展Blender内置数据的属性. 这些函数的结果用于为用Blender注册的类分配属性,不能直接使用。

  • bpy.props.BoolProperty()
  • bpy.props.BoolVectorProperty
  • bpy.props.FloatProperty
  • bpy.props.FloatVectorProperty
  • bpy.props.IntProperty
  • bpy.props.IntVectorProperty
  • bpy.props.StringProperty
  • bpy.props.CollectionProperty
  • bpy.props.EnumProperty
  • bpy.props.PointerProperty
  • bpy.props.RemoveProperty

分配给现有类

自定义属性可以被添加到ID、Bone和PoseBone的任何子类中。

import bpy

# Assign a custom property to an existing type.
bpy.types.Material.custom_float = bpy.props.FloatProperty(name="Test Prob") # Test the property is there.
bpy.data.materials[0].custom_float = 5.0

操作器示例

import bpy

class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Property Example" my_float = bpy.props.FloatProperty(name="Some Floating Point")
my_bool = bpy.props.BoolProperty(name="Toggle Option")
my_string = bpy.props.StringProperty(name="String Value") def execute(self, context):
print("Dialog Runs")
return {'FINISHED'} def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self) bpy.utils.register_class(DialogOperator) # test call
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')

PropertyGroup示例

import bpy

class MaterialSettings(bpy.types.PropertyGroup):
my_int = bpy.props.IntProperty()
my_float = bpy.props.FloatProperty()
my_string = bpy.props.StringProperty() bpy.utils.register_class(MaterialSettings) bpy.types.Material.my_settings = \
bpy.props.PointerProperty(type=MaterialSettings) # test the new settings work
material = bpy.data.materials[0] material.my_settings.my_int = 5
material.my_settings.my_float = 3.0
material.my_settings.my_string = "Foo"

Collection示例

import bpy

# Assign a collection
class SceneSettingItem(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
value = bpy.props.IntProperty(name="Test Prop", default=22) bpy.utils.register_class(SceneSettingItem) bpy.types.Scene.my_settings = \
bpy.props.CollectionProperty(type=SceneSettingItem) # Assume an armature object selected
print("Adding 2 values!") my_item = bpy.context.scene.my_settings.add()
my_item.name = "Spam"
my_item.value = 1000 my_item = bpy.context.scene.my_settings.add()
my_item.name = "Eggs"
my_item.value = 30 for my_item in bpy.context.scene.my_settings:
print(my_item.name, my_item.value)

Blender之Property的更多相关文章

  1. Blender插件编写指南

    前言 Blender插件是Blender的利器, 用户可以使用各种插件扩充Blender的功能. Blender Python插件以bpy.props, bpy.types.Operator, bpy ...

  2. Blender 之修改器代码分析

                           Blender的修改器(modifier)模块,默认界面右下块(Property)面板的扳手,分类(修改.生成.形变.模拟)列出所有的修改器.也可以空格键 ...

  3. 探究@property申明对象属性时copy与strong的区别

    一.问题来源 一直没有搞清楚NSString.NSArray.NSDictionary--属性描述关键字copy和strong的区别,看别人的项目中属性定义有的用copy,有的用strong.自己在开 ...

  4. JavaScript特性(attribute)、属性(property)和样式(style)

    最近在研读一本巨著<JavaScript忍者秘籍>,里面有一篇文章提到了这3个概念. 书中的源码可以在此下载.我将源码放到了线上,如果不想下载,可以直接访问在线网址,修改页面名就能访问到相 ...

  5. -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HO 解决办法

    最近在使用maven,项目测试的时候出现了这么一个错.-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2 ...

  6. python property理解

    一般情况下我这样使用property: @property def foo(self): return self._foo # 下面的两个decrator由@property创建 @foo.sette ...

  7. Android动画效果之Property Animation进阶(属性动画)

    前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...

  8. Android动画效果之初识Property Animation(属性动画)

    前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...

  9. # ios开发 @property 和 Ivar 的区别

    ios开发 @property 和 Ivar 的区别 @property 属性其实是对成员变量的一种封装.我们先大概这样理解: @property = Ivar + setter + getter I ...

随机推荐

  1. centos7安装个人网盘owncloud

    现在个人资料越来越重要,网络速度也已经满足日常需要,网盘已经是生活着存取个人数据不可缺少的工具. 下面在linxu centos7下面安装owncloud搭建自己私人网盘: 1.新建一个账号用来安装个 ...

  2. jquery 实现 单选框点击取消

    <label for="1" class="z-label"> <input type="radio" class=&qu ...

  3. copy.c实现

    #cat copy.c #include <stdio.h> #include <stdlib.h> #include <string.h> int copyFil ...

  4. 使用PHP操作MongoDB数据库

    1.连接MongoDB数据库(在已安装php-mongodb扩展的前提下) $config = "mongodb://{$user}:{$pass}@{$host}:{$port}" ...

  5. 腾讯云&搭建微信小程序服务

    准备域名和证书 任务时间:20min ~ 40min 小程序后台服务需要通过 HTTPS 访问,在实验开始之前,我们要准备域名和 SSL 证书. 域名注册 如果您还没有域名,可以在腾讯云上选购,过程可 ...

  6. PAT 1105 Spiral Matrix

    This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasi ...

  7. Django——2 路由分配设置 re_path正则匹配 include总路由 url传参 name使用 模板渲染render方法 模板渲染方法

    Django 路由分配设置 re_path正则匹配 include总路由设置 url额外参数的传递 name的使用 模板的渲染:render方法   路由的分配中, 可以设定相应的转换器加以约束,比如 ...

  8. 【Codeforces 1106B】Lunar New Year and Food Ordering

    [链接] 我是链接,点我呀:) [题意] 给你n个菜以及每个人需要的菜以及数量 如果某个人无法满足它对菜的需求的话 就用价格比较低的菜来填充它的要求. (如果价格低的菜不够了,那么就直接输出0) 否则 ...

  9. 利用fontforge制作自己的字体

    最近手伤了,写代码特别慢,索性就干干一些奇奇怪怪的事情. 发现我电脑上的中文字体很是奇怪,于是便去找了中英混合的等宽字体. 满足条件的只找到了YaHei Consolas Hybrid,是微软的Con ...

  10. jQuery WEI----DIV+CSS样式li自动适应高度,自动换行,横向排列

    设置相关样式即可,按照需求自己修改样式,Demo代码如下: <li style="display:inline;;line-height:24px;height:auto;word-b ...