「Doc:2.6/Manual/Extensions/Python/FAQ」の版間の差分

提供: wiki
< Doc:2.6‎ | Manual‎ | Extensions‎ | Python
移動先: 案内検索
(world matrix was multiplied in the wrong order)
 
(1版 をインポートしました)
 
(相違点なし)

2018年6月29日 (金) 03:45時点における最新版


Page status (reviewing guidelines)

Partial page
Proposed fixes: none

Introduction

Since we are working with new and improving Python API, if you have something that needs to be answered, please add it here. We will find answers from dev's if we do not know them and provide an answer here.

Geometry

How can I generate a mesh object using the API?

Download this code example Script_GeneratePyramidMesh.py and run it from the Text Window.

How do I apply a modifier using the API?

 bpy.ops.object.convert(target='MESH', keep_original=False)

All the modifiers in the stack will be applied.

In case you just want to apply only the subsurf modifier and leave others alone, and create a new mesh (Old mesh will retain all its modifiers), the following code shows one way of doing it.

 for modifier in bpy.context.object.modifiers:
     if modifier.type != 'SUBSURF':
         modifier.show_render=True
 bpy.ops.object.convert(target='MESH', '''keep_original=True''')

How do I get the world coordinates of a control vertex of a BezierCurve?

wmtx = bpy.context.active_object.matrix_world

localCoord = bpy.context.active_object.data.splines[0].bezier_points[1].co

worldCoord = wmtx * localCoord

Manual-Part20-scripting-faq-CV-in-world-coords.png

More info...

How do I select/deselect the control points of a Curve

Method 1

Manual-Part20-scripting-faq-select-curve-control-point-method-1.png

curve = bpy.context.selected_objects[0]

curve.data.splines[0].bezier_points[0].select_control_point = True
curve.data.splines[0].bezier_points[2].select_control_point = True

Method 2

Manual-Part20-scripting-faq-select-curve-control-point-method-2.png

bpy.context.active_object.data.splines[0].bezier_points[0].select_control_point = True

More info...

Materials

How to link a mesh/object to a material?

TODO

Customization

How do I automate custom hotkeys?