Python Intro #04 | Rhino Command

Contents

  1. Script Context
  2. Rhino Command
    1. Function
    2. Usage
  3. Practice – Auto Export

Script Context

Refer ” Tips | Script Context in GH Python

Rhino Command

Function

rs.Command(<command here>)

Usage

import rhinoscriptsyntax

rs.Command()

Practice – Auto Export

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
 
if active:
    for i in range(len(objs)):
        obj = objs[i]
        
        #get object properties
        obj_id = obj
        doc_object = rs.coercerhinoobject(obj_id)
        attributes = doc_object.Attributes
        geometry = doc_object.Geometry
 
        #go to Rhino workspace
        scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc
 
        #bake and select object
        rhino_obj = scriptcontext.doc.Objects.Add(geometry, attributes)
        rs.SelectObject(rhino_obj)
 
        #run command to bake and delete
        save = filename+str(i)+".obj"
        formatted_text = '-_export "{0}" _Enter _Enter'.format(save)
        rs.Command(formatted_text)
        rs.Command("_Delete")
 
        #back to GH workspace
        scriptcontext.doc = ghdoc