operator and buttons not working anymore? 2.62

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

mafster
Posts: 4
Joined: Sat Mar 17, 2012 10:12 am
Location: New Zealand

operator and buttons not working anymore? 2.62

Postby mafster » Sat Mar 17, 2012 10:24 am

Hi just using Blender 2.6, seem the custom operators aren't working for me...

Just tested with the pingpong script

import bpy
# version 1.3.0
# tested on 31315


class OBJECT_PT_pingpong(bpy.types.Panel):
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
bl_label = "Ping Pong"

display = 0

def draw_header(self, context):
layout = self.layout
layout.label(text="", icon="PHYSICS")

def draw(self, context):
layout = self.layout
row = layout.row()
split = row.split(percentage=0.5)
colL = split.column()
colR = split.column()

if self.display == 0:
colL.operator("pipo", text="Ping")
else:
colR.operator("pipo", text="Pong")



bpy.utils.register_class(OBJECT_PT_pingpong)

This is all i get:
Image


all my custom buttons are doing the same, just the txt and nothing to click. Any ideas? Is this 2.6 problem?
....interesting....

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Sun Mar 18, 2012 11:05 am

What is “pipo”?

mafster
Posts: 4
Joined: Sat Mar 17, 2012 10:12 am
Location: New Zealand

Postby mafster » Sun Mar 18, 2012 6:59 pm

lol! sorry my bad....shoulda put the whole script. "pipo" is the class (Operator) id_name

class OBJECT_OT_pingpong(bpy.types.Operator):
bl_label = "PingPong operator"
bl_idname = "pipo"
bl_description = "Move the ball"

def invoke(self, context, event):
import bpy

self.report("INFO", "Moving the ball")
bpy.types.OBJECT_PT_pingpong.display = 1 - bpy.types.OBJECT_PT_pingpong.display
return{"FINISHED"}

thats what the previous def calls on.
....interesting....

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Mon Mar 19, 2012 1:49 am

Your bl_idname probably needs a prefix which is one of the valid subcategories defined in bpy.ops, e.g. “object.pipo” rather than just “pipo”.

Also I wouldn’t bother giving your class a magic xx_OT_xx-type name—it serves no purpose.

mafster
Posts: 4
Joined: Sat Mar 17, 2012 10:12 am
Location: New Zealand

Postby mafster » Mon Mar 19, 2012 7:42 am

Hmm that didnt work for me, im wondering do i have to register the operator class as well?
Well anyway that didnt work either. Its strange if i use any of the operators already created e.g. "object.armature_add" then it pops out a button with any problemos.
Seems rather wierd was working on previous versions.

:) fully agree with the whole magic thing...i wondered why so many people were doing that? Never used it in the past. Seems a bit convoluted to me

Well if anyone has had any luck with creating their own operators and having it run as a button would be keen to see your script
....interesting....

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Mon Mar 19, 2012 8:20 am

Yes, you have to register your operators. You want to see some sample code that works? Have a lookt at this: https://github.com/ldo/gimp_palettes_for_blender.

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Mon Mar 19, 2012 8:26 am

If you want a button example try this one: https://github.com/ldo/treadtiler.

mafster
Posts: 4
Joined: Sat Mar 17, 2012 10:12 am
Location: New Zealand

Postby mafster » Mon Mar 19, 2012 8:51 am

thanks peeps! mustv typed something wrong i tried again with register and it worked. Also had to have the operator sub category as well
....interesting....


Return to “Coding Blender”

Who is online

Users browsing this forum: No registered users and 1 guest