Convert OBJ to STL Python

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:

  1. Python OBJ to STL Converter – Free Download
  2. Steps to Convert OBJ to STL
  3. Convert OBJ File to STL
  4. 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:

  1. Firstly, load an input OBJ file using the Scene.from_file() method.
  2. After that, create an instance of the StlSaveOptions class.
  3. 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:

  1. Firstly, load an input OBJ file using the Scene.from_file() method.
  2. Next, create an instance of the StlSaveOptions class.
  3. After that, specify STL save options such as flip_coordinate_system, lookup_paths, etc.
  4. 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.

See Also