Hello everyone!
New here and just found about this group.
I’m trying to develop my own add-on for blender, like most of you, and I fail stupidly in the basics…
so to explain : I have 3 files, one for the init, one for the operators and one for the panels.
In the init, I register my files as such :
import bpy
from . nbe_op import NBE_OT_Greeblies_Finisher,
from . nbe_pnl import NBE_PT_Panel_Greeblies_Finisher, NBE_PT_Property_Group
classes = (NBE_PT_Panel_Greeblies_Finisher,NBE_OT_Greeblies_Finisher)
def register():
bpy.utils.register_class(NBE_PT_Property_Group)
bpy.types.Scene.custom_props = bpy.props.PointerProperty(type=NBE_PT_Property_Group)
for c in classes:
bpy.utils.register_class(c)
def unregister():
del bpy.types.Scene.custom_props
bpy.utils.unregister_class(NBE_PT_Property_Group)
for c in classes:
bpy.utils.unregister_class(c)
in the panel file (nbe_pnl), I define my elements as such
import bpy
from bpy.types import Panel,PropertyGroup
from bpy.props import EnumProperty
class NBE_PT_Panel_Nameplate_bender(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Nameplate Bender"
bl_category = "Nameplate Creator"
def draw(self, context):
layout = self.layout
col = layout.column()
params = context.scene.custom_props
# definition of the functions
row = layout.row()
col = row.column()
row = col.row()
row.prop(params, "nameplate_size")
class NBE_PT_Property_Group(PropertyGroup):
nameplate_size : EnumProperty(name = "Size", \
items = [('25mm', '25 mm', '25mm'),
('32mm', '32 mm', '32mm')], \
description = 'size of the basic nameplates')
class NBE_PT_Panel_Greeblies_Finisher(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Greeblies Finisher"
bl_category = "Nameplate Creator"
def draw(self, context):
layout = self.layout
col = layout.column()
params = context.scene.custom_props
# definition of the functions
row = layout.row()
col = row.column()
row = col.row()
row.prop(params, "nameplate_size")
And in my nbe_op.py I have this code :
import bpy,os
from bpy.types import Operator
def finish_greeblie(obj,params):
pass
class NBE_OT_Greeblies_Finisher(Operator):
bl_idname = "object.greeblies_finisher"
bl_label = "Greeblies Finisher"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
params = (
context.scene.nameplate_size,
)
for obj in bpy.context.selected_objects:
finish_greeblie(obj, params)
return {'FINISHED'}
When I try to execute my code, I get this error:
Python: Traceback (most recent call last):
File “C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\Nameplate_bender\nbe_op.py”, line xxx, in execute
context.scene.nameplate_size,
AttributeError: ‘Scene’ object has no attribute ‘nameplate_size’
location: :-1
Error: Python: Traceback (most recent call last):
File “C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\Nameplate_bender\nbe_op.py”, line xxx, in execute
context.scene.nameplate_size,
AttributeError: ‘Scene’ object has no attribute ‘nameplate_size’
location: :-1
What did I do wrong? It must be something trivial on my panel or my init, but I’m lost…