Created
February 28, 2026 12:26
-
-
Save aspose-com-gists/8dc2bf083eaa11e0b6ed6852ccbfd135 to your computer and use it in GitHub Desktop.
How to Convert 3MF to STL in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.aspose.threed.cloud.ApiException; | |
| import com.aspose.threed.cloud.api.ThreeDApi; | |
| import com.aspose.threed.cloud.model.ConvertRequest; | |
| import com.aspose.threed.cloud.model.StlExportOptions; | |
| import java.io.IOException; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| public class Convert3mfToStl { | |
| public static void main(String[] args) { | |
| // Replace with your actual credentials | |
| String clientId = "YOUR_CLIENT_ID"; | |
| String clientSecret = "YOUR_CLIENT_SECRET"; | |
| // Input and output file names | |
| String inputFile = "model.3mf"; | |
| String outputFile = "model.stl"; | |
| try { | |
| // Initialize API client | |
| ThreeDApi api = new ThreeDApi(clientId, clientSecret); | |
| // Upload source 3MF file | |
| byte[] inputData = Files.readAllBytes(Paths.get(inputFile)); | |
| api.uploadFile(inputFile, inputData); | |
| // Set STL export options (binary, millimeter units) | |
| StlExportOptions exportOptions = new StlExportOptions(); | |
| exportOptions.setBinary(true); | |
| exportOptions.setUnit("millimeter"); | |
| api.setExportOptions(inputFile, exportOptions); | |
| // Create and execute conversion request | |
| ConvertRequest convertRequest = new ConvertRequest(inputFile, "stl"); | |
| api.convert(convertRequest); | |
| // Download the generated STL file | |
| byte[] stlData = api.downloadFile(outputFile); | |
| Files.write(Paths.get(outputFile), stlData); | |
| System.out.println("Conversion successful. STL saved as " + outputFile); | |
| } catch (ApiException e) { | |
| System.err.println("API error: " + e.getResponseBody()); | |
| } catch (IOException e) { | |
| System.err.println("File I/O error: " + e.getMessage()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment