Can you export selected object to step?

Can you export selected objects to step?
From ScriptEditor Python to a file, when you have selected breps as guids.

step.py (1.6 KB)

I was able to export an stp file, I had to change some of the filepath code for it to work however.

# Original
here = pathlib.Path(__file__).parent.parent
fp_schoring_foot_0_json = here / "data" / "schoring_foot_0.json"
fp_schoring_foot_0_stp = here / "data" / "schoring_foot_0.stp"
# new
here = pathlib.Path(__file__).parent
print (here)

fp_schoring_foot_0_json = pathlib.Path("data", "schoring_foot_0.json")
fp_schoring_foot_0_stp = pathlib.Path(here, "data", "schoring_foot_0.stp")
print (fp_schoring_foot_0_json)
print (fp_schoring_foot_0_stp)

This line did nothing for me, looking at the API it makes sense as this method doesn’t take a list as an argument.

Rhino.FileIO.FileStp.Write(str(fp_schoring_foot_0_stp), brep_guids, Rhino.FileIO.FileStpWriteOptions())

It exports, but it exports all the objects in rhino file:

FileStp.Write method

But it does not allow export individual objects. Is there any workaround?

Ah I see.

You could use RhinoApp.RunScript("-Export "<destination>\<filename>.stp" _Enter"); to only export selected.

Or you could copy all the selected to a new headless RhinoDoc, pass that in as the args and then dispose of it.

As Callum writes. The objects need to be put in a headless doc first, then they can be written to a file.

The Grasshopper python sample on this page probably shows that best: Rhino - Code-Driven File IO

import System
import Rhino
 
doc = Rhino.RhinoDoc.CreateHeadless(None)
 
if not objects is None:
    for o in objects:
        doc.Objects.Add(o)

Thanks I managed to get it to work:

schoring.3dm (3.6 MB)

schoring.py (3.9 KB)