i did a small operators panel and check out the number of times it’s being executed
after doing a selection in menu from panel
i can see it being run like 3 or 4 times before stopping
so is there a way to run it only ounce?
i got some script functions with lot’s of calculations which takes times
so if this is run more then ounce then it’s gone take a lot of time to get results ?
here is the little test script i did
import bpy
from bpy.props import *
# For the non-operator menus, define their values like this:
bpy.types.Scene.EnumProperty(attr='method', name='Method', items=(
('1', 'One', 'The first item'),
('2', 'Two', 'The second item'),
('3', 'Three', 'The third item')), default='1')
# These are stored in the .blend
# And for one without a label before it make the first element the name
bpy.types.Scene.EnumProperty(attr='nameless', items=(
('0', 'Choose one', 'Choose one'),
('1', 'One', 'The first item'),
('2', 'Two', 'The second item'),
('3', 'Three', 'The third item')), default='1')
# For the operator menu this variable just stores the last operation called
last_method = 'None'
class myPanel(bpy.types.Panel): # This is the panel
'''Panel'''
bl_label = "Data here" # Called this
bl_space_type = "VIEW_3D" # in 3D view
# bl_region_type = "TOOLS" # in tool shelf
bl_region_type = "TOOL_PROPS"
def draw(self, context):
global last_method # make this global to find the last operation
layout = self.layout
col = layout.column()
col.label(' Menu fo rDATA:', 'LAMP_DATA')
col.operator_menu_enum('view_3d.my_operator', 'method', 'Menu Selection')
# Here the operator menu is displayed
# 'view_3d.my_operator' is the bl_idname of the operator called
col.label(' Last: ' + last_method, 'QUESTION')
print ('Method =',last_method,' Val =',eval(last_method))
if eval(last_method)==1:
col.label(' Polar Graph', 'FCURVE')
print (' selected polar graph1')
elif last_method==2:
pass
class myOperator(bpy.types.Operator): # When an option in the operator menu is clicked, this is called
'''Operator'''
bl_idname = 'view_3d.my_operator'
bl_label = 'Operator'
# Define possible operations
method = EnumProperty(items=(
('1', 'Polar Graph', 'The first item'),
('2', 'Lu Curve', 'The second item'),
('3', 'Lamps', 'The third item')))
def execute(self, context):
global last_method # Make global so we can later draw it in the panel
last_method = self.properties.method # Store the choosen operation
return {'FINISHED'}
def register():
bpy.types.register(myOperator)
bpy.types.register(myPanel)
def unregister():
bpy.types.unregister(myOperator)
bpy.types.unregister(myPanel)
if __name__ == "__main__":
pass
i added some print to show on the console
and after selecting in menu you can see several loop !
Thanks for any help