﻿<?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%3A2.4%2FSource%2FPython%2FAPI%2FObjectCreation</id>
	<title>Dev:2.4/Source/Python/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%3A2.4%2FSource%2FPython%2FAPI%2FObjectCreation"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Source/Python/API/ObjectCreation&amp;action=history"/>
	<updated>2026-05-03T17:38:04Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.4/Source/Python/API/ObjectCreation&amp;diff=51616&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Source/Python/API/ObjectCreation&amp;diff=51616&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:2.4/Source/Python/API/ObjectCreation&amp;diff=51615&amp;oldid=prev</id>
		<title>2010年3月30日 (火) 19:13にwiki&gt;Terrywallworkによる</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Source/Python/API/ObjectCreation&amp;diff=51615&amp;oldid=prev"/>
		<updated>2010-03-30T19:13:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Object Creation API==&lt;br /&gt;
&lt;br /&gt;
===Current===&lt;br /&gt;
&lt;br /&gt;
These are the available ways to create an object in BPython:&lt;br /&gt;
&lt;br /&gt;
====Recommended====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = Object.New(type) # type is a string: 'Mesh', 'Lamp', 'Camera', etc.&lt;br /&gt;
obdata = ob.data # access the new object's data&lt;br /&gt;
scene.link(ob) # link ob to a scene&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Pros:&lt;br /&gt;
*#Works well, easy to understand.&lt;br /&gt;
*#No risk of creating unlinked obdata.&lt;br /&gt;
*Cons:&lt;br /&gt;
*#A little too verbose for such a common operation.&lt;br /&gt;
*#If the script coder doesn't link to a scene we may end up with an unlinked object that also doesn't have obdata (it is only created when ob.data is first accessed or when linking to a scene).&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
====Also possible====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
obdata = Mesh.New('mymesh') # using Mesh as an example&lt;br /&gt;
ob = Object.New('Mesh')&lt;br /&gt;
ob.link(obdata)&lt;br /&gt;
scene.link(ob)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Pros:&lt;br /&gt;
*#Works well, easy to understand, too.&lt;br /&gt;
*Cons:&lt;br /&gt;
*#Even more verbose.&lt;br /&gt;
*#If an error happens or the script writer forgets to link obdata to ob or ob to scene we end up with unlinked data in Blender.&lt;br /&gt;
*#If the object is linked to a scene, first, object data is unnecessarily (in this example) created for it and later substituted by obdata at ob.link(obdata).&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
====Summing up====&lt;br /&gt;
&lt;br /&gt;
The situation can and should be improved. These are our goals:&lt;br /&gt;
&lt;br /&gt;
*Avoid pitfalls like the issues mentioned above.&lt;br /&gt;
*Present a less verbose way to create and link ob+obdata to a scene.&lt;br /&gt;
*Not break compatibility, if possible.&lt;br /&gt;
&lt;br /&gt;
There are uses where the current API might be necessary and, more important, many scripts out there depend on it. Since we are not creating a new API right now, the best way to solve this is to have a simple and safe alternative that we can recommend users to adopt.&lt;br /&gt;
&lt;br /&gt;
====Planned updates====&lt;br /&gt;
&lt;br /&gt;
*Object.New() can be changed to accept a 'data' keyword argument:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = Object.New(type, name, data = None) # data can be an obdata of the right 'type'.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''NEW''': Object.New() can be changed to accept a 'scene' keyword argument:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = Object.New(type, name, data = None, scene = None)&lt;br /&gt;
# The current scene is used, unless the user provides a different one.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, with these two updates, this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
ob = Blender.Object.New('Lamp')&lt;br /&gt;
data = Blender.Lamp.New()&lt;br /&gt;
ob.link(data)&lt;br /&gt;
scene = Blender.Scene.GetCurrent()&lt;br /&gt;
scene.link(ob)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
ob = Blender.Object.New('Lamp')&lt;br /&gt;
scene = Blender.Scene.GetCurrent()&lt;br /&gt;
scene.link(ob) # automatically adds the obdata&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
can safely be written as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Blender&lt;br /&gt;
ob = Blender.Object.New('Lamp')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above changes should be added early next week, unless someone has a good point against it.&lt;br /&gt;
----&lt;br /&gt;
*To help create duplicates we can use a .copy() method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
ob = Object.Get(name)&lt;br /&gt;
ob2 = ob.copy() # normal copy&lt;br /&gt;
ob3 = ob.copy(linked = True) # linked copy&lt;br /&gt;
ten_objects = ob.copy(linked = True, count = 10) # returns list or tuple&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Notes:&lt;br /&gt;
*#These changes don't break the current API.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
===Ideas for an alternative===&lt;br /&gt;
&lt;br /&gt;
====Start with the scene====&lt;br /&gt;
&lt;br /&gt;
A point we all seem to agree on is that this alternative should at once create an object+obdata and link it to a scene. An elegant way to do this is to have it as a scene method.&lt;br /&gt;
&lt;br /&gt;
====Iterator: scene.objects====&lt;br /&gt;
&lt;br /&gt;
This is in Blender's CVS as an experimental feature, designed to eventually replace the current method of adding objects and dealing with the objects in the scene.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from Blender import Scene, Object&lt;br /&gt;
scn= Scene.GetCurrent() &lt;br /&gt;
&lt;br /&gt;
print len(scn.objects) # Print the number of objects in the scene&lt;br /&gt;
&lt;br /&gt;
scn.objects.remove(Object.Get('Cube')) # instead of scene.unlink()&lt;br /&gt;
&lt;br /&gt;
scn.objects.add(someObject) # instead of scn.link() &lt;br /&gt;
&lt;br /&gt;
# Adding an object from obdata in 1 step&lt;br /&gt;
ob= scn.objects.new(Mesh.New('Cube')) &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Pros:&lt;br /&gt;
*#Thin wrapper, more efficient than scn.getChidren() in many cases.&lt;br /&gt;
*#New objects are ALWAYS added to a scene and have obdata&lt;br /&gt;
*#New objects can be made with 1 command&lt;br /&gt;
*#Acts like a set with generic set operations.&lt;br /&gt;
*#Gives object operations their own namespace&amp;lt;br&amp;gt;scn.link(ob) and scn.unlink() don't obviously refer to objects.&lt;br /&gt;
*#Scene operations that currently deal with objects can be moved into this iterator. scn.getActiveObject() can be made scn.objects.active&lt;br /&gt;
*Cons:&lt;br /&gt;
*#Not compatible with current method (would have to coexist initially)&lt;br /&gt;
*#Changes functionality unnecessarily - add() and remove() are just scn.link() and scn.unlink() renamed and in a more obscure place.&lt;br /&gt;
*Notes:&lt;br /&gt;
*#Campbell already committed this to cvs, so it can be tested.&lt;br /&gt;
*# --[[User:Ideasman42|Ideasman42]] 04:36, 29 August 2006 (CEST) Writes...&amp;lt;br&amp;gt;Stivs was critical of the way objects uses scn.objects add()|remove()|new()&amp;lt;br&amp;gt;suggesting these functions should be accessible directly from the scene.&amp;lt;br&amp;gt;There are arguments for and against I can think of for this...&amp;lt;br&amp;gt;Moving object manipulation functions to the scene, ob= scn.newObject(obdata) could replace my proposed ob= scn.objects.new(obdata).  However doing this opens up a namespace problem. - Scenes don't just deal with objects - if they did we could scrap scn.objects and just add iterator functions to scn.&amp;lt;br&amp;gt;eg. for ob in scn: print ob.name.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
====Separate object type creation====&lt;br /&gt;
&lt;br /&gt;
Instead of a general object creation function or method, we could have specific ones:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# these create objects of the indicated kind:&lt;br /&gt;
mesh_ob = scene.addMesh(name = 'Mesh', data = None)&lt;br /&gt;
lamp_ob = scene.addLamp(name = 'Lamp', type = &amp;lt;Spot&amp;gt;, data = None)&lt;br /&gt;
cam_ob = scene.addCamera(name = 'Camera', type = &amp;lt;Persp&amp;gt;, data = None)&lt;br /&gt;
#and so on&lt;br /&gt;
&lt;br /&gt;
#Say we want a new mesh object linked to existing obdata:&lt;br /&gt;
obdata = Mesh.Get('mymeshdata') # our mesh data&lt;br /&gt;
ob = scene.addMesh(name = 'NewMesh', data = obdata)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Pros:&lt;br /&gt;
*#Clear and simple.&lt;br /&gt;
*#Already takes care of obdata and also links to a scene.&lt;br /&gt;
*Cons:&lt;br /&gt;
*#Creates a bunch of functions instead of one single scene.addObject.&lt;br /&gt;
*#Data spesific functions are not an advantage when adding from obdata since the obdata already defines its own type.&lt;br /&gt;
*#Functions dont obviously deal with objects only. Other functions that add elements to a scene may then be confused with obdata. - ob.addScriptLink() for eg.&lt;br /&gt;
*Notes:&lt;br /&gt;
*#In the code we used placeholders &amp;lt;Spot&amp;gt; and &amp;lt;Persp&amp;gt; instead of strings because we've discussed using constants for these things everywhere (where to put these constants for easier access?).&lt;br /&gt;
*#We can further simplify access via scenes by pre-importing Blender.Scene functions and variables in our main dictionary (but this is another discussion).&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
====Other ideas?====&lt;br /&gt;
&amp;lt;Feel free to add them&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Comments and Suggestions===&lt;br /&gt;
&lt;br /&gt;
- We need to be aware of the problem with curves- a curve object can't exist without at least 1 curve, this will be a problem when adding an object directly to a scene from new obdata.&lt;br /&gt;
Maybe always have a 1 point curve at 0,0,0 --[[User:Ideasman42|Ideasman42]] 05:09, 29 August 2006 (CEST)&lt;br /&gt;
&lt;br /&gt;
[[Category:API's]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Terrywallwork</name></author>
		
	</entry>
</feed>