I’m trying to make my import plugin obey the ‘Object, Action, Settings’ UI model - that is, the import should happen with default settings (after choosing a file), but the property panel should remain in the Tool area to allow one to tweak the settings and reimport with those new settings.
There is a very nice tutorial for this here
However I don’t understand what is happening well enough to adapt this to the case where one of the properties needs to be a file picked by the file selector. My current code for the import operator has:
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {"RUNNING_MODAL"}
def execute(self, context):
self.action(context)
return {"FINISHED"}
where ‘action’ does the work of making a new object based on the current properties from the tool panel and leaving the object selected. With this code, choosing the operator from the menu causes the modal file selector to pop up, and when you push the import button on that, it does all of the work and the tool panel properties go away.
In one attempt to imitate the above tutorial, I put the filepath property (a string property, with subtype = ‘FILE_PATH’) into the draw method - then it shows up with a little file selector box you can use to select the file. Then I changed the invoke code to:
def invoke(self, context, event):
self.action(context)
return {"FINISHED"}
This sort of works. Now when you pick the menu entry, it does nothing except put up the properties in the tool panel. If I then choose a file for the filepath property, nothing happens - why? If I make any change at all to another parameter, then it does as expected: the import happens and the panel stays up so that if I change another parameter it reimports with the new parameters, as desired.
I have two questions/problems:
- Why does nothing happen when you just choose a file? What changes in the property panel cause the operator’s execute function to be called again?
- It is clunky not to have the menu operation go straight to the file selector window. How can I have that happen, yet chain into code that leaves the panel up for further tweaking? What is it about returning ‘RUNNING_MODAL’ from invoke after adding file_select to the window manager that causes the desired behavior of the property panel hanging around not to work any more?
- Does anyone know of any example code that accomplishes what I am trying to do - that is, go straight to a file selector when an operator is first invoked but then leave the property panel up so that the operator will be re-executed every time the user changes a property?