I have been working on a Blender script that is meant to pick a from a list of strings and output it to a UI panel via label when an operator button is pressed by the user. However, the label in the panel does not update from whatever it is set to initially when I change the string variable in the code.
How could I go about updating this label or the panel from the script?
Do you have a draw() function? You’ll need one for that update to occur. Here’s one way to do it:
class OBJECT_PT_<PanelName>(Panel):
...
@classmethod
def poll(self,context):
return context.object is not None
def draw(self, context):
layout = self.layout
scene = context.scene
subcolumn = layout.column()
subrow = layout.row(align=True)
subrow.label(text="<prop_reference>")
Another good option (I like having a Global variable storage class, it makes things a lot easier):
class Globals():
var = <default value>
#update var on operator execute()
g = Globals()
...
class OBJECT_PT_<PanelName>(Panel):
...
@classmethod
def poll(self,context):
return context.object is not None
def draw(self, context):
layout = self.layout
scene = context.scene
subcolumn = layout.column()
subrow = layout.row(align=True)
subrow.label(text=g.var)
I have the draw function for the panel but there is no update after it is initially drawn. Is there a way to redraw all or part of it somehow? Or do I need to define the variables differently?
These are the string variables before they are redefined by the operator:
# strings to output to panel
ideaOutput1 = "default"
ideaOutput2 = "default2"
After the operator button is pressed and the string variables are changed, the output labels do not change:
The script is meant to select random list items and output them at the bottom there.
Hello ! I think you are changing the prop in a local scope which doesnt modify the global one. Would you mind copy pasting the content of your execute method ?