When I export manually I get the full STL but when I try using the Python API I get 1k (ie empty) files.

The code is quite complex (which I'm not a liberty to share at the moment) but its final piece is called Boundary

I execute the following lines of code to export the STL,

bpy.context.scene.objects.active = Boundary
bpy.ops.export_mesh.stl(filepath="C:/Users/User/Documents/Pyticle/Volume Blender/Bob.stl")

I saw some previous questions asking this but they all suggested that the geometry was not selected which is not the case here. That is unless I'm not selecting it properly?

(An aside, a decent NURBS interpreter, that is all)


2 Answers 2


It’s going to be hard to answer with so few info… STL exporter by default export all (geometry) object in active scene (only exporting selected ones is an option, disabled by default).

That said, here are some ideas to check:

  • Active is not selected, those two states are different and you may have an active but non-selected object (so you should also ensure you do Boundary.select = True in case you export only selected).
  • Your object must be linked in the active scene (context.scene.objects.link(Boundary)), otherwise you can select it or even (try to!) make it active, it won’t work.

I recently had and solved the same problem: in my Python API loop, some objects would export to STL files without a problem, and one would be exported empty. When I tried to export that one troublemaker manually, it worked fine.

The problem turned out to be that I had set the viewport visibility off for that particular object (to make fluid simulation results visible). That somehow had the effect of disassociating the object from the objects list of the scene. Turning the visibility back on solved the problem for me - so check that this isn't the case before you go in search of more elaborate solutions.

  • $\begingroup$ To be precise, making an object hidden also prevents it to be in context's 'selected' list (because an hidden item cannot be selected in Blender). $\endgroup$
    – mont29
    Jul 20, 2016 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .