﻿<?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%2FConsole</id>
	<title>Doc:2.6/Manual/Extensions/Python/Console - 版の履歴</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%2FConsole"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Console&amp;action=history"/>
	<updated>2026-11-25T05:11:44Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Console&amp;diff=94143&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/Console&amp;diff=94143&amp;oldid=prev"/>
		<updated>2018-06-28T18:45:52Z</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:45時点における版&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/Console&amp;diff=94142&amp;oldid=prev</id>
		<title>wiki&gt;Arboury: fix a typo</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Doc:2.6/Manual/Extensions/Python/Console&amp;diff=94142&amp;oldid=prev"/>
		<updated>2013-06-27T15:04:50Z</updated>

		<summary type="html">&lt;p&gt;fix a typo&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Page/Header | 2.5| Doc:2.5/Manual/Extensions/Python/Intro to Python | Doc:2.5/Manual/Extensions/Python/Text_editor}}&lt;br /&gt;
&lt;br /&gt;
= The Console Editor Type =&lt;br /&gt;
The interactive console in Blender 2.5 has been improved. Auto Complete, Python Reporting &amp;amp; more features have been added. Testing one-liners in the console is a good way to learn the Python API.&lt;br /&gt;
&lt;br /&gt;
== Accessing Built-in Python Console ==&lt;br /&gt;
Launching the Console using mouse.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt; &amp;lt;youtube&amp;gt;Ge2Kwy5EGE0&amp;lt;/youtube&amp;gt; &amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By pressing {{Shortcut|Shift|F4}} in any Blender Editor Type (3D View, Timeline etc.,)  you can change it to a Console Editor.&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Default-Console.png|600px]]&lt;br /&gt;
&lt;br /&gt;
From the screen shot above, you will notice that apart from the usual hot keys that are used to navigate, by pressing {{Shortcut|Ctrl|Space}} you can enable Auto-complete feature.&lt;br /&gt;
&lt;br /&gt;
Since Blender 2.5 uses Python 3.x, the interpreter is loaded and is ready to accept commands at the prompt &amp;#039;&amp;#039;&amp;#039;&amp;gt;&amp;gt;&amp;gt; &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== First look at the Console Environment ==&lt;br /&gt;
To check what is loaded into the interpreter environment, type dir() at the prompt and execute it.&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Listing-Globals.png|600px]]&lt;br /&gt;
&lt;br /&gt;
Following is a quick overview of the output&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;&amp;#039;C&amp;#039;&amp;#039;&amp;#039;&amp;#039;: Quick access to bpy.context&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;&amp;#039;D&amp;#039;&amp;#039;&amp;#039;&amp;#039;: Quick access to bpy.data&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;&amp;#039;__builtins__&amp;#039;&amp;#039;&amp;#039;&amp;#039;: Python Built-ins (Classes, functions, variables)&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;&amp;#039;bpy&amp;#039;&amp;#039;&amp;#039;&amp;#039;: Top level Blender Python API module.&lt;br /&gt;
&lt;br /&gt;
== Auto Completion at work ==&lt;br /&gt;
Now, type bpy. and then press {{Shortcut|Ctrl|Space}} and you will see the Console auto-complete feature in action. &lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Auto-Completion.png|600px]]&lt;br /&gt;
&lt;br /&gt;
You will notice that a list of sub-modules inside of bpy appear. These modules encapsulate all that we can do with Blender Python API and are very powerful tools.&lt;br /&gt;
&lt;br /&gt;
Lets list all the contents of bpy.app module.&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-List-SubModule-Contents.png|600px]]&lt;br /&gt;
&lt;br /&gt;
Notice the green output above the prompt where you enabled auto-completion. What you see is the result of auto completion listing. In the above listing all are module attribute names, but if you see any name end with &amp;#039;(&amp;#039;, then that is a function.&lt;br /&gt;
&lt;br /&gt;
We will make use of this a lot to help our learning the API faster. Now that you got a hang of this, lets proceed to investigate some of modules in bpy.&lt;br /&gt;
&lt;br /&gt;
== Before tinkering with the modules.. ==&lt;br /&gt;
If you look at the 3D Viewport in the default Blender scene, you will notice 3 objects: Cube, Lamp and Camera.&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Default-Scene.png|600px]]&lt;br /&gt;
&lt;br /&gt;
* All objects exist in a context and there can be various modes under which they are operated upon.&lt;br /&gt;
* At any instance, only one object is active and there can be more than one selected objects.&lt;br /&gt;
* All objects are data in the Blender file.&lt;br /&gt;
* There are operators/functions that create and modify these objects.&lt;br /&gt;
&lt;br /&gt;
For all the scenarios listed above (not all were listed, mind you..) the bpy module provides functionality to access and modify data.&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
== bpy.context ==&lt;br /&gt;
;Note: For the commands below to show the proper output, make sure you have selected object(s) in the 3D view.&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Example-bpy-context.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Try it out!===&lt;br /&gt;
&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;bpy.context.mode&amp;#039;&amp;#039;&amp;#039;: Will print the current 3D View mode (Object, Edit, Sculpt etc.,)&lt;br /&gt;
&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;bpy.context.object&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;bpy.context.active_object&amp;#039;&amp;#039;&amp;#039;: Will give access to the active object in the 3D View&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.object.location.x = 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Change x location to a value of 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.object.location.x += 0.5&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Move object from previous x location by 0.5 unit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.object.location = [1, 2, 3]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Changes x, y, z location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.object.location.xyz = [1, 2, 3]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Same as above&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; type(bpy.context.object.location)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Data type of objects location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; dir(bpy.context.object.location)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Now that is a lot of data that you have access to&lt;br /&gt;
&lt;br /&gt;
;&amp;#039;&amp;#039;&amp;#039;bpy.context.selected_objects&amp;#039;&amp;#039;&amp;#039;: Will give access to a list of all selected objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.selected_objects then press {{Shortcut|Ctrl|Space}}&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.selected_objects[0]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Prints out name of first object in the list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; [object for object in bpy.context.selected_objects if object != bpy.context.object]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Complex one.. But this prints a list of objects not including the active object&lt;br /&gt;
&lt;br /&gt;
== bpy.data ==&lt;br /&gt;
bpy.data has a bunch of functions and variables that give you access to all the data in the Blender file.&lt;br /&gt;
&lt;br /&gt;
You can access following data in the current Blender file:&lt;br /&gt;
 objects, meshes, materials, textures, scenes, screens, sounds, scripts, texts, &lt;br /&gt;
 cameras, curves, lamps, brushes, armatures, images, lattices, libraries, worlds, &lt;br /&gt;
 groups, metaballs, particles, node_groups&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s a lot of data.&lt;br /&gt;
&lt;br /&gt;
=== Try it out! ===&lt;br /&gt;
&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Example-bpy-data.png|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Exercise ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; for object in bpy.data.scenes[&amp;#039;Scene&amp;#039;].objects: print(object.name)&amp;lt;/source&amp;gt; {{Shortcut|Enter}} twice&lt;br /&gt;
 Prints the names of all objects belonging to the Blender scene with name &amp;quot;Scene&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.data.scenes[&amp;#039;Scene&amp;#039;].objects.unlink(bpy.context.active_object)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 Unlink the active object from the Blender scene named &amp;#039;Scene&amp;#039;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.data.materials[&amp;#039;Material&amp;#039;].shadows&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.data.materials[&amp;#039;Material&amp;#039;].shadows = False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== bpy.ops ==&lt;br /&gt;
The tool/action system in Blender 2.5 is built around the concept of operators. These operators can be called directly from console or can be executed by click of a button or packaged in a python script. Very powerful they are..&lt;br /&gt;
&lt;br /&gt;
For a list of various operator categories, click here&lt;br /&gt;
&lt;br /&gt;
Lets create a set of five Cubes in the 3D Viewport. First, delete the existing Cube object by selecting it and pressing {{Shortcut|X}}&lt;br /&gt;
&lt;br /&gt;
=== Try it out! ===&lt;br /&gt;
The following commands are used to specify that the objects are created in layer 1. So first we define an array variable for later reference:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; mylayers = [False]*20&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; mylayers[0] = True&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We create a reference to the operator that is used for creating a cube mesh primitive&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; add_cube = bpy.ops.mesh.primitive_cube_add&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now in a for loop, we create the five objects like this (In the screenshot above, I used another method)&lt;br /&gt;
Press ENTER-KEY twice after entering the command at the shell prompt.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; for index in range(0, 5):&lt;br /&gt;
 ...     add_cube(location=(index*3, 0, 0), layers=mylayers)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:Manual-Part-XX-Manual-Extensions-Python-Console-Example-bpy-ops.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
{{Page/Footer | Doc:2.5/Manual/Extensions/Python/Intro to Python | Doc:2.5/Manual/Extensions/Python/Text_editor}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Arboury</name></author>
		
	</entry>
</feed>