Invoking an operator from the command line

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

damix
Posts: 21
Joined: Wed Dec 07, 2011 4:42 pm

Invoking an operator from the command line

Postby damix » Tue Oct 09, 2012 3:55 pm

Hello everybody. At the end of my export script I wrote:

bpy.ops.export_scene.dmx('INVOKE_DEFAULT')

because I want the file browser to pop up when I click 'Run Script' in the text editor. This works fine. Now I would like the same thing to happen when, instead of using the text editor, I pass the script as a command line argument:

blender -P DmxExporter.py file.blend

The resulting behaviour is quite strange; I would expect Blender to open, with the file browser of my exporter open in a way that I only need to click 'Export' button to actually save the exported scene. Instead, two Blender 3D windows open, seemingly in two different instances of Blender; and the two views are not the same: one looks at the object from the angle used last time the blend file was saved; the other is a Top view. If I switch the order of the arguments:

blender file.blend -P DmxExporter.py

I still get two windows, but the one that used to show the Top view now correctly shows the file browser.

How can I invoke the operator from command line, such that I get a single Blender window showing the export file browser?

Thank you for your help.

Dario

damix
Posts: 21
Joined: Wed Dec 07, 2011 4:42 pm

Maybe it does work...

Postby damix » Wed Oct 10, 2012 8:51 am

Actually, it seems like reversing the order of the arguments did the trick; I did not notice that it was working correctly because probably I saved the blend file when there were still two windows open after the previous attempt. So yes, the following command launches Blender at the file browser, ready to export file.blend:

blender file.blend -P DmxExporter.py


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests