OBJ file is an end product of the 3D modeling process, usually generated by CAD software. It is a geometry definition file that contains vertex, vertex normals, vertices, etc. In certain cases, we may need to convert an OBJ file to STL format. The STL file contains information about 3D vector graphics. In this article, we will learn how to convert an OBJ file to STL format in Python.
This article shall cover the following topics:
- Python OBJ to STL Converter – Free Download
- Steps to Convert OBJ to STL
- Convert OBJ File to STL
- Convert OBJ to STL With Options in Python
Python OBJ to STL Converter – Free Download
For converting an OBJ to STL, we will be using the Aspose.3D for Python API. It allows the conversion of various 3D file formats. The API also supports working with geometry & scene hierarchy and animating objects in a 3D Scene.
The Scene class of the API is a top-level object that contains the nodes, geometries, materials, textures, animation, poses, sub-scenes, etc. The from_file(string) method of this class opens the scene from a given file path. It also provides the save(string, SaveOptions) method that saves the scene to the specified path. The StlSaveOptions class of the API allows specifying save options for STL format.
Please either download the package or install the API from PyPI using the following pip command in the console:
pip install aspose-3d
How to Convert OBJ to STL
We can easily convert an OBJ file to STL format by following the steps given below:
- Load an OBJ file.
- Specify STL save options.
- Save OBJ as an STL.
The following section describes how to transform these steps into Python code and convert an OBJ file to an STL format.
Convert OBJ to STL using Python
We can convert an OBJ file to an STL format by following the steps given below:
- Firstly, load an input OBJ file using the Scene.from_file() method.
- After that, create an instance of the StlSaveOptions class.
- Finally, call the save() method to save it as an STL. It takes the output STL file path and StlSaveOptions as arguments.
The following code sample shows how to convert OBJ to STL in Python.
Convert OBJ to STL With Options in Python
We can specify the STL save options while converting an OBJ file to an STL format by following the steps given below:
- Firstly, load an input OBJ file using the Scene.from_file() method.
- Next, create an instance of the StlSaveOptions class.
- After that, specify STL save options such as flip_coordinate_system, lookup_paths, etc.
- Finally, call the save() method to save it as an STL. It takes the output STL file path and StlSaveOptions as arguments.
The following code sample shows how to convert OBJ to STL with STL save options in Python.
Get Free Temporary License
You can get a free temporary license to try Aspose.3D for Python without evaluation limitations.
Try Online
Please try the following free online OBJ to STL conversion tool, which is developed using the above API.
https://products.aspose.app/3d/conversion/obj-to-stl
Conclusion
In this article, we have learned how to convert OBJ to STL using Python. We have also seen how to specify various STL save options programmatically. Besides, you can learn more about Aspose.3D for Python API using documentation. In case of any ambiguity, please feel free to contact us on our free support forum.