728x90
반응형
- 개요
bpy에서는 report 함수를 사용하여 메세지를 생성할 수 있다
인자로는 type과 message를 사용하는데, message는 메세지에 담을 문구를 의미하고
type의 경우 메세지의 타입을 의미한다

사용가능한 type의 종류는 위와 같다
1) 메인 패널 클래스
...
import bpy
from bpy.types import Panel, Operator
class AI_PT_main_panel(Panel):
bl_label = "Main Panel"
bl_idname = "AI_PT_main_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "New Tab"
def draw(self, context):
layout = self.layout
layout.operator("ai.myop_operator")
...
메인 패널 클래스는 위와 같이 구성하였다
패널을 설정하는 draw 함수에서는 별다른 로직없이 operator만 설정하여 동작을 정의한다
2) Operator 클래스
...
class AI_OT_my_op(Operator):
bl_label = "Button"
bl_idname = "ai.myop_operator"
num : bpy.props.IntProperty(default=10)
def execute(self, context):
message = ("Number is %i" % self.num)
self.report({'INFO'}, message)
return {'FINISHED'}
...
Operator 클래스는 위와 같이 구성하였다
동작을 정의하는 execute 함수의 로직은 다음과 같다
operator가 동작하면 report 함수를 호출하여 INFO 타입의 메세지를 num 프로퍼티와 같이 생성한다
3) 클래스의 등록 / 등록해제
...
classes = [AI_PT_main_panel, AI_OT_my_op]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
생성한 클래스를 등록 / 등록해제한다
- 최종 실행 결과
728x90
반응형