Reputation: 91
What I am trying to do is import a .stl model into blender using a script (in python). I have tried using the command below but I can't seem to get it to work. The problem is I don't know the format of the "Filepath", "files", and "directory" part of the command.
bpy.ops.import_mesh.stl(filepath="", filter_glob="*.stl", files=None, directory="")
Can someone please show me how to get this working; that is all I ask.
bpy.ops.import_mesh.stl(filepath="C://Users//Dom//Documents//DomCorp.//mymodel.stl", filter_glob="*.stl", files=None, directory="")
When I write this I get this errror:
TypeError: Converting py args to operator properties: IMPORT_MESH_OT_stl.files expected a each sequence member to be a dict for an RNA collection, not str
Since I am fairly new to programming I don't know what it means so can someone help and explain it and possibly come up with a fix?? :)
Upvotes: 5
Views: 10388
Reputation: 8022
The import_mesh library was deprecated with version 4 of blender (November, 2023). The new function to do the same thing:
import bpy
bpy.ops.wm.stl_import(filepath="/path/to/file.stl")
See the docs.
Upvotes: 2
Reputation: 2213
The "filepath" parameter should be sufficient as the others are optional:
bpy.ops.import_mesh.stl(filepath="C://Users//Dom//Documents//DomCorp//mymodel.stl")
Upvotes: 7
Reputation: 91
I have managed to work this out!! :D
This seems to work:
bpy.ops.import_mesh.stl(filepath="C://Users//Dom//Documents//DomCorp.//mymodel.stl", filter_glob="*.stl", files=[{"name":"mymodel.stl", "name":"mymodel.stl"}], directory="C://Users//Dom//Documents//DomCorp.")
Upvotes: 4