﻿<?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=Dev_talk%3ASource%2FBPython%2FAPI%2FObjectCreation</id>
	<title>Dev talk:Source/BPython/API/ObjectCreation - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev_talk%3ASource%2FBPython%2FAPI%2FObjectCreation"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev_talk:Source/BPython/API/ObjectCreation&amp;action=history"/>
	<updated>2026-12-04T07:16:33Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev_talk:Source/BPython/API/ObjectCreation&amp;diff=51628&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev_talk:Source/BPython/API/ObjectCreation&amp;diff=51628&amp;oldid=prev"/>
		<updated>2018-06-28T17:49:50Z</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日 (木) 17:49時点における版&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=Dev_talk:Source/BPython/API/ObjectCreation&amp;diff=51627&amp;oldid=prev</id>
		<title>wiki&gt;Mindrones: Talk:BlenderDev/BPythonAPI/ObjectCreationAPI moved to Dev talk:Source/BPython/API/ObjectCreation: move to Dev:</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev_talk:Source/BPython/API/ObjectCreation&amp;diff=51627&amp;oldid=prev"/>
		<updated>2009-04-24T22:45:10Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/%E3%83%88%E3%83%BC%E3%82%AF:BlenderDev/BPythonAPI/ObjectCreationAPI&quot; class=&quot;mw-redirect&quot; title=&quot;トーク:BlenderDev/BPythonAPI/ObjectCreationAPI&quot;&gt;Talk:BlenderDev/BPythonAPI/ObjectCreationAPI&lt;/a&gt; moved to &lt;a href=&quot;/Dev_talk:Source/BPython/API/ObjectCreation&quot; title=&quot;Dev talk:Source/BPython/API/ObjectCreation&quot;&gt;Dev talk:Source/BPython/API/ObjectCreation&lt;/a&gt;: move to Dev:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Discussion: Ideas for an alternative==&lt;br /&gt;
&lt;br /&gt;
The main problem (well pointed by Stephen) with Campbell&amp;#039;s scene.objects iterators was having new/add methods. It looked wrong to be able to change the number of objects, specially in a loop. But doing some more research on it, it&amp;#039;s clear that Python itself accepts addition methods in containers with iter functionality (after all, dicts, lists, etc. can be iterators) and prevents messing with their size with a runtime error:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dict = {&amp;#039;one&amp;#039;:1, &amp;#039;two&amp;#039;:2, &amp;#039;three&amp;#039;: 3}&lt;br /&gt;
&lt;br /&gt;
for k in dict:&lt;br /&gt;
   if k == &amp;#039;two&amp;#039;:&lt;br /&gt;
      dict[&amp;#039;four&amp;#039;] = 4&lt;br /&gt;
   print k&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This triggers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File &amp;quot;&amp;lt;pyshell#7&amp;gt;&amp;quot;, line 1, in -toplevel-&lt;br /&gt;
    for k in dict:&lt;br /&gt;
RuntimeError: dictionary changed size during iteration&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, if we can code this error checking, too, scene.objects.new or .add looks nice enough.&lt;br /&gt;
&lt;br /&gt;
[[User:ianwill|Willian]] 20:33, 9 December 2006 (CET)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
If we are to have scn.add() rather then scn.objects.add() have about we make it that operations on scene are always related to objects.&lt;br /&gt;
&lt;br /&gt;
  for ob in scn:&lt;br /&gt;
    print ob.name&lt;br /&gt;
&lt;br /&gt;
  len(scn)&lt;br /&gt;
&lt;br /&gt;
  scn.add(ob)&lt;br /&gt;
  scn.add(data= obdata)&lt;br /&gt;
  scn.remove(ob)&lt;br /&gt;
&lt;br /&gt;
We can seperate other functuionality that might need adding/removing into sub iterators so there is no confusion with scn.add() and adding other data.&lt;br /&gt;
&lt;br /&gt;
so we could still have scn.scriptlinks.add(script, event=...)&lt;br /&gt;
&lt;br /&gt;
--[[User:Ideasman42|Ideasman42]] 18:14, 10 September 2006 (CEST)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Iterators show promise, but I&amp;#039;d like to expand on them and have more features, otherwise they are just a fancy way to repeat what we already have:&lt;br /&gt;
&lt;br /&gt;
*Still having to use Object.New() like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ob = scene.objects.new(Mesh.New(&amp;#039;Cube&amp;#039;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is not the best we can do. Example: for the very basic task of creating and naming an object it would translate to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
from Blender import Scene, Mesh # or import *&lt;br /&gt;
&lt;br /&gt;
scene = Scene.GetCurrent()&lt;br /&gt;
ob = scene.objects.new(Mesh.New(&amp;#039;Cube&amp;#039;))&lt;br /&gt;
ob.name = &amp;#039;somename&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A little too much code, just like our current situation. Been thinking about something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
&lt;br /&gt;
scene = Blender.scenes.active&lt;br /&gt;
scene.objects.add(&amp;lt;mesh&amp;gt;, dataname = &amp;#039;Cube&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#so, using:&lt;br /&gt;
scene.objects.add(type = &amp;lt;mesh&amp;gt;, name = &amp;#039;Mesh&amp;#039;,dataname = &amp;#039;Mesh&amp;#039;, data = None)&lt;br /&gt;
#or even:&lt;br /&gt;
scene.meshes.add(name = &amp;#039;Mesh&amp;#039;, dataname = &amp;#039;Mesh&amp;#039;, data = None)&lt;br /&gt;
&lt;br /&gt;
#also, to link existing objects:&lt;br /&gt;
me = Object.Get(&amp;quot;meshob&amp;quot;)&lt;br /&gt;
scene.meshes.link(me)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, having a Blender.scenes iterator and iterator(s) for objects in the Scene module. Note: used &amp;quot;&amp;lt;mesh&amp;gt;&amp;quot; for type because it might be string or constant, let&amp;#039;s see.&lt;br /&gt;
&lt;br /&gt;
Anyway, still discussing / thinking.[[User:ianwill|Willian]]18:59, 30 August 2006 (CEST)&lt;br /&gt;
&lt;br /&gt;
{{Note|Early stages|We&amp;#039;re only thinking and discussing, for now. Nothing is defined yet and opinions / new ideas are welcome.}}&lt;br /&gt;
&lt;br /&gt;
===Update===&lt;br /&gt;
&lt;br /&gt;
Still thinking... also using feedback to the list or via irc from Matt Ebb, Campbell Barton, Martin Poirier, Toni Alatalo and Ken Hughes. Thanks all.&lt;br /&gt;
&lt;br /&gt;
Right now I&amp;#039;m considering these ideas:&lt;br /&gt;
&lt;br /&gt;
* Remove the &amp;#039;&amp;#039;need&amp;#039;&amp;#039; to import Blender and some / most / all its submodules and data.&lt;br /&gt;
:In other words, init the Python interpreter with the C equivalent of this setup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
from Blender import Scene, Mesh, Camera # ... or simply *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add a few things:&lt;br /&gt;
*# Special iterators: Blender.scenes and scene.objects, too, maybe more.&lt;br /&gt;
*: + dict like access: scene.objects[&amp;#039;name&amp;#039;], which is equiv. to Object.Get(&amp;#039;name&amp;#039;).&lt;br /&gt;
*# Add Blender.Data (or some other name) module to access id lists (objects, mesh data objects, etc. etc.). &lt;br /&gt;
*# Constants in the modules themselves for easier access:&lt;br /&gt;
*: Lamp.SUN, Lamp.SPOT, Camera.ORTHO, etc.&lt;br /&gt;
*: ob types (also) directly in the Blender module: MESH, EMPTY, LAMP, etc&lt;br /&gt;
*: ob primitive types, too, as: SPHERE, CUBE, etc. (or Mesh.SPHERE, Mesh.CUBE, then later Curve.BEZIER_CIRCLE, Curve.NURBS_CIRCLE, etc.) Note: we need UVSPHERE and ICOSPHERE, SPHERE (if we add it) would be an alias for the most popular of these two.&lt;br /&gt;
&lt;br /&gt;
* Add scene.add():&lt;br /&gt;
*# Campbell suggested scene.objects.new() instead, but scene.add() is looking better to me, it&amp;#039;s less verbose, more readable.  Compare these two lines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scene.add(Mesh.New())&lt;br /&gt;
scene.objects.new(Mesh.New())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First, I dislike the repetition of &amp;quot;new&amp;quot; in the later, specially with one being lower and the other upper case (one of those little things that force users to learn and remember quirks). And &amp;quot;add&amp;quot; also sounds better than &amp;quot;new&amp;quot; in this case to me. But between scene.objects.add() and scene.add() I still prefer the shorter version for its simplicity and good description of what is going on: scene is a container, you&amp;#039;re adding an object to it.&lt;br /&gt;
&lt;br /&gt;
The method could accept varied input to create objects from:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scene.add(MESH) # a constant&lt;br /&gt;
&lt;br /&gt;
scene.add(Object.New(&amp;#039;Mesh&amp;#039;)) # a new object&lt;br /&gt;
scene.add(ob) # an existing object&lt;br /&gt;
&lt;br /&gt;
scene.add(Mesh.New()) # ob data, object is created and linked to it&lt;br /&gt;
scene.add(mesh) # existing ob data&lt;br /&gt;
&lt;br /&gt;
scene.add(SPHERE) # a constant for a primitive&lt;br /&gt;
#or&lt;br /&gt;
scene.add(Mesh.SPHERE) # But here&amp;#039;s the issue with upper/lower again: MESH, Mesh&lt;br /&gt;
&lt;br /&gt;
scene.add(SPHERE, rings = 16, segments = 16) # keyword params&lt;br /&gt;
&lt;br /&gt;
# we can also extend it to accept script links:&lt;br /&gt;
scene.add(SCRIPTLINK)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With these, here are some simple examples of complete scripts:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scn = scenes.active&lt;br /&gt;
&lt;br /&gt;
scn.add(CUBE)&lt;br /&gt;
scn.add(SPHERE, rings = 10, segments = 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cam = Camera.New(&amp;#039;mycam&amp;#039;, &amp;#039;ortho&amp;#039;)&lt;br /&gt;
light = Object.New(&amp;#039;Lamp&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
scenes.active.add(cam)&lt;br /&gt;
scenes.active.add(light)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Still considering:&lt;br /&gt;
&lt;br /&gt;
*It&amp;#039;s obvious that &amp;quot;scenes.active&amp;quot; will be needed very often, so probably we should have a Blender.scene object always pointing to it (remember that I&amp;#039;d like to import these names from the Blender module on startup, so Blender.something can be accessed directly, no need to import / reference the Blender module). Maybe also scene.object (for active object, if any), too. That&amp;#039;s a tiny but important step towards a &amp;quot;state machine&amp;quot; API, something Stephen told me he&amp;#039;s been thinking about, too. Ex:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scene.add(CUBE)&lt;br /&gt;
&lt;br /&gt;
print scene.object.name&lt;br /&gt;
&lt;br /&gt;
scenes.active = &amp;lt;another scene&amp;gt; # scenes[&amp;#039;myscene&amp;#039;], for example&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;BUT&amp;#039;&amp;#039;&amp;#039; we can have problems with Blender.scene, because of existing scripts that have vars called &amp;quot;scene&amp;quot;. Because &amp;quot;scene = &amp;lt;something&amp;gt;&amp;quot; would either cause an error, if &amp;lt;something&amp;gt; is not a scene or make the passed scene the active one, something the script writer might not have intended. Well, this may not be a huge problem, let&amp;#039;s see.&lt;br /&gt;
&lt;br /&gt;
[[User:ianwill|Willian]] 22:58, 6 September 2006 (CEST)&lt;br /&gt;
&lt;br /&gt;
==Question on Scene API==&lt;br /&gt;
&lt;br /&gt;
Hi Folks,&lt;br /&gt;
&lt;br /&gt;
Objects refactor opens up a wider issue with scene,&lt;br /&gt;
Should we make it more modular?&lt;br /&gt;
At the moment you can do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
scn.addScriptLink()&lt;br /&gt;
scn.remopeScriptLink()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With more data being added to the scenes (tool options), and for general API niceness,&lt;br /&gt;
I think we should divide Scene into parts: this has already been started with renderdata and radiosity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# At the moment we have&lt;br /&gt;
scn.addScriptLinks()&lt;br /&gt;
scn.getScriptLinks()&lt;br /&gt;
scn.clearScriptLinks()&lt;br /&gt;
&lt;br /&gt;
# scriptlinks could be an iterator with add/remove functons&lt;br /&gt;
scn.scriptlinks.add()&lt;br /&gt;
scn.scriptlinks.remove()&lt;br /&gt;
scn.scriptlinks.clear() # or = []&lt;br /&gt;
&lt;br /&gt;
# We could allow access to tool settings (they are stored in the scene too)&lt;br /&gt;
scn.tools.color= someColor&lt;br /&gt;
scn.tools.threshold= 1.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The question- do we want to move functionality into their own namespace.&lt;br /&gt;
&lt;br /&gt;
scn.addMesh(...) is very convenient for new users but kinda pollutes the namespace IMHO.&lt;br /&gt;
&lt;br /&gt;
NMesh was an example of how this was messy-&lt;br /&gt;
 me= ob.data&lt;br /&gt;
&lt;br /&gt;
you could do&lt;br /&gt;
 me.faces.append(...)&lt;br /&gt;
or&lt;br /&gt;
 me.addFace(...)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Currently we have&lt;br /&gt;
 ob= scn.getActiveObject()&lt;br /&gt;
it could be&lt;br /&gt;
 ob= scn.obejcts.active&lt;br /&gt;
&lt;br /&gt;
Why support both modes?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
maybe we need a wiki for this discussion also.&lt;br /&gt;
&lt;br /&gt;
--[[User:Ideasman42|Ideasman42]] 19:01, 30 August 2006 (CEST)&lt;/div&gt;</summary>
		<author><name>wiki&gt;Mindrones</name></author>
		
	</entry>
</feed>