Last active
March 7, 2020 19:05
-
-
Save tomol/e344dea1462453b735c606967455d5cb to your computer and use it in GitHub Desktop.
3Dカーソルを動かすやつを2.8に対応
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
bl_info = { | |
"name": "カーソルを選択物のX座標が0の位置へ", | |
"author": "orokanaMyMol", | |
"version": (1, 0), | |
"blender": (2, 80, 1), | |
"location": "オブジェクト > スナップ", | |
"description": "3Dカーソルを選択部分の中心座標から,X座標のみ0の位置に移す.", | |
"warning": "", | |
"support": "TESTING", | |
"wiki_url": "", | |
"tracker_url": "", | |
"category": "3D View" | |
} | |
class TOOLS_OT_move_cursor(bpy.types.Operator): | |
bl_idname = "tools.move_cursor" | |
bl_label = "カーソル → 選択物のX座標が0" | |
bl_description = "カーソルを選択したオブジェクトの中心に配置した後,x座標のみを0にします." | |
bl_options = {'REGISTER', 'UNDO'} | |
# メニューを実行した時に呼ばれる関数 | |
def execute(self, context): | |
# カーソル位置の変更 | |
bpy.ops.view3d.snap_cursor_to_selected() | |
bpy.context.scene.cursor.location.x = 0 | |
# ピポットポイントをカーソルに変更 | |
for area in bpy.context.screen.areas: | |
if area.type == 'VIEW_3D': | |
for space in area.spaces: | |
if space.type == 'VIEW_3D': | |
bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR' | |
return {'FINISHED'} | |
# メニューを構築する関数 | |
def menu_fn(self, context): | |
self.layout.separator() | |
self.layout.operator(TOOLS_OT_move_cursor.bl_idname) | |
# Blenderに登録するクラス | |
classes = [ | |
TOOLS_OT_move_cursor, | |
] | |
# アドオン有効化時の処理 | |
def register(): | |
for c in classes: | |
bpy.utils.register_class(c) | |
bpy.types.VIEW3D_MT_snap.append(menu_fn) | |
print("Add-on '{}' is enabled".format(bl_info["name"])) | |
# アドオン無効化時の処理 | |
def unregister(): | |
bpy.types.VIEW3D_MT_snap.remove(menu_fn) | |
for c in classes: | |
bpy.utils.unregister_class(c) | |
print("Add-on '{}' is disabled".format(bl_info["name"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment