1
$\begingroup$

I have defined a StringProperty as:
StrParents = StringProperty(default='-1 ',update= GetParent), and used prop to display the property in a panel as: layout.prop(item, 'StrParents', text='parents').

I would like now to make some actions (i.e: call a function X()) if the StringProperty was changed from inside the code. And doing another action (i.e:call a function Y()) if the StringProperty was changed from the user via the panel.

How can I achieve such that requirement?

$\endgroup$
2
$\begingroup$

I suggest looking at the context properties, for instance in this example context.area.type. If scene.x is changed in the console it prints CONSOLE, a panel in the properties panel PROPERTIES etc. As a test, print the context.copy() dictionary to find what suits for your needs.

import bpy

from bpy.props import StringProperty

def goober(self, context):
    print(context.area.type)
    return None

bpy.types.Scene.x = StringProperty(update=goober)
$\endgroup$
  • $\begingroup$ Good thinking. Keep in mind that context overriding can be used to simulate a different area (so does temporarily changing the area.type). $\endgroup$ – CoDEmanX Sep 9 '15 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.