import bpy
for count in range(5):
bpy.ops.mesh.primitive_cone_add(
vertices=32
, end_fill_type='TRIFAN'
, calc_uvs=True
, rotation=(0.0, 0.0, 0.0)
, scale=(0.5, 0.5, 0.5))
ひと工夫してみる
横だけでなく縦にも並べる
※X軸方向にも並べる処理を追加する
横人並べるた上で、それを一回転してみようというわけです。
なので、下のような出力が得られました。
実行コマンドは下のようになります。
import bpy
# change direction
for lines in range(0, 5):
# put on line
for count in range(0, 5):
bpy.ops.mesh.primitive_cone_add(
vertices=32
, end_fill_type='NGON'
, calc_uvs=True
, location=(lines,count,0)
, rotation=(0.0, 0.0, 0.0)
, scale=(0.5, 0.5, 0.5))
ひと工夫してみる、その二
横だけでなく縦(Z軸方向)にも追加してみる
やり方は、上記のものと変わりません。ただし、X副方向ではなくZ軸方向に追加します。 実行結果
実行コマンドは下のようになります。
import bpy
# change height direction
for height in range(0,5):
# change direction
for lines in range(0, 5):
# put on line
for count in range(0, 5):
bpy.ops.mesh.primitive_cone_add(
vertices=32
, end_fill_type='NGON'
, calc_uvs=True
, location=(lines,count,height)
, rotation=(0.0, 0.0, 0.0)
, scale=(0.5, 0.5, 0.5))
稀にみる3次元ループです(笑)
円状に並べてしてみる
実行結果
三角関数を使用してみました。数学嫌いだった過去が悔やまれる。。。
import bpy
import math
#for lines in range(0, 3):
for count in range(0, 11):
rad = count * 36
bpy.ops.mesh.primitive_cone_add(
vertices=32
, end_fill_type='NGON'
, calc_uvs=True
, location=(math.sin(rad), math.cos(rad), 0)
, rotation=(0.0, 0.0, 0.0)
, scale=(0.2, 0.2, 0.2))
from bpy import context, data, ops
# [1] Create a bezier circle and enter edit mode.
ops.curve.primitive_bezier_circle_add(radius=1.0,
location=(0.0, 0.0, 0.0),
enter_editmode=True)
# [2] Subdivide the curve by a number of cuts, giving the
# random vertex function more points to work with.
ops.curve.subdivide(number_cuts=16)
# [3] Randomize the vertices of the bezier circle.
# offset [-inf .. inf], uniform [0.0 .. 1.0],
# normal [0.0 .. 1.0], RNG seed [0 .. 10000].
ops.transform.vertex_random(offset=1.0, uniform=0.1, normal=0.0, seed=0)
# [4] Scale the curve while in edit mode.
ops.transform.resize(value=(2.0, 2.0, 3.0))
# Return to object mode.
ops.object.mode_set(mode='OBJECT')
# Subdivide the curve by a number of cuts, giving the
# random vertex function more points to work with.
ops.curve.subdivide(number_cuts=16)
# Randomize the vertices of the bezier circle.
# offset [-inf .. inf], uniform [0.0 .. 1.0],
# normal [0.0 .. 1.0], RNG seed [0 .. 10000].
ops.transform.vertex_random(offset=1.0, uniform=0.1, normal=0.0, seed=0)
from bpy import context, data, ops
# [1] Create a bezier circle and enter edit mode.
ops.curve.primitive_bezier_curve_add(radius=1.0,
location=(0.0, 0.0, 0.0),
enter_editmode=True)
# [2] Subdivide the curve by a number of cuts, giving the
# random vertex function more points to work with.
ops.curve.subdivide(number_cuts=16)
# [3] Randomize the vertices of the bezier circle.
# offset [-inf .. inf], uniform [0.0 .. 1.0],
# normal [0.0 .. 1.0], RNG seed [0 .. 10000].
ops.transform.vertex_random(offset=1.0, uniform=0.1, normal=0.0, seed=0)
# [4] Scale the curve while in edit mode.
ops.transform.resize(value=(2.0, 2.0, 3.0))
# Return to object mode.
ops.object.mode_set(mode='OBJECT')
# This example assumes we have a mesh object selected
import bpy
import bmesh
# Get the active mesh
me = bpy.context.object.data
# Get a BMesh representation
bm = bmesh.new() # create an empty BMesh
bm.from_mesh(me) # fill it in from a Mesh
# Modify the BMesh, can do anything here...
for v in bm.verts:
v.co.x += 1.0
# Finish up, write the bmesh back to the mesh
bm.to_mesh(me)
bm.free() # free and prevent further access
from bpy import context, data, ops
# Create a bezier circle and enter edit mode.
ops.curve.primitive_bezier_circle_add(radius=1.0,
location=(0.0, 0.0, 0.0),
enter_editmode=True)
# Subdivide the curve by a number of cuts, giving the
# random vertex function more points to work with.
ops.curve.subdivide(number_cuts=16)
# Randomize the vertices of the bezier circle.
# offset [-inf .. inf], uniform [0.0 .. 1.0],
# normal [0.0 .. 1.0], RNG seed [0 .. 10000].
ops.transform.vertex_random(offset=1.0, uniform=0.1, normal=0.0, seed=0)
# Scale the curve while in edit mode.
ops.transform.resize(value=(2.0, 2.0, 3.0))
# Return to object mode.
ops.object.mode_set(mode='OBJECT')
import bpy
# print all objects
for obj in bpy.data.objects:
print(obj.name)
# print all scene names in a list
print(bpy.data.scenes.keys())
# remove mesh Cube
if "Cube" in bpy.data.meshes:
mesh = bpy.data.meshes["Cube"]
print("removing mesh", mesh)
bpy.data.meshes.remove(mesh)
# write images into a file next to the blend
import os
with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w') as fs:
for image in bpy.data.images:
fs.write("%s %d x %d\n" % (image.filepath, image.size[0], image.size[1]))
# remove all objects in scene rather than the selected ones
import bpy
override = bpy.context.copy()
override['selected_objects'] = list(bpy.context.scene.objects)
bpy.ops.object.delete(override)
MeCab python module
$Id: README,v 1.1.1.1 2005/12/03 14:18:50 taku-ku Exp $;
1. Installation
% python setup.py build
% su
# python setup.py install
You can change the install directory with the --prefix option. For example:
% python setup.py install --prefix=/tmp/pybuild/foobar
2. How to use?
see 'test.py' as a sample program.
MeCab python module
$Id: README,v 1.1.1.1 2005/12/03 14:18:50 taku-ku Exp $;
1. Installation
% python setup.py build
% su
# python setup.py install
You can change the install directory with the --prefix option. For example:
% python setup.py install --prefix=/tmp/pybuild/foobar
2. How to use?
see 'test.py' as a sample program.