how do i do this?

i’ve been trying to breakdown and recreate that old IK FK snap script that bassam kudali made for blender 2.56 but being a total script kitty i’ve hit a stumbling block with making some simple buttons, im just trying to make a buttom that’ll print hello or something to the console

heres my code

import bpy


class snapTryPanel(bpy.types.Panel):
    bl_label = "Snap try"
    bl_space_type = "VIEW_3D"                                             
    bl_region_type = "UI" 
    
    
    def draw(self, context):
        layout = self.layout
        col = layout.column()
        row = col.row(align=True)
        
        row.operator("helloOperator", text="test")


class helloOperator(bpy.types.Operator):
    bl_idname = "test"
    
    def execute(self, context):
        print("test this class")
        return {'FINISHED'}


def register():
    bpy.utils.register_class(helloOperator)


##########################################
def register():
    bpy.utils.register_class(snapTryPanel)

def unregister():
    bpy.utils.unregister_class(snapTryPanel)


if __name__ == "__main__":
    register()

and heres the error i keep getting

search for unknown operator ‘helloOperator’, ‘helloOperator’
uiItemFullO: ‘helloOperator’ unknown operator
/Users/snowcovered/Desktop/myprojects/3dStuff/JAM_ProprietaryLibrary/specialThangZ/tests/scripts/snapTry.blend/snap.py:15

if anyone’s curious about the bassam kurdali script, ive attached his file here

Attachments

IK_FK_Snap-03.blend (439 KB)

Well, for one, you’ve defined your register() function twice. Try replacing the last 12 lines of your script with the following:

def register():
    bpy.utils.register_class(helloOperator)
    bpy.utils.register_class(snapTryPanel)

def unregister():
    bpy.utils.unregister_class(helloOperator)
    bpy.utils.unregister_class(snapTryPanel)

if __name__ == "__main__":
    register()

thanks, that’s one problem down. im still getting basically the same error tho, i don’t really know why but i keep getting this "search for unknown operator ‘helloOperator’, ‘helloOperator’ "

 
import bpy

class snapTryPanel(bpy.types.Panel):
    bl_idname = "snapTryPanel"
    bl_label = "Snap try"
    bl_space_type = "VIEW_3D"                                             
    bl_region_type = "UI" 
    
    def draw(self, context):
        layout = self.layout
        col = layout.column()
        row = col.row(align=True)
        
        row.operator("helloOperator", text="test")


class helloOperator(bpy.types.Operator):
    bl_idname = "wm.test"
    bl_label = "helloOperator"
    
    
    def execute(self, context):
        print("test this class")
        return {'FINISHED'}

##########################################
def register():
    bpy.utils.register_class(helloOperator)
    bpy.utils.register_class(snapTryPanel)

def unregister():
    bpy.utils.unregister_class(helloOperator)
    bpy.utils.unregister_class(snapTryPanel)

if __name__ == "__main__":
    register()
    
class helloOperator(bpy.types.Operator):
    bl_idname = "wm.test" # This is your operator name that should be called

Just rename it as you want keeping in mind that it should contain “.” char.
So it will be smth like

bl_idname = "myops.helloOperator"

then you can use it as

row.operator("myops.helloOperator", text="test")

thanks a ton guys, it’s working now. its kinda useless but maybe some other script kitty might want it to learn more about making these scripts or something

i

mport bpy

class cubeButtonPanel(bpy.types.Panel):
    bl_label = "adds A Cube BTN"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row.operator("myops.dothis", text = "this adds a cube")
        
        
class operation(bpy.types.Operator):
    bl_idname = "myops.dothis"
    bl_label  = "operation"

    def execute(self, context):
        print("this is a statement")
        bpy.ops.mesh.primitive_cube_add()
        
        return{'FINISHED'}
        
def register():
    bpy.utils.register_class(cubeButtonPanel)
    bpy.utils.register_class(operation)

def unregister():
    bpy.utils.unregister_class(cubeButtonPanel)
    bpy.utils.unregister_class(operation)


if __name__ == "__main__":
    register()