Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Export temporary .stp and autoload in Bambu Lab Slicer

$
0
0

I started writing a script to load a brep directly in bambu studio. A temp step file is saved and opened with bambu.
What I would like to do is that if bambu studio is alredy running to just inject the file and open a new buildplate but I couldnt find any hint how to make that work. Bambus api seems to be focused on network control of the printer.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import System
import os
import platform

# 1. Let user select multiple Breps
brep_ids = rs.GetObjects("Select Breps to export (press Enter to finish)", rs.filter.polysurface | rs.filter.surface)
if not brep_ids or len(brep_ids) == 0:
    print("No Breps selected.")
    exit()

# 2. Prepare temp export file
temp_dir = System.IO.Path.GetTempPath()
temp_file = os.path.join(temp_dir, "exported_model.step")

# 3. Unselect all, select only desired Breps
rs.UnselectAllObjects()
for id in brep_ids:
    rs.SelectObject(id)

# 4. Export via Rhino command
export_command = '-_Export "{}" _Enter'.format(temp_file)
success = Rhino.RhinoApp.RunScript(export_command, False)

# 5. Deselect after export
rs.UnselectAllObjects()

if success:
    print("Exported to:", temp_file)
    
    # 6. Determine OS and Bambu Studio path
    system = platform.system()
    if system == 'Windows':
        bambu_path = r"C:\Program Files\Bambu Studio\bambu-studio.exe"
    elif system == 'Darwin':
        bambu_path = "/Applications/Bambu Studio.app/Contents/MacOS/Bambu Studio"
    else:
        bambu_path = None
    
    # 7. Launch Bambu Studio
    if bambu_path and os.path.exists(bambu_path):
        print("Launching Bambu Studio...")
        System.Diagnostics.Process.Start(bambu_path, '"{}"'.format(temp_file))
    else:
        print("Bambu Studio executable not found or unsupported OS. Opening with default app.")
        psi = System.Diagnostics.ProcessStartInfo()
        psi.FileName = temp_file
        psi.UseShellExecute = True
        System.Diagnostics.Process.Start(psi)
else:
    print("Export failed.")

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles