import bpy
from math import radians
# Create a cylinder
bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=2)
# Select rotation axis
zion_xyz = 'xana'
if zion_xyz == 'xana':
# Rotate 90 degrees around X-axis
bpy.context.object.rotation_euler[0] = radians(0)
bpy.context.object.rotation_euler[1] = radians(0)
bpy.context.object.rotation_euler[2] = radians(0)
# Scale along X-axis
bpy.context.object.scale[0] = 120
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1
elif zion_xyz == 'yana':
# Rotate 90 degrees around Y-axis
bpy.context.object.rotation_euler[0] = radians(0)
bpy.context.object.rotation_euler[1] = radians(0)
bpy.context.object.rotation_euler[2] = radians(-90)
# Scale along Y-axis
bpy.context.object.scale[0] = 1
bpy.context.object.scale[1] = 3
bpy.context.object.scale[2] = 1
elif zion_xyz == 'zana':
# Rotate 90 degrees around Z-axis
bpy.context.object.rotation_euler[0] = radians(180)
bpy.context.object.rotation_euler[1] = radians(0)
bpy.context.object.rotation_euler[2] = radians(0)
# Scale along Z-axis
bpy.context.object.scale[0] = 1
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 10
else:
print('Invalid rotation axis selected.')
# 位置を調整
bpy.context.object.location[0] = 0.0 #x
bpy.context.object.location[1] = 0.0 #y
bpy.context.object.location[2] = 0.0 #z
# オブジェクトに名前を付ける
bpy.context.object.name = "線路 円柱"
# Select the cylinder
bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
以下のスクリプトを使用して、長さ120、半径0.5の円柱を作成することができます。
import bpy
# 半径と高さを設定
r = 0.5
h = 120
# 円柱を作成
bpy.ops.mesh.primitive_cylinder_add(radius=r, depth=h)
# 位置を調整
bpy.context.object.location[0] = 0.0
bpy.context.object.location[1] = 0.0
bpy.context.object.location[2] = h/2
# オブジェクトに名前を付ける
bpy.context.object.name = "線路 円柱"
import bpy
# 円柱を作成する
bpy.ops.mesh.primitive_cylinder_add(radius=30, depth=1)
# 円に面を追加する
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.edge_face_add()
bpy.ops.object.mode_set(mode='OBJECT')
# 円柱の位置を変更する
bpy.context.object.location[0] = 0.0 # X座標
bpy.context.object.location[1] = 0.0 # Y座標
bpy.context.object.location[2] = 0.0 # Z座標
# オブジェクトに名前を付ける
bpy.context.object.name = "線路レール"
bbb