First time here! So, I'm trying to create a python script that uses bpy (This script is not being used from within blender, but rather bpy is being called from python as a module), and in this script I am trying to import a mesh into the scene. However, I cannot figure out the correct usage of "bpy.ops.import_mesh.stl". I have the following block of code:
print("Importing mesh...")
bpy.ops.import_mesh.stl(filepath="Meshes/cm.stl")
print("Mesh imported!")
But when I try to run this code, this is what I see in the terminal:
Importing mesh...
Traceback (most recent call last):
File "C:\Users\Browser\Desktop\blendTest\blend_mesh_test.py", line 220, in <module>
import_stl()
File "C:\Users\Browser\Desktop\blendTest\blend_mesh_test.py", line 11, in import_stl
bpy.ops.import_mesh.stl(filepath="Meshes/mesh.stl")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Browser\Desktop\blendTest\myEnv\Lib\site-packages\bpy\4.3\scripts\modules\bpy\ops.py", line 109, in __call__
ret = _op_call(self.idname_py(), kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: Calling operator "bpy.ops.import_mesh.stl" error, could not be found
In case it was because I was entering the filepath incorrectly, I also tried with the absolute file path:
print("Importing mesh...")
bpy.ops.import_mesh.stl(filepath="c:/Users/Browser/Desktop/blendTest/Meshes/cm.stl")
print("Mesh imported!")
But that just comes up with the same error:
Importing mesh...
Traceback (most recent call last):
File "C:\Users\Browser\Desktop\blendTest\blend_mesh_test.py", line 220, in <module>
import_stl()
File "C:\Users\Browser\Desktop\blendTest\blend_mesh_test.py", line 11, in import_stl
bpy.ops.import_mesh.stl(filepath="c:/Users/Browser/Desktop/blendTest/Meshes/cm.stl")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Browser\Desktop\blendTest\myEnv\Lib\site-packages\bpy\4.3\scripts\modules\bpy\ops.py", line 109, in __call__
ret = _op_call(self.idname_py(), kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: Calling operator "bpy.ops.import_mesh.stl" error, could not be found
It doesn't seem like I'm calling the function correctly, and I have no idea what the problem could be. Would anyone happen to have an idea as to what I might be doing wrong? Thank you so much in advance!
blender myblendfile --python myscript.py
like this? Where the code is inside myscript.py or how do you execute your script then if not within Blender? Or is it called when you run an operator, perhaps from the File > Import menu? $\endgroup$bpy.ops.wm.stl_import
: docs.blender.org/api/current/… $\endgroup$