Convert step to usd with python code


I am trying to write a converter for converting a .STEP file to a .USB file. I want to make this a standalone application with python. I know that it is possible in the GUI of Isaac Sim but I want to do it in a standalone application. Is that possible?

Thanks in advance.

Hi @nickbakker40 - Yes, it is possible to write a standalone application to convert a .STEP file to a .USD file using the Omniverse Kit SDK. However, it’s important to note that the conversion process involves a few steps and requires a good understanding of both the STEP and USD file formats.

Here’s a high-level overview of the process:

  1. Import the STEP file: You can use a library like pythonOCC or FreeCAD to import the STEP file and access its geometric and topological data.

  2. Create a new USD stage: Use the pxr.Usd.Stage API to create a new USD stage.

  3. Convert the STEP data to USD: This is the most complex part of the process. You’ll need to iterate over the geometric and topological data in the STEP file and create corresponding USD prims in the USD stage. The specifics of this process will depend on the complexity of your STEP files and how much detail you want to preserve in the USD file.

  4. Save the USD stage: Once you’ve created all the necessary USD prims, you can save the USD stage to a .usd file using the Save method of the pxr.Usd.Stage API.

Here’s a very basic example of how you might structure your application:

import FreeCAD
import Part
from pxr import Usd, UsdGeom

# Import the STEP file
doc = FreeCAD.newDocument()"path/to/your/file.step", doc.Name)

# Create a new USD stage
stage = Usd.Stage.CreateNew("path/to/your/file.usd")

# Convert the STEP data to USD
for obj in doc.Objects:
    if obj.TypeId == "Part::Feature":
        shape = obj.Shape
        # Convert the shape to a USD prim and add it to the stage
        # ...

# Save the USD stage

This is a very simplified example and doesn’t include the actual conversion of the STEP data to USD. The specifics of that process will depend on your particular use case and may require a good deal of custom code.

Please note that the CAD Importer extension in Omniverse Kit provides a GUI-based tool for importing CAD files (including STEP files) into a USD stage. If you’re looking to automate this process, you might consider using the Omniverse Kit SDK to create a custom extension that uses the CAD Importer extension to perform the conversion.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.