Open25

Blender Scripts Memo

SamiaSamia

カーブオブジェクトに含まれている複数のスプラインを分離して、1オブジェクト1スプラインのカーブオブジェクトにするBlenderスクリプト

from typing import cast
from typing import List

import bpy


# カーブオブジェクトに含まれている複数のスプラインを分離して、1オブジェクト1スプラインのカーブオブジェクトにするBlenderスクリプトです。
# 使い方:オブジェクトモードで、分離(P)したいカーブオブジェクトを選択し、スクリプトを実行します。
def execute():
    # 実行時点のモードを取得
    previous_mode: str = cast(str, bpy.context.mode)

    # 実行時点のモードが「オブジェクト」か「エディット」モードなら以下を実行
    if previous_mode == "OBJECT" or "EDIT":
        active_object: bpy.types.Object = bpy.context.active_object
        curve_data: bpy.types.Curve = active_object.data if isinstance(active_object.data, bpy.types.Curve) else None

        if curve_data:
            splines: List[bpy.types.Spline] = cast(List[bpy.types.Spline], curve_data.splines)
            bpy.ops.object.mode_set(mode="EDIT", toggle=False)
            bpy.ops.curve.select_all(action="DESELECT")

            while len(splines) > 1:
                spline: bpy.types.Spline = splines[0]
                if spline.bezier_points:
                    bezier_points: List[bpy.types.BezierSplinePoint] = cast(
                        List[bpy.types.BezierSplinePoint], spline.bezier_points
                    )
                    bezier_points[0].select_control_point = True
                elif spline.points:
                    points: List[bpy.types.SplinePoint] = cast(List[bpy.types.SplinePoint], spline.points)
                    points[0].select = True
                bpy.ops.curve.select_linked()
                bpy.ops.curve.separate()

            # 実行時点のモードに戻す
            bpy.ops.object.mode_set(mode=previous_mode, toggle=False)


if __name__ == "__main__":
    execute()
SamiaSamia

BlendeのOperatorのidnameから、ソースファイルが何処に存在するかを調べるスクリプト

以下の場合は「bpy.ops.mesh.select_next_item.idname()」の箇所でidnameを指定している。
実行するとコマンドプロンプトにソースファイルまでのパスが表示される

Blenderに内蔵しているオペレーターの場合、必ずしもpythonで書かれているわけではないので、取得できないこともあるので注意。

import bpy
import inspect

print(inspect.getfile(getattr(bpy.types, bpy.ops.mesh.select_next_item.idname())))
SamiaSamia

Blender上でのPythonパッケージのインポート

Blender上で、アドオンではなくpyファイルを直接実行した場合は、下記の参考記事の

https://qiita.com/ysk24ok/items/2711295d83218c699276

このとき、main.pyの__package属性はNone、__name__属性は__main__となり、
top-levelのmoduleとして認識されている。
そのため、from .の.はmain.py自身となりmymoduleをimportできない。

に該当するため、relative importが使えない。

解決策1の様に、相対パスの「.」を外して

from utils import uv_helpers.get_selected_faces

とすれば、読み込めるようになるが、自作のモジュールはPythonのsys.pathにディレクトリを登録しないと読み込めない。
なので

import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

で、実行環境のディレクトリを追加する必要がある。

ただし、PyCharm上ではエラーとなり、コード補完も効かなくなるので、
下記のように条件分岐したほうが良さそう。

if __package__ is None and __name__ == '__main__':
    # print('__package__: {}, __name__: {}'.format(__package__, __name__))
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    from utils import uv_helpers
else:
    # print('__package__: {}'.format(__package__))
    from .utils import uv_helpers
SamiaSamia

BlenderでAPIからアクティブなスペースを取得する方法

記述方法1

import bpy

def main():
    areas = [area for area in bpy.context.screen.areas if (area.type == "IMAGE_EDITOR")]
    print(areas)
    # spaces[0]にActiveなスペースが入っている
    for area in areas:
        area.spaces[0].pivot_point = "CENTER"

main()

記述方法2 関数化して利用

import bpy

def get_areas(type_name):
    areas = []
    for area in bpy.context.screen.areas:
        if area.type == type_name:
            areas.append(area)
    return areas

def get_active_spaces(type):
    areas = get_areas(type)
    return [area.spaces[0] for area in areas]

def main():
    spaces = get_active_spaces("IMAGE_EDITOR")

    for space in spaces:
        space.pivot_point = "CENTER"

main()
SamiaSamia

Blenderのバージョンを確認する関数

# Blenderのバージョンを確認する関数
# 引数に指定したバージョンとBlenderのバージョンを比較して、次に示す値を返す。
# 1 : 引数に指定したバージョン > Blenderのバージョン
# 0 : 引数に指定したバージョン == Blenderのバージョン
# -1: 引数に指定したバージョン < Blenderのバージョン
# 引数
# major: メジャーバージョン
# minor: マイナーバージョン
def check_version(major, minor):
    if bpy.app.version[0] == major and bpy.app.version[1] == minor:
        return 0
    if bpy.app.version[0] > major:
        return 1
    if bpy.app.version[1] > minor:
        return 1
    return -1
SamiaSamia
import bpy

# Rigidbody World が存在しなければ
if not bpy.context.scene.rigidbody_world:
    # Rigidbody Worldを追加する
    bpy.ops.rigidbody.world_add()

    # Rigidbody World Collectionにコレクションを指定する
    bpy.context.scene.rigidbody_world.collection = bpy.data.collections["RigidbodyWorldCollection"]
    # Rigidbody World Constraintsにコレクションを指定する
    bpy.context.scene.rigidbody_world.constraints = bpy.data.collections["RigidbodyWorldConstraints"]

# Rigid Body の有効/無効を切り替える
bpy.context.scene.rigidbody_world.enabled = True

SamiaSamia

Blender 3.0 のアイコン名のリスト

アイコン名のリストを表示する
[
  "NONE",
  "QUESTION",
  "ERROR",
  "CANCEL",
  "TRIA_RIGHT",
  "TRIA_DOWN",
  "TRIA_LEFT",
  "TRIA_UP",
  "ARROW_LEFTRIGHT",
  "PLUS",
  "DISCLOSURE_TRI_RIGHT",
  "DISCLOSURE_TRI_DOWN",
  "RADIOBUT_OFF",
  "RADIOBUT_ON",
  "MENU_PANEL",
  "BLENDER",
  "GRIP",
  "DOT",
  "COLLAPSEMENU",
  "X",
  "DUPLICATE",
  "TRASH",
  "COLLECTION_NEW",
  "OPTIONS",
  "NODE",
  "NODE_SEL",
  "WINDOW",
  "WORKSPACE",
  "RIGHTARROW_THIN",
  "BORDERMOVE",
  "VIEWZOOM",
  "ADD",
  "REMOVE",
  "PANEL_CLOSE",
  "COPY_ID",
  "EYEDROPPER",
  "CHECKMARK",
  "AUTO",
  "CHECKBOX_DEHLT",
  "CHECKBOX_HLT",
  "UNLOCKED",
  "LOCKED",
  "UNPINNED",
  "PINNED",
  "SCREEN_BACK",
  "RIGHTARROW",
  "DOWNARROW_HLT",
  "FCURVE_SNAPSHOT",
  "OBJECT_HIDDEN",
  "TOPBAR",
  "STATUSBAR",
  "PLUGIN",
  "HELP",
  "GHOST_ENABLED",
  "COLOR",
  "UNLINKED",
  "LINKED",
  "HAND",
  "ZOOM_ALL",
  "ZOOM_SELECTED",
  "ZOOM_PREVIOUS",
  "ZOOM_IN",
  "ZOOM_OUT",
  "DRIVER_DISTANCE",
  "DRIVER_ROTATIONAL_DIFFERENCE",
  "DRIVER_TRANSFORM",
  "FREEZE",
  "STYLUS_PRESSURE",
  "GHOST_DISABLED",
  "FILE_NEW",
  "FILE_TICK",
  "QUIT",
  "URL",
  "RECOVER_LAST",
  "THREE_DOTS",
  "FULLSCREEN_ENTER",
  "FULLSCREEN_EXIT",
  "BRUSHES_ALL",
  "LIGHT",
  "MATERIAL",
  "TEXTURE",
  "ANIM",
  "WORLD",
  "SCENE",
  "OUTPUT",
  "SCRIPT",
  "PARTICLES",
  "PHYSICS",
  "SPEAKER",
  "TOOL_SETTINGS",
  "SHADERFX",
  "MODIFIER",
  "BLANK1",
  "FAKE_USER_OFF",
  "FAKE_USER_ON",
  "VIEW3D",
  "GRAPH",
  "OUTLINER",
  "PROPERTIES",
  "FILEBROWSER",
  "IMAGE",
  "INFO",
  "SEQUENCE",
  "TEXT",
  "SPREADSHEET",
  "SOUND",
  "ACTION",
  "NLA",
  "PREFERENCES",
  "TIME",
  "NODETREE",
  "CONSOLE",
  "TRACKER",
  "ASSET_MANAGER",
  "NODE_COMPOSITING",
  "NODE_TEXTURE",
  "NODE_MATERIAL",
  "UV",
  "OBJECT_DATAMODE",
  "EDITMODE_HLT",
  "UV_DATA",
  "VPAINT_HLT",
  "TPAINT_HLT",
  "WPAINT_HLT",
  "SCULPTMODE_HLT",
  "POSE_HLT",
  "PARTICLEMODE",
  "TRACKING",
  "TRACKING_BACKWARDS",
  "TRACKING_FORWARDS",
  "TRACKING_BACKWARDS_SINGLE",
  "TRACKING_FORWARDS_SINGLE",
  "TRACKING_CLEAR_BACKWARDS",
  "TRACKING_CLEAR_FORWARDS",
  "TRACKING_REFINE_BACKWARDS",
  "TRACKING_REFINE_FORWARDS",
  "SCENE_DATA",
  "RENDERLAYERS",
  "WORLD_DATA",
  "OBJECT_DATA",
  "MESH_DATA",
  "CURVE_DATA",
  "META_DATA",
  "LATTICE_DATA",
  "LIGHT_DATA",
  "MATERIAL_DATA",
  "TEXTURE_DATA",
  "ANIM_DATA",
  "CAMERA_DATA",
  "PARTICLE_DATA",
  "LIBRARY_DATA_DIRECT",
  "GROUP",
  "ARMATURE_DATA",
  "COMMUNITY",
  "BONE_DATA",
  "CONSTRAINT",
  "SHAPEKEY_DATA",
  "CONSTRAINT_BONE",
  "CAMERA_STEREO",
  "PACKAGE",
  "UGLYPACKAGE",
  "EXPERIMENTAL",
  "BRUSH_DATA",
  "IMAGE_DATA",
  "FILE",
  "FCURVE",
  "FONT_DATA",
  "RENDER_RESULT",
  "SURFACE_DATA",
  "EMPTY_DATA",
  "PRESET",
  "RENDER_ANIMATION",
  "RENDER_STILL",
  "LIBRARY_DATA_BROKEN",
  "BOIDS",
  "STRANDS",
  "LIBRARY_DATA_INDIRECT",
  "GREASEPENCIL",
  "LINE_DATA",
  "LIBRARY_DATA_OVERRIDE",
  "GROUP_BONE",
  "GROUP_VERTEX",
  "GROUP_VCOL",
  "GROUP_UVS",
  "FACE_MAPS",
  "RNA",
  "RNA_ADD",
  "MOUSE_LMB",
  "MOUSE_MMB",
  "MOUSE_RMB",
  "MOUSE_MOVE",
  "MOUSE_LMB_DRAG",
  "MOUSE_MMB_DRAG",
  "MOUSE_RMB_DRAG",
  "MEMORY",
  "PRESET_NEW",
  "DECORATE",
  "DECORATE_KEYFRAME",
  "DECORATE_ANIMATE",
  "DECORATE_DRIVER",
  "DECORATE_LINKED",
  "DECORATE_LIBRARY_OVERRIDE",
  "DECORATE_UNLOCKED",
  "DECORATE_LOCKED",
  "DECORATE_OVERRIDE",
  "FUND",
  "TRACKER_DATA",
  "HEART",
  "ORPHAN_DATA",
  "USER",
  "SYSTEM",
  "SETTINGS",
  "OUTLINER_OB_EMPTY",
  "OUTLINER_OB_MESH",
  "OUTLINER_OB_CURVE",
  "OUTLINER_OB_LATTICE",
  "OUTLINER_OB_META",
  "OUTLINER_OB_LIGHT",
  "OUTLINER_OB_CAMERA",
  "OUTLINER_OB_ARMATURE",
  "OUTLINER_OB_FONT",
  "OUTLINER_OB_SURFACE",
  "OUTLINER_OB_SPEAKER",
  "OUTLINER_OB_FORCE_FIELD",
  "OUTLINER_OB_GROUP_INSTANCE",
  "OUTLINER_OB_GREASEPENCIL",
  "OUTLINER_OB_LIGHTPROBE",
  "OUTLINER_OB_IMAGE",
  "OUTLINER_COLLECTION",
  "RESTRICT_COLOR_OFF",
  "RESTRICT_COLOR_ON",
  "HIDE_ON",
  "HIDE_OFF",
  "RESTRICT_SELECT_ON",
  "RESTRICT_SELECT_OFF",
  "RESTRICT_RENDER_ON",
  "RESTRICT_RENDER_OFF",
  "RESTRICT_INSTANCED_OFF",
  "OUTLINER_DATA_EMPTY",
  "OUTLINER_DATA_MESH",
  "OUTLINER_DATA_CURVE",
  "OUTLINER_DATA_LATTICE",
  "OUTLINER_DATA_META",
  "OUTLINER_DATA_LIGHT",
  "OUTLINER_DATA_CAMERA",
  "OUTLINER_DATA_ARMATURE",
  "OUTLINER_DATA_FONT",
  "OUTLINER_DATA_SURFACE",
  "OUTLINER_DATA_SPEAKER",
  "OUTLINER_DATA_LIGHTPROBE",
  "OUTLINER_DATA_GP_LAYER",
  "OUTLINER_DATA_GREASEPENCIL",
  "GP_SELECT_POINTS",
  "GP_SELECT_STROKES",
  "GP_MULTIFRAME_EDITING",
  "GP_ONLY_SELECTED",
  "GP_SELECT_BETWEEN_STROKES",
  "MODIFIER_OFF",
  "MODIFIER_ON",
  "ONIONSKIN_OFF",
  "ONIONSKIN_ON",
  "RESTRICT_VIEW_ON",
  "RESTRICT_VIEW_OFF",
  "RESTRICT_INSTANCED_ON",
  "MESH_PLANE",
  "MESH_CUBE",
  "MESH_CIRCLE",
  "MESH_UVSPHERE",
  "MESH_ICOSPHERE",
  "MESH_GRID",
  "MESH_MONKEY",
  "MESH_CYLINDER",
  "MESH_TORUS",
  "MESH_CONE",
  "MESH_CAPSULE",
  "EMPTY_SINGLE_ARROW",
  "LIGHT_POINT",
  "LIGHT_SUN",
  "LIGHT_SPOT",
  "LIGHT_HEMI",
  "LIGHT_AREA",
  "CUBE",
  "SPHERE",
  "CONE",
  "META_PLANE",
  "META_CUBE",
  "META_BALL",
  "META_ELLIPSOID",
  "META_CAPSULE",
  "SURFACE_NCURVE",
  "SURFACE_NCIRCLE",
  "SURFACE_NSURFACE",
  "SURFACE_NCYLINDER",
  "SURFACE_NSPHERE",
  "SURFACE_NTORUS",
  "EMPTY_AXIS",
  "STROKE",
  "EMPTY_ARROWS",
  "CURVE_BEZCURVE",
  "CURVE_BEZCIRCLE",
  "CURVE_NCURVE",
  "CURVE_NCIRCLE",
  "CURVE_PATH",
  "LIGHTPROBE_CUBEMAP",
  "LIGHTPROBE_PLANAR",
  "LIGHTPROBE_GRID",
  "COLOR_RED",
  "COLOR_GREEN",
  "COLOR_BLUE",
  "TRIA_RIGHT_BAR",
  "TRIA_DOWN_BAR",
  "TRIA_LEFT_BAR",
  "TRIA_UP_BAR",
  "FORCE_FORCE",
  "FORCE_WIND",
  "FORCE_VORTEX",
  "FORCE_MAGNETIC",
  "FORCE_HARMONIC",
  "FORCE_CHARGE",
  "FORCE_LENNARDJONES",
  "FORCE_TEXTURE",
  "FORCE_CURVE",
  "FORCE_BOID",
  "FORCE_TURBULENCE",
  "FORCE_DRAG",
  "FORCE_FLUIDFLOW",
  "RIGID_BODY",
  "RIGID_BODY_CONSTRAINT",
  "IMAGE_PLANE",
  "IMAGE_BACKGROUND",
  "IMAGE_REFERENCE",
  "NODE_INSERT_ON",
  "NODE_INSERT_OFF",
  "NODE_TOP",
  "NODE_SIDE",
  "NODE_CORNER",
  "ANCHOR_TOP",
  "ANCHOR_BOTTOM",
  "ANCHOR_LEFT",
  "ANCHOR_RIGHT",
  "ANCHOR_CENTER",
  "SELECT_SET",
  "SELECT_EXTEND",
  "SELECT_SUBTRACT",
  "SELECT_INTERSECT",
  "SELECT_DIFFERENCE",
  "ALIGN_LEFT",
  "ALIGN_CENTER",
  "ALIGN_RIGHT",
  "ALIGN_JUSTIFY",
  "ALIGN_FLUSH",
  "ALIGN_TOP",
  "ALIGN_MIDDLE",
  "ALIGN_BOTTOM",
  "BOLD",
  "ITALIC",
  "UNDERLINE",
  "SMALL_CAPS",
  "CON_ACTION",
  "MOD_LENGTH",
  "MOD_DASH",
  "MOD_LINEART",
  "HOLDOUT_OFF",
  "HOLDOUT_ON",
  "INDIRECT_ONLY_OFF",
  "INDIRECT_ONLY_ON",
  "CON_CAMERASOLVER",
  "CON_FOLLOWTRACK",
  "CON_OBJECTSOLVER",
  "CON_LOCLIKE",
  "CON_ROTLIKE",
  "CON_SIZELIKE",
  "CON_TRANSLIKE",
  "CON_DISTLIMIT",
  "CON_LOCLIMIT",
  "CON_ROTLIMIT",
  "CON_SIZELIMIT",
  "CON_SAMEVOL",
  "CON_TRANSFORM",
  "CON_TRANSFORM_CACHE",
  "CON_CLAMPTO",
  "CON_KINEMATIC",
  "CON_LOCKTRACK",
  "CON_SPLINEIK",
  "CON_STRETCHTO",
  "CON_TRACKTO",
  "CON_ARMATURE",
  "CON_CHILDOF",
  "CON_FLOOR",
  "CON_FOLLOWPATH",
  "CON_PIVOT",
  "CON_SHRINKWRAP",
  "MODIFIER_DATA",
  "MOD_WAVE",
  "MOD_BUILD",
  "MOD_DECIM",
  "MOD_MIRROR",
  "MOD_SOFT",
  "MOD_SUBSURF",
  "HOOK",
  "MOD_PHYSICS",
  "MOD_PARTICLES",
  "MOD_BOOLEAN",
  "MOD_EDGESPLIT",
  "MOD_ARRAY",
  "MOD_UVPROJECT",
  "MOD_DISPLACE",
  "MOD_CURVE",
  "MOD_LATTICE",
  "MOD_TINT",
  "MOD_ARMATURE",
  "MOD_SHRINKWRAP",
  "MOD_CAST",
  "MOD_MESHDEFORM",
  "MOD_BEVEL",
  "MOD_SMOOTH",
  "MOD_SIMPLEDEFORM",
  "MOD_MASK",
  "MOD_CLOTH",
  "MOD_EXPLODE",
  "MOD_FLUIDSIM",
  "MOD_MULTIRES",
  "MOD_FLUID",
  "MOD_SOLIDIFY",
  "MOD_SCREW",
  "MOD_VERTEX_WEIGHT",
  "MOD_DYNAMICPAINT",
  "MOD_REMESH",
  "MOD_OCEAN",
  "MOD_WARP",
  "MOD_SKIN",
  "MOD_TRIANGULATE",
  "MOD_WIREFRAME",
  "MOD_DATA_TRANSFER",
  "MOD_NORMALEDIT",
  "MOD_PARTICLE_INSTANCE",
  "MOD_HUE_SATURATION",
  "MOD_NOISE",
  "MOD_OFFSET",
  "MOD_SIMPLIFY",
  "MOD_THICKNESS",
  "MOD_INSTANCE",
  "MOD_TIME",
  "MOD_OPACITY",
  "REC",
  "PLAY",
  "FF",
  "REW",
  "PAUSE",
  "PREV_KEYFRAME",
  "NEXT_KEYFRAME",
  "PLAY_SOUND",
  "PLAY_REVERSE",
  "PREVIEW_RANGE",
  "ACTION_TWEAK",
  "PMARKER_ACT",
  "PMARKER_SEL",
  "PMARKER",
  "MARKER_HLT",
  "MARKER",
  "KEYFRAME_HLT",
  "KEYFRAME",
  "KEYINGSET",
  "KEY_DEHLT",
  "KEY_HLT",
  "MUTE_IPO_OFF",
  "MUTE_IPO_ON",
  "DRIVER",
  "SOLO_OFF",
  "SOLO_ON",
  "FRAME_PREV",
  "FRAME_NEXT",
  "NLA_PUSHDOWN",
  "IPO_CONSTANT",
  "IPO_LINEAR",
  "IPO_BEZIER",
  "IPO_SINE",
  "IPO_QUAD",
  "IPO_CUBIC",
  "IPO_QUART",
  "IPO_QUINT",
  "IPO_EXPO",
  "IPO_CIRC",
  "IPO_BOUNCE",
  "IPO_ELASTIC",
  "IPO_BACK",
  "IPO_EASE_IN",
  "IPO_EASE_OUT",
  "IPO_EASE_IN_OUT",
  "NORMALIZE_FCURVES",
  "VERTEXSEL",
  "EDGESEL",
  "FACESEL",
  "CURSOR",
  "PIVOT_BOUNDBOX",
  "PIVOT_CURSOR",
  "PIVOT_INDIVIDUAL",
  "PIVOT_MEDIAN",
  "PIVOT_ACTIVE",
  "CENTER_ONLY",
  "ROOTCURVE",
  "SMOOTHCURVE",
  "SPHERECURVE",
  "INVERSESQUARECURVE",
  "SHARPCURVE",
  "LINCURVE",
  "NOCURVE",
  "RNDCURVE",
  "PROP_OFF",
  "PROP_ON",
  "PROP_CON",
  "PROP_PROJECTED",
  "PARTICLE_POINT",
  "PARTICLE_TIP",
  "PARTICLE_PATH",
  "SNAP_FACE_CENTER",
  "SNAP_PERPENDICULAR",
  "SNAP_MIDPOINT",
  "SNAP_OFF",
  "SNAP_ON",
  "SNAP_NORMAL",
  "SNAP_GRID",
  "SNAP_VERTEX",
  "SNAP_EDGE",
  "SNAP_FACE",
  "SNAP_VOLUME",
  "SNAP_INCREMENT",
  "STICKY_UVS_LOC",
  "STICKY_UVS_DISABLE",
  "STICKY_UVS_VERT",
  "CLIPUV_DEHLT",
  "CLIPUV_HLT",
  "SNAP_PEEL_OBJECT",
  "GRID",
  "OBJECT_ORIGIN",
  "ORIENTATION_GLOBAL",
  "ORIENTATION_GIMBAL",
  "ORIENTATION_LOCAL",
  "ORIENTATION_NORMAL",
  "ORIENTATION_VIEW",
  "COPYDOWN",
  "PASTEDOWN",
  "PASTEFLIPUP",
  "PASTEFLIPDOWN",
  "VIS_SEL_11",
  "VIS_SEL_10",
  "VIS_SEL_01",
  "VIS_SEL_00",
  "AUTOMERGE_OFF",
  "AUTOMERGE_ON",
  "UV_VERTEXSEL",
  "UV_EDGESEL",
  "UV_FACESEL",
  "UV_ISLANDSEL",
  "UV_SYNC_SELECT",
  "GP_CAPS_FLAT",
  "GP_CAPS_ROUND",
  "FIXED_SIZE",
  "TRANSFORM_ORIGINS",
  "GIZMO",
  "ORIENTATION_CURSOR",
  "NORMALS_VERTEX",
  "NORMALS_FACE",
  "NORMALS_VERTEX_FACE",
  "SHADING_BBOX",
  "SHADING_WIRE",
  "SHADING_SOLID",
  "SHADING_RENDERED",
  "SHADING_TEXTURE",
  "OVERLAY",
  "XRAY",
  "LOCKVIEW_OFF",
  "LOCKVIEW_ON",
  "AXIS_SIDE",
  "AXIS_FRONT",
  "AXIS_TOP",
  "LAYER_USED",
  "LAYER_ACTIVE",
  "OUTLINER_OB_HAIR",
  "OUTLINER_DATA_HAIR",
  "HAIR_DATA",
  "OUTLINER_OB_POINTCLOUD",
  "OUTLINER_DATA_POINTCLOUD",
  "POINTCLOUD_DATA",
  "OUTLINER_OB_VOLUME",
  "OUTLINER_DATA_VOLUME",
  "VOLUME_DATA",
  "CURRENT_FILE",
  "HOME",
  "DOCUMENTS",
  "TEMP",
  "SORTALPHA",
  "SORTBYEXT",
  "SORTTIME",
  "SORTSIZE",
  "SHORTDISPLAY",
  "LONGDISPLAY",
  "IMGDISPLAY",
  "BOOKMARKS",
  "FONTPREVIEW",
  "FILTER",
  "NEWFOLDER",
  "FOLDER_REDIRECT",
  "FILE_PARENT",
  "FILE_REFRESH",
  "FILE_FOLDER",
  "FILE_BLANK",
  "FILE_BLEND",
  "FILE_IMAGE",
  "FILE_MOVIE",
  "FILE_SCRIPT",
  "FILE_SOUND",
  "FILE_FONT",
  "FILE_TEXT",
  "SORT_DESC",
  "SORT_ASC",
  "LINK_BLEND",
  "APPEND_BLEND",
  "IMPORT",
  "EXPORT",
  "LOOP_BACK",
  "LOOP_FORWARDS",
  "BACK",
  "FORWARD",
  "FILE_ARCHIVE",
  "FILE_CACHE",
  "FILE_VOLUME",
  "FILE_3D",
  "FILE_HIDDEN",
  "FILE_BACKUP",
  "DISK_DRIVE",
  "MATPLANE",
  "MATSPHERE",
  "MATCUBE",
  "MONKEY",
  "HAIR",
  "ALIASED",
  "ANTIALIASED",
  "MAT_SPHERE_SKY",
  "MATSHADERBALL",
  "MATCLOTH",
  "MATFLUID",
  "WORDWRAP_OFF",
  "WORDWRAP_ON",
  "SYNTAX_OFF",
  "SYNTAX_ON",
  "LINENUMBERS_OFF",
  "LINENUMBERS_ON",
  "SCRIPTPLUGINS",
  "DISC",
  "DESKTOP",
  "EXTERNAL_DRIVE",
  "NETWORK_DRIVE",
  "SEQ_SEQUENCER",
  "SEQ_PREVIEW",
  "SEQ_LUMA_WAVEFORM",
  "SEQ_CHROMA_SCOPE",
  "SEQ_HISTOGRAM",
  "SEQ_SPLITVIEW",
  "SEQ_STRIP_META",
  "SEQ_STRIP_DUPLICATE",
  "IMAGE_RGB",
  "IMAGE_RGB_ALPHA",
  "IMAGE_ALPHA",
  "IMAGE_ZDEPTH",
  "HANDLE_AUTOCLAMPED",
  "HANDLE_AUTO",
  "HANDLE_ALIGNED",
  "HANDLE_VECTOR",
  "HANDLE_FREE",
  "VIEW_PERSPECTIVE",
  "VIEW_ORTHO",
  "VIEW_CAMERA",
  "VIEW_PAN",
  "VIEW_ZOOM",
  "BRUSH_BLOB",
  "BRUSH_BLUR",
  "BRUSH_CLAY",
  "BRUSH_CLAY_STRIPS",
  "BRUSH_CLONE",
  "BRUSH_CREASE",
  "BRUSH_FILL",
  "BRUSH_FLATTEN",
  "BRUSH_GRAB",
  "BRUSH_INFLATE",
  "BRUSH_LAYER",
  "BRUSH_MASK",
  "BRUSH_MIX",
  "BRUSH_NUDGE",
  "BRUSH_PINCH",
  "BRUSH_SCRAPE",
  "BRUSH_SCULPT_DRAW",
  "BRUSH_SMEAR",
  "BRUSH_SMOOTH",
  "BRUSH_SNAKE_HOOK",
  "BRUSH_SOFTEN",
  "BRUSH_TEXDRAW",
  "BRUSH_TEXFILL",
  "BRUSH_TEXMASK",
  "BRUSH_THUMB",
  "BRUSH_ROTATE",
  "GPBRUSH_SMOOTH",
  "GPBRUSH_THICKNESS",
  "GPBRUSH_STRENGTH",
  "GPBRUSH_GRAB",
  "GPBRUSH_PUSH",
  "GPBRUSH_TWIST",
  "GPBRUSH_PINCH",
  "GPBRUSH_RANDOMIZE",
  "GPBRUSH_CLONE",
  "GPBRUSH_WEIGHT",
  "GPBRUSH_PENCIL",
  "GPBRUSH_PEN",
  "GPBRUSH_INK",
  "GPBRUSH_INKNOISE",
  "GPBRUSH_BLOCK",
  "GPBRUSH_MARKER",
  "GPBRUSH_FILL",
  "GPBRUSH_AIRBRUSH",
  "GPBRUSH_CHISEL",
  "GPBRUSH_ERASE_SOFT",
  "GPBRUSH_ERASE_HARD",
  "GPBRUSH_ERASE_STROKE",
  "KEYTYPE_KEYFRAME_VEC",
  "KEYTYPE_BREAKDOWN_VEC",
  "KEYTYPE_EXTREME_VEC",
  "KEYTYPE_JITTER_VEC",
  "KEYTYPE_MOVING_HOLD_VEC",
  "HANDLETYPE_FREE_VEC",
  "HANDLETYPE_ALIGNED_VEC",
  "HANDLETYPE_VECTOR_VEC",
  "HANDLETYPE_AUTO_VEC",
  "HANDLETYPE_AUTO_CLAMP_VEC",
  "COLORSET_01_VEC",
  "COLORSET_02_VEC",
  "COLORSET_03_VEC",
  "COLORSET_04_VEC",
  "COLORSET_05_VEC",
  "COLORSET_06_VEC",
  "COLORSET_07_VEC",
  "COLORSET_08_VEC",
  "COLORSET_09_VEC",
  "COLORSET_10_VEC",
  "COLORSET_11_VEC",
  "COLORSET_12_VEC",
  "COLORSET_13_VEC",
  "COLORSET_14_VEC",
  "COLORSET_15_VEC",
  "COLORSET_16_VEC",
  "COLORSET_17_VEC",
  "COLORSET_18_VEC",
  "COLORSET_19_VEC",
  "COLORSET_20_VEC",
  "COLLECTION_COLOR_01",
  "COLLECTION_COLOR_02",
  "COLLECTION_COLOR_03",
  "COLLECTION_COLOR_04",
  "COLLECTION_COLOR_05",
  "COLLECTION_COLOR_06",
  "COLLECTION_COLOR_07",
  "COLLECTION_COLOR_08",
  "SEQUENCE_COLOR_01",
  "SEQUENCE_COLOR_02",
  "SEQUENCE_COLOR_03",
  "SEQUENCE_COLOR_04",
  "SEQUENCE_COLOR_05",
  "SEQUENCE_COLOR_06",
  "SEQUENCE_COLOR_07",
  "SEQUENCE_COLOR_08",
  "SEQUENCE_COLOR_09",
  "EVENT_A",
  "EVENT_B",
  "EVENT_C",
  "EVENT_D",
  "EVENT_E",
  "EVENT_F",
  "EVENT_G",
  "EVENT_H",
  "EVENT_I",
  "EVENT_J",
  "EVENT_K",
  "EVENT_L",
  "EVENT_M",
  "EVENT_N",
  "EVENT_O",
  "EVENT_P",
  "EVENT_Q",
  "EVENT_R",
  "EVENT_S",
  "EVENT_T",
  "EVENT_U",
  "EVENT_V",
  "EVENT_W",
  "EVENT_X",
  "EVENT_Y",
  "EVENT_Z",
  "EVENT_SHIFT",
  "EVENT_CTRL",
  "EVENT_ALT",
  "EVENT_OS",
  "EVENT_F1",
  "EVENT_F2",
  "EVENT_F3",
  "EVENT_F4",
  "EVENT_F5",
  "EVENT_F6",
  "EVENT_F7",
  "EVENT_F8",
  "EVENT_F9",
  "EVENT_F10",
  "EVENT_F11",
  "EVENT_F12",
  "EVENT_ESC",
  "EVENT_TAB",
  "EVENT_PAGEUP",
  "EVENT_PAGEDOWN",
  "EVENT_RETURN",
  "EVENT_SPACEKEY"
]
SamiaSamia

オブジェクトのタイプ別にアイコンの表示を変えたい場合、以下のようにタイプを文字列に変換してアイコン名を取得する。

icon = "OUTLINER_OB_%s" % str(item.type)
SamiaSamia

「object_eval.data」からモディファイア適用後のデータが取得できる。

https://docs.blender.org/api/current/bpy.types.Depsgraph.html

SamiaSamia
import bpy


def execute():
    active_object = bpy.context.active_object
    if active_object and active_object.type == "MESH":
        depsgraph = bpy.context.evaluated_depsgraph_get()
        object_eval = active_object.evaluated_get(depsgraph)
        mesh_eval = object_eval.data
        
        # モディファイア適用後の頂点の総数が取得できる
        print("Number of evaluated vertices:", len(mesh_eval.vertices))


if __name__ == "__main__":
    execute()
SamiaSamia
import bpy
import mathutils


def execute():
    active_object = bpy.context.active_object
    if active_object and active_object.type == "MESH":
        depsgraph = bpy.context.evaluated_depsgraph_get()
        object_eval = active_object.evaluated_get(depsgraph)
        mesh_eval = object_eval.data

        v1 = []
        for vt in active_object.data.vertices:
            x = object_eval.closest_point_on_mesh(vt.co)
            if x[0]:
                # 元の頂点の位置と比較したモディファイア適用後の最近接頂点の位置が取得できる
                print(vt.index, x[1])
                v1.append(x)


if __name__ == "__main__":
    execute()
SamiaSamia
    @staticmethod
    def filter_items_by_type(bitflag: int, items: List[Any], data_type, flags: List[int] = None, reverse: bool = False):
        flags = flags if flags else [0] * len(items)
        item: Any
        for i, item in enumerate(items):
            flags[i] = bitflag if isinstance(item.data, data_type) and item.select_get() else 0
        return flags.reverse() if reverse else flags
SamiaSamia
blender --help
Render Options
-b or --background
        Run in background (often used for UI-less rendering).

-a or --render-anim
        Render frames from start to end (inclusive).

-S or --scene <name>
        Set the active scene <name> for rendering.

-f or --render-frame <frame>
        Render frame <frame> and save it.

        * +<frame> start frame relative, -<frame> end frame relative.
        * A comma separated list of frames can also be used (no spaces).
        * A range of frames can be expressed using '..' separator between the first and last frames (inclusive).


-s or --frame-start <frame>
        Set start to frame <frame>, supports +/- for relative frames too.

-e or --frame-end <frame>
        Set end to frame <frame>, supports +/- for relative frames too.

-j or --frame-jump <frames>
        Set number of frames to step forward after each rendered frame.

-o or --render-output <path>
        Set the render path and file name.
        Use '//' at the start of the path to render relative to the blend-file.

        The '#' characters are replaced by the frame number, and used to define zero padding.

        * 'animation_##_test.png' becomes 'animation_01_test.png'
        * 'test-######.png' becomes 'test-000001.png'

        When the filename does not contain '#', The suffix '####' is added to the filename.

        The frame number will be added at the end of the filename, eg:
        # blender -b animation.blend -o //render_ -F PNG -x 1 -a
        '//render_' becomes '//render_####', writing frames as '//render_0001.png'

-E or --engine <engine>
        Specify the render engine.
        Use '-E help' to list available engines.

-t or --threads <threads>
        Use amount of <threads> for rendering and other operations
        [1-1024], 0 for systems processor count.
Format Options
-F or --render-format <format>
        Set the render format.
        Valid options are:
        'TGA' 'RAWTGA' 'JPEG' 'IRIS' 'IRIZ' 'AVIRAW' 'AVIJPEG' 'PNG' 'BMP'

        Formats that can be compiled into Blender, not available on all systems:
        'HDR' 'TIFF' 'OPEN_EXR' 'OPEN_EXR_MULTILAYER' 'MPEG' 'CINEON' 'DPX' 'DDS' 'JP2'

-x or --use-extension <bool>
        Set option to add the file extension to the end of the file.
Animation Playback Options
-a <options> <file(s)>
        Instead of showing Blender's user interface, this runs Blender as an animation player,
        to view movies and image sequences rendered in Blender (ignored if '-b' is set).

        Playback Arguments:

        -p <sx> <sy>
                Open with lower left corner at <sx>, <sy>.
        -m
                Read from disk (Do not buffer).
        -f <fps> <fps-base>
                Specify FPS to start with.
        -j <frame>
                Set frame step to <frame>.
        -s <frame>
                Play from <frame>.
        -e <frame>
                Play until <frame>.
        -c <cache_memory>
                Amount of memory in megabytes to allow for caching images during playback.
                Zero disables (clamping to a fixed number of frames instead).
Window Options
-w or --window-border
        Force opening with borders.

-W or --window-fullscreen
        Force opening in fullscreen mode.

-p or --window-geometry <sx> <sy> <w> <h>
        Open with lower left corner at <sx>, <sy> and width and height as <w>, <h>.

-M or --window-maximized
        Force opening maximized.

-con or --start-console
        Start with the console window open (ignored if '-b' is set), (Windows only).

--no-native-pixels
        Do not use native pixel size, for high resolution displays (MacBook 'Retina').

--no-window-focus
        Open behind other windows and without taking focus.
Python Options
-y or --enable-autoexec
        Enable automatic Python script execution.

-Y or --disable-autoexec
        Disable automatic Python script execution (pydrivers & startup scripts), (compiled as non-standard default).


-P or --python <filename>
        Run the given Python script file.

--python-text <name>
        Run the given Python script text block.

--python-expr <expression>
        Run the given expression as a Python script.

--python-console
        Run Blender with an interactive console.

--python-exit-code <code>
        Set the exit-code in [0..255] to exit if a Python exception is raised
        (only for scripts executed from the command line), zero disables.

--python-use-system-env
        Allow Python to use system environment variables such as 'PYTHONPATH' and the user site-packages directory.

--addons <addon(s)>
        Comma separated list (no spaces) of add-ons to enable in addition to any default add-ons.
Logging Options
--log <match>
        Enable logging categories, taking a single comma separated argument.
        Multiple categories can be matched using a '.*' suffix,
        so '--log "wm.*"' logs every kind of window-manager message.
        Sub-string can be matched using a '*' prefix and suffix,
        so '--log "*undo*"' logs every kind of undo-related message.
        Use "^" prefix to ignore, so '--log "*,^wm.operator.*"' logs all except for 'wm.operators.*'
        Use "*" to log everything.

--log-level <level>
        Set the logging verbosity level (higher for more details) defaults to 1,
        use -1 to log all levels.

--log-show-basename
        Only show file name in output (not the leading path).

--log-show-backtrace
        Show a back trace for each log message (debug builds only).

--log-show-timestamp
        Show a timestamp for each log message in seconds since start.

--log-file <filename>
        Set a file to output the log to.
Debug Options
-d or --debug
        Turn debugging on.

        * Enables memory error detection
        * Disables mouse grab (to interact with a debugger in some cases)
        * Keeps Python's 'sys.stdin' rather than setting it to None

--debug-value <value>
        Set debug value of <value> on startup.


--debug-events
        Enable debug messages for the event system.

--debug-ffmpeg
        Enable debug messages from FFmpeg library.

--debug-handlers
        Enable debug messages for event handling.

--debug-libmv
        Enable debug messages from libmv library.

--debug-cycles
        Enable debug messages from Cycles.

--debug-memory
        Enable fully guarded memory allocation and debugging.

--debug-jobs
        Enable time profiling for background jobs.

--debug-python
        Enable debug messages for Python.

--debug-depsgraph
        Enable all debug messages from dependency graph.

--debug-depsgraph-eval
        Enable debug messages from dependency graph related on evaluation.

--debug-depsgraph-build
        Enable debug messages from dependency graph related on graph construction.

--debug-depsgraph-tag
        Enable debug messages from dependency graph related on tagging.

--debug-depsgraph-no-threads
        Switch dependency graph to a single threaded evaluation.

--debug-depsgraph-time
        Enable debug messages from dependency graph related on timing.

--debug-depsgraph-pretty
        Enable colors for dependency graph debug messages.

--debug-depsgraph-uuid
        Verify validness of session-wide identifiers assigned to ID datablocks.

--debug-ghost
        Enable debug messages for event handling.

--debug-gpu
        Enable GPU debug context and information for OpenGL 4.3+.

--debug-gpu-force-workarounds
        Enable workarounds for typical GPU issues and disable all GPU extensions.

--debug-wm
        Enable debug messages for the window manager, shows all operators in search, shows keymap errors.

--debug-xr
        Enable debug messages for virtual reality contexts.
        Enables the OpenXR API validation layer, (OpenXR) debug messages and general information prints.

--debug-xr-time
        Enable debug messages for virtual reality frame rendering times.

--debug-all
        Enable all debug messages.

--debug-io
        Enable debug messages for I/O (Collada, ...).


--debug-fpe
        Enable floating-point exceptions.

--debug-exit-on-error
        Immediately exit when internal errors are detected.

--disable-crash-handler
        Disable the crash handler.

--disable-abort-handler
        Disable the abort handler.

--verbose <verbose>
        Set the logging verbosity level for debug messages that support it.
Misc Options
--open-last
        Open the most recently opened blend file, instead of the default startup file.

--app-template <template>
        Set the application template (matching the directory name), use 'default' for none.

--factory-startup
        Skip reading the BLENDER_STARTUP_FILE in the users home directory.

--enable-event-simulate
        Enable event simulation testing feature 'bpy.types.Window.event_simulate'.


--env-system-datafiles
        Set the BLENDER_SYSTEM_DATAFILES environment variable.

--env-system-scripts
        Set the BLENDER_SYSTEM_SCRIPTS environment variable.

--env-system-python
        Set the BLENDER_SYSTEM_PYTHON environment variable.


-noaudio
        Force sound system to None.

-setaudio
        Force sound system to a specific device.
        'None' 'SDL' 'OpenAL' 'CoreAudio' 'JACK' 'PulseAudio' 'WASAPI'.


-h or --help
        Print this help text and exit.

/?
        Print this help text and exit (Windows only).

-R
        Register blend-file extension, then exit (Windows only).

-r
        Silently register blend-file extension, then exit (Windows only).

-v or --version
        Print Blender version and exit.

--
        End option processing, following arguments passed unchanged. Access via Python's 'sys.argv'.
Other Options
--debug-freestyle
        Enable debug messages for Freestyle.


Argument Parsing:
        Arguments must be separated by white space, eg:
        # blender -ba test.blend
        ...will exit since '-ba' is an unknown argument.
Argument Order:
        Arguments are executed in the order they are given. eg:
        # blender --background test.blend --render-frame 1 --render-output '/tmp'
        ...will not render to '/tmp' because '--render-frame 1' renders before the output path is set.
        # blender --background --render-output /tmp test.blend --render-frame 1
        ...will not render to '/tmp' because loading the blend-file overwrites the render output that was set.
        # blender --background test.blend --render-output /tmp --render-frame 1
        ...works as expected.
Environment Variables
  $BLENDER_USER_CONFIG      Directory for user configuration files.
  $BLENDER_USER_SCRIPTS     Directory for user scripts.
  $BLENDER_SYSTEM_SCRIPTS   Directory for system wide scripts.
  $BLENDER_USER_DATAFILES   Directory for user data files (icons, translations, ..).
  $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.
  $BLENDER_SYSTEM_PYTHON    Directory for system Python libraries.
  $OCIO                     Path to override the OpenColorIO config file.
  $TEMP                     Store temporary files here.
SamiaSamia
環境変数 説明
$BLENDER_USER_CONFIG ユーザー設定ファイル用のディレクトリ。
$BLENDER_USER_SCRIPTS ユーザースクリプトのためのディレクトリ。
$BLENDER_SYSTEM_SCRIPTS システム全体のスクリプトのためのディレクトリ。
$BLENDER_USER_DATAFILES ユーザーデータファイル (アイコン、トランスレーションなど) のディレクトリ。
$BLENDER_SYSTEM_DATAFILES システム全体のデータファイルのためのディレクトリ。
$BLENDER_SYSTEM_PYTHON Python ライブラリ用のディレクトリ。
$OCIO Open Color IOの設定ファイルを上書きするためのパス。
$TEMP 一時ファイルを格納するディレクトリ。