﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Doc%3A2.6%2FManual%2FExtensions%2FPython%2FProperties</id>
	<title>Doc:2.6/Manual/Extensions/Python/Properties - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Doc%3A2.6%2FManual%2FExtensions%2FPython%2FProperties"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Properties&amp;action=history"/>
	<updated>2026-07-12T11:47:22Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Properties&amp;diff=96793&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Properties&amp;diff=96793&amp;oldid=prev"/>
		<updated>2018-06-28T18:47:30Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 18:47時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Properties&amp;diff=96792&amp;oldid=prev</id>
		<title>wiki&gt;Iluvblender: Fixed more broken links</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Properties&amp;diff=96792&amp;oldid=prev"/>
		<updated>2014-03-28T07:39:20Z</updated>

		<summary type="html">&lt;p&gt;Fixed more broken links&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Page/Header||}}&lt;br /&gt;
&lt;br /&gt;
== Properties, ID-Properties and their differences ==&lt;br /&gt;
----&lt;br /&gt;
There are several ways to define custom properties in Blender using Python. One of them is to add a new property to an existing datablock. Another is to define a new ID-property for a datablock. This might seem to be the same, but there are some differences. So when to use what?&lt;br /&gt;
&lt;br /&gt;
This document assumes that the reader has a basic knowledge of Python and Blender. Any code examples can be tested successfully in the default scene. Any user-interface elements that are created will be displayed in the properties sidebar of the 3d-view (toggle with N-key). As they show up at the bottom of this bar, it might be useful to collapse the panels above it (like Transform, View, etc.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Properties ==&lt;br /&gt;
----&lt;br /&gt;
=== Basics ===&lt;br /&gt;
By default these are the normal properties that Blender itself uses. For instance, an object has a [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.types.Object.html#bpy.types.Object.location location] property. This is a vector which contains information on the location of the object. This property can be both read and written. Other properties, like for instance [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.types.Object.html#bpy.types.Object.users users] are read-only.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bpy&lt;br /&gt;
&lt;br /&gt;
ob = bpy.context.active_object  # get the active object&lt;br /&gt;
print(&amp;quot;Location:&amp;quot;, ob.location) # print its location&lt;br /&gt;
ob.location = [1,1,1]           # set it to a new location&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;Users:&amp;quot;, ob.users)       # print its number of users&lt;br /&gt;
#ob.users = 3                   # this will raise an error&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Custom properties ===&lt;br /&gt;
You can also add a new property yourself. The first thing you need to decide is the property type: a boolean, float, string, etc. Here is the [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.props.html full list]. Simply add the new property (a string in this case) by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;bpy.types.Object.myProperty = bpy.props.StringProperty()&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This adds the property &amp;lt;i&amp;gt;myProperty&amp;lt;/i&amp;gt; to all objects.&lt;br /&gt;
&lt;br /&gt;
Once you've added the property you can interact with it just like it were any other normal property.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;ob = bpy.context.active_object      # get the active object&lt;br /&gt;
bpy.types.Object.foo = bpy.props.StringProperty()       # add a new property, called &amp;quot;foo&amp;quot;&lt;br /&gt;
ob.foo = &amp;quot;bar&amp;quot;                      # assign a value to the property&lt;br /&gt;
print(&amp;quot;foo:&amp;quot;, ob.foo)               # prints &amp;quot;foo: bar&amp;quot;&lt;br /&gt;
print(&amp;quot;foo:&amp;quot;, ob['foo'])            # also prints &amp;quot;foo: bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class myPanel(bpy.types.Panel):     # panel to display new property&lt;br /&gt;
    bl_space_type = &amp;quot;VIEW_3D&amp;quot;       # show up in: 3d-window&lt;br /&gt;
    bl_region_type = &amp;quot;UI&amp;quot;           # show up in: properties panel&lt;br /&gt;
    bl_label = &amp;quot;My Panel&amp;quot;           # name of the new panel&lt;br /&gt;
    &lt;br /&gt;
    def draw(self, context):&lt;br /&gt;
        # display value of &amp;quot;foo&amp;quot;, of the active object&lt;br /&gt;
        self.layout.prop(bpy.context.active_object, &amp;quot;foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
bpy.utils.register_class(myPanel)   # register panel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SideNote|1=right|2=Spaces|3=[[image:Blender3D_FreeTip.png|left]]If you have spaces in your property name you can't call it with &amp;lt;i&amp;gt;ob.foo bar&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;Use &amp;lt;i&amp;gt;getattr(ob, &amp;quot;foo bar&amp;quot;)&amp;lt;/i&amp;gt; instead}}&lt;br /&gt;
One thing to keep in mind is that after saving and reloading your blend-file, your new property will have disappeared. So &amp;lt;i&amp;gt;print(ob.foo)&amp;lt;/i&amp;gt; won't work anymore. Any object that had a value assigned to the property will still have it available though, but only as an ID-property. For more information on those, look further down this page.&amp;lt;br&amp;gt;&lt;br /&gt;
To make the values you assigned in a previous session available again, you need to redefine the property. So after reopening the blend-file you need to rerun:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;bpy.types.Object.myProperty = bpy.props.StringProperty()&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will also reassign the values to the property that were assigned to it in a previous session (they are retrieved from the corresponding ID-properties), so you don't need to reassign those. &amp;lt;i&amp;gt;print(ob.foo)&amp;lt;/i&amp;gt; will still return &amp;lt;i&amp;gt;bar&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dynamic custom properties ===&lt;br /&gt;
The previous method will work fine for cases in which you wish to store static information on certain datablocks, but won't be of much help when you want the property to be dynamic. In that case you need to assign a function to the property. The way to do this is to use python's built-in [http://docs.python.org/library/functions.html#property property()] function. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;bpy.types.Lamp.foo = property(bar)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A further difference is that dynamic custom properties aren't stored when saving a blend-file. Not even as an ID-property.&lt;br /&gt;
&lt;br /&gt;
Below is a full example of creating a new dynamic property, called &amp;lt;i&amp;gt;distance&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bpy #needed in a script-text-window!&lt;br /&gt;
def fget(self):                                 # custom get function&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Distance from origin&amp;quot;&amp;quot;&amp;quot;                  # description of property&lt;br /&gt;
    loc = self.location                         # location of object&lt;br /&gt;
    distance = loc.length                       # distance from origin&lt;br /&gt;
    return distance                             # return value&lt;br /&gt;
&lt;br /&gt;
def fset(self, value):                          # custom set function&lt;br /&gt;
    if self.location.length &amp;lt; 1E-6:             # if object is at origin&lt;br /&gt;
        self.location = [1, 0, 0]               # direction to move in&lt;br /&gt;
    self.location.length = value                # set distance from origin&lt;br /&gt;
&lt;br /&gt;
bpy.types.Object.distance = property(fget, fset)# assign function to property&lt;br /&gt;
&lt;br /&gt;
ob = bpy.context.active_object                  # get the active object&lt;br /&gt;
print(ob.distance)                              # print distance to the console&lt;br /&gt;
ob.distance = 2                                 # set the distance&lt;br /&gt;
&lt;br /&gt;
class myPanel(bpy.types.Panel):                 # panel to display new property&lt;br /&gt;
    bl_space_type = &amp;quot;VIEW_3D&amp;quot;                   # show up in: 3d-window&lt;br /&gt;
    bl_region_type = &amp;quot;UI&amp;quot;                       # show up in: properties panel&lt;br /&gt;
    bl_label = &amp;quot;My Panel&amp;quot;                       # name of the new panel&lt;br /&gt;
    &lt;br /&gt;
    def draw(self, context):&lt;br /&gt;
        # display &amp;quot;distance&amp;quot; of the active object&lt;br /&gt;
        self.layout.label(text=str(bpy.context.active_object.distance))&lt;br /&gt;
&lt;br /&gt;
bpy.utils.register_class(myPanel)               # register panel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To have your property available across different blend-files (even after saving and reloading), you'll have to add your property in ../.blender/scripts/modules/bpy_types.py (where .. is the folder in which blender is installed).&lt;br /&gt;
Find the class to which you wish to add your property and simply add the functions that define your property. There are two small differences, concerning the syntax. The first one is the use of a [http://docs.python.org/glossary.html#term-decorator decorator]. The second one (resulting from this) is that the function name is used as the property name.&amp;lt;br&amp;gt;&lt;br /&gt;
Here's the same example as above, but now added to bpy_types.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
@property                           # decorator&lt;br /&gt;
def distance(self):                 # attribute name&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Distance from origin&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    loc = self.location&lt;br /&gt;
    distance = loc.length&lt;br /&gt;
    return distance&lt;br /&gt;
&lt;br /&gt;
@distance.setter                    # decorator&lt;br /&gt;
def distance(self, value):&lt;br /&gt;
    if self.location.length &amp;lt; 1E-6:&lt;br /&gt;
        self.location = [1, 0, 0]&lt;br /&gt;
    self.location.length = value&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ID-Properties ==&lt;br /&gt;
----&lt;br /&gt;
=== Basics ===&lt;br /&gt;
ID-properties are properties that are assigned to individual datablocks. And not just any datablock, but only datablocks that are subclassed from the ID-type. Examples are Lamps, Meshes, Objects and WindowManagers. Look at the [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.types.ID.html  full list] for more information about ID subclasses. &lt;br /&gt;
&lt;br /&gt;
Creating a new ID-property is very easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = bpy.context.active_object  # get the active object&lt;br /&gt;
ob[&amp;quot;foo&amp;quot;] = &amp;quot;bar&amp;quot;               # create and assign an ID-property&lt;br /&gt;
&lt;br /&gt;
print(ob[&amp;quot;foo&amp;quot;])                # prints &amp;quot;bar&amp;quot;&lt;br /&gt;
# print(ob.foo)                 # won't work, as foo isn't an attribute&lt;br /&gt;
print(ob.items())               # prints all ID-properties of ob&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Creating the ID-property and assigning it a value is all done at the same time. The ID-properties are stored as a dictionary on the datablock.&lt;br /&gt;
&lt;br /&gt;
Besides the types of datablocks they can be assigned to, ID-properties have another limitation to be aware of. You can only assign strings, integers, floats, and lists to an ID-property. And the lists are limited, because they may only contain floats and integers.&lt;br /&gt;
&lt;br /&gt;
=== Referencing ===&lt;br /&gt;
[[image:Crouch-custom-properties.png |right|250px|]]&lt;br /&gt;
ID-properties have the advantages that they are stored in a blend-file when it is saved, and that they are easy to keep track of. The main reason they are easy to track, is that by default they are shown in the user interface. They show up in the appropriate Custom Properties panel. So if you add an ID-property to a lamp, it will show up in the Custom Properties panel in the Lamp window. This makes it very easy to change their values, even for normal users. This can also be used to add new ID-properties, without having to use python.&lt;br /&gt;
&lt;br /&gt;
To display an ID-property using [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.types.UILayout.html#bpy.types.UILayout.prop UILayout.prop()], you can't simply pass &amp;lt;i&amp;gt;&amp;quot;foo&amp;quot;&amp;lt;/i&amp;gt; as the property, but you need to pass a one-item list as a string. So &amp;lt;i&amp;gt;'[&amp;quot;foo&amp;quot;]'&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class myPanel(bpy.types.Panel):     # panel to display new property&lt;br /&gt;
    bl_space_type = &amp;quot;VIEW_3D&amp;quot;       # show up in: 3d-window&lt;br /&gt;
    bl_region_type = &amp;quot;UI&amp;quot;           # show up in: properties panel&lt;br /&gt;
    bl_label = &amp;quot;My Panel&amp;quot;           # name of the new panel&lt;br /&gt;
    &lt;br /&gt;
    def draw(self, context):&lt;br /&gt;
        # display &amp;quot;foo&amp;quot; ID-property, of the active object&lt;br /&gt;
        self.layout.prop(bpy.context.active_object, '[&amp;quot;foo&amp;quot;]')&lt;br /&gt;
&lt;br /&gt;
bpy.utils.register_class(myPanel)   # register panel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that this won't work if the active object hasn't got the ID-property, so make sure that you have a fallback in your code instead of raising an error.&lt;br /&gt;
&lt;br /&gt;
So far ID-properties were pretty straightforward, but it gets a bit more tricky when you wish to set parameters for the ID-property. For instance the minimum and maximum value of an integer. These parameters are stored in a special property called &amp;lt;i&amp;gt;_RNA_UI&amp;lt;/i&amp;gt; It can be accessed like any other ID-property and is a dictionary with the other ID-properties as key and their parameters as values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = bpy.context.active_object               # get the active object&lt;br /&gt;
ob[&amp;quot;foo&amp;quot;] = 7                                # create the ID-property&lt;br /&gt;
ob[&amp;quot;_RNA_UI&amp;quot;] = {&amp;quot;foo&amp;quot;: {&amp;quot;min&amp;quot;:3, &amp;quot;max&amp;quot;:42}} # set parameters&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To keep this example script short it simply overwrites &amp;lt;i&amp;gt;_RNA_UI&amp;lt;/i&amp;gt; and thus erases any already existing parameters. In normal scripts it's better to insert a new key for your new parameters.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
----&lt;br /&gt;
{| {{Css/prettytable}}&lt;br /&gt;
!&lt;br /&gt;
! align=&amp;quot;center&amp;quot; style=&amp;quot;width:28%;&amp;quot; | Property&amp;lt;br&amp;gt;(static)&lt;br /&gt;
! align=&amp;quot;center&amp;quot; style=&amp;quot;width:28%;&amp;quot; |Property&amp;lt;br&amp;gt;(dynamic)&lt;br /&gt;
! align=&amp;quot;center&amp;quot; style=&amp;quot;width:28%;&amp;quot; | ID-Property&lt;br /&gt;
|-&lt;br /&gt;
!align=center|Creation&lt;br /&gt;
|align=center|bpy.types.Object.foo = bpy.props.StringProperty()&lt;br /&gt;
|align=center|bpy.types.Object.foo = property(bar)&lt;br /&gt;
|align=center|ob[&amp;quot;foo&amp;quot;] = &amp;quot;bar&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=center|Declared for&lt;br /&gt;
|align=center|all datablocks of same type&lt;br /&gt;
|align=center|all datablocks of same type&lt;br /&gt;
|align=center|single datablock&lt;br /&gt;
|-&lt;br /&gt;
!align=center|Assigning values&lt;br /&gt;
|align=center|ob.foo = &amp;quot;bar&amp;quot;&lt;br /&gt;
|align=center|ob.foo = &amp;quot;bar&amp;quot;&lt;br /&gt;
|align=center|ob[&amp;quot;foo&amp;quot;] = &amp;quot;bar&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!align=center|Accepted values&lt;br /&gt;
|align=center|Any [http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.props.html property]&lt;br /&gt;
|align=center|Functions&lt;br /&gt;
|align=center|Floats, integers, lists*, strings&lt;br /&gt;
|-&lt;br /&gt;
!align=center|Stored in .blend&lt;br /&gt;
|align=center|Yes**&lt;br /&gt;
|align=center|No&lt;br /&gt;
|align=center|Yes&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; List may only contain floats and integers.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; Datablocks that have a value assigned to the property, save that value as an ID-property.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Iluvblender</name></author>
		
	</entry>
</feed>