When I start blender, create an e.g. cube and want to export this cube as obj I do this via:
File -> Export -> Wavefront (.obj)
In the opened export dialog I see e.g. besides the last used file location the OBJ export properties like: Selection Only, Animation etc.
These properties are defined in "<<blender location>>/scripts/addons/io_scene_obj/__init__.py" where the ExportOBJ class is registered as operator I think.

If I export my scene as OBJ via the Wavefront (.obj) UI dialog blender saves the last set property state values like Selection Only.

enter image description here

How can I get those property values in a python script? So for the Selection Only a boolean like:
selection_only = bpy.ops.export_scene.obj.use_selection


1 Answer 1


Window manager methods

Prior to running python console code below I have exported the scene to wavefront obj, set a filepath and chosen use selection.

>>> wm = C.window_manager

>>> props = wm.operator_properties_last("export_scene.obj")

Running auto-complete props.CtrlSpace

>>> props.

          ... cut for brevity...

>>> props.

Can get any property value

>>> props.use_uvs

This is the default value for use_uvs

If however we iterate over items, will get those values last used that are non default.

>>> for k, v in props.items():
...     k, v
('filepath', '/home/batfinger/Desktop/untitled.obj')
('use_selection', 1)

To run the operator again using the same properties from code could simply make this a dictionary and pass it to the operator as kwargs

>>> d = {k : v for k, v in props.items()} # or d = dict(props.items())
>>> bpy.ops.export_scene.obj(**d)
Progress:   0.00%
    (  0.0003 sec |   0.0000 sec) OBJ Export path: '/home/batfinger/Desktop/untitled.obj'
Progress:   0.00%
Progress:   8.33%
Progress:  16.67%
Progress:  25.00%
Progress:  33.33%
Progress:  41.67%
Progress:  50.00%
          (  0.0044 sec |   0.0034 sec) Finished writing geometry of 'Cube'.
Progress:  50.00%
Progress:  50.00%
Progress:  50.00%
      (  0.0058 sec |   0.0051 sec) Finished exporting geometry, now exporting materials
Progress: 100.00%
      (  0.0074 sec |   0.0067 sec) OBJ Export Finished
Progress: 100.00%
Progress: 100.00%
Progress: 100.00%
Progress: 100.00%

  • $\begingroup$ Thank you that's the solution :) I searched the whole web for a solution and browsed through the api docs. How did you know about it? $\endgroup$
    – schlegel11
    Jul 9, 2019 at 23:41

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.