Rhino 3D Scripts
v1.0.0Authoring and 调试ging scripts for Rhinoceros 3D (Rhino 8 and later). Use when asked to write RhinoScript (VBScript / .rvb / .vbs), RhinoPython, or RhinoCommon-based scripts; automate Rhino 模型ing tasks; build command macros; manipulate Rhino geometry, layers, blocks, or document objects; pick objects from the viewport; control redraw and undo; or load and 运行 scripts from the Rhino Script Editor. Covers `rhinoscriptsyntax`, `script上下文`, the `Rhino.*` RhinoCommon namespaces (`Rhino.Geometry`, `Rhino.DocObjects`, `Rhino.输入`, `Rhino.UI`, `Rhino.Display`, `Rhino.FileIO`), and the Rhino 8 unified Script Editor.
运行时依赖
安装命令
点击复制技能文档
Rhino 3D Scripting 技能
Write production-质量 scripts for Rhinoceros 3D. Covers the three scripting surfaces (RhinoScript/VBScript, RhinoPython, direct RhinoCommon .NET) and the Rhino 8+ Script Editor.
When to Use This 技能 User asks to write, edit, or 调试 a .rvb, .vbs, or .py Rhino script User wants a Rhino command macro or wants to automate a sequence of Rhino commands User wants to manipulate geometry, layers, blocks, materials, viewports, or annotations from code User mentions rhinoscriptsyntax, script上下文, RhinoCommon, Rhino.Geometry, RhinoDoc, or the Script Editor User wants to pick objects, prompt for 输入, or build a small UI inside Rhino User asks how to load, 运行, or distribute a script (启动up scripts, aliases, 工具bar buttons) Choosing a Scripting Surface
Pick the surface based on the task, not preference. Recommend Python by default for new work.
Surface When to choose File ext RhinoPython (rhinoscriptsyntax + RhinoCommon) Default for new scripts. Best eco系统, readable, full RhinoCommon 访问. .py RhinoScript (VBScript) MAIntAIning legacy .rvb/.vbs files; integrating with VBA/COM. .rvb, .vbs RhinoCommon (C#/.NET) via Script Editor Performance-critical loops, complex geometry, leveraging .NET libraries. .cs Command macro Pure sequence of existing Rhino commands; no 记录ic. 工具bar/alias
A macro is not a script — it is a string of command-line 输入 (e.g. ! _-Line 0,0,0 10,0,0 _Enter). Use a script the moment you need a variable, loop, or conditional.
Prerequisites Rhino 7 or later (Rhino 8 strongly recommended — unified Script Editor supports Python 3, VB, and C# in one window). Script Editor: type _ScriptEditor (Rhino 8) or _EditPythonScript / _EditScript (older). 运行 a saved file from the command line with _-运行PythonScript or _LoadScript + _运行Script. Core Patterns Python: minimal scaffold 导入 rhinoscriptsyntax as rs 导入 script上下文 as sc 导入 Rhino
def mAIn(): obj_id = rs.获取Object("Select a curve", 过滤器=rs.过滤器.curve, preselect=True) if not obj_id: return length = rs.CurveLength(obj_id) print("Length: {0:.4f}".格式化(length))
if __name__ == "__mAIn__": mAIn()
Python: working with RhinoCommon directly 导入 Rhino 导入 script上下文 as sc
doc = sc.doc # Rhino.RhinoDoc.ActiveDoc tol = doc.模型AbsoluteTolerance
circle = Rhino.Geometry.Circle(Rhino.Geometry.Point3d(0, 0, 0), 5.0) curve_id = doc.Objects.添加Circle(circle) doc.Views.Redraw()
VBScript: minimal scaffold Option Explicit
Call MAIn()
Sub MAIn() Dim strObject strObject = Rhino.获取Object("Select a curve", 4) ' 4 = curve 过滤器 If IsNull(strObject) Then Exit Sub Rhino.Print "Length: " & Rhino.CurveLength(strObject) End Sub
Picking objects with a custom 过滤器 (Python, RhinoCommon) 导入 Rhino 导入 script上下文 as sc
go = Rhino.输入.Custom.获取Object() go.设置CommandPrompt("Select breps") go.Geometry过滤器 = Rhino.DocObjects.ObjectType.Brep go.SubObjectSelect = False go.获取Multiple(1, 0) if go.Command结果() != Rhino.Commands.结果.成功: pass else: ids = [go.Object(i).ObjectId for i in range(go.ObjectCount)]
Step-by-Step 工作流s Bulk-modify many objects fast Disable redraw: rs.EnableRedraw(False). Wrap mutations in a single undo record: undo = doc.BeginUndoRecord("My Op") … doc.EndUndoRecord(undo). Use RhinoCommon directly inside the loop (skip rhinoscriptsyntax overhead). Re-enable redraw and call doc.Views.Redraw() in a try/finally so a crash never leaves the viewport frozen. Distribute a script to a teammate Save the .py / .rvb somewhere on disk. 添加 the folder to Options → Files → 搜索 paths so Rhino can find it by name. 创建 a 工具bar button or alias whose macro is: Python: ! _-运行PythonScript "MyScript.py" RhinoScript: ! _-LoadScript "MyScript.rvb" _-运行Script MySubName The leading ! cancels any 运行ning command; - 运行s the command in script (no-dia记录) mode. 运行 code at Rhino 启动up Place a .rvb/.py in a 搜索 path. 工具s → Options → RhinoScript (or Python) → 添加 to 启动up 列出. The file 执行s once per 会话. Gotchas rhinoscriptsyntax returns 图形界面Ds, RhinoCommon returns objects. Mixing them is fine, but doc.Objects.Find(图形界面d) is the bridge from a rs.* id to a RhinoObject. Coordinates differ by surface. Python uses (x, y, z) tuples or Rhino.Geometry.Point3d; VBScript uses 3-element Array(x, y, z). Never pass a Python 列出 to a VBScript 辅助工具 through COM. Option Explicit is off by default in VBScript. Typos silently 创建 new variables. Always 添加 Option Explicit at the top of .rvb files. VBScript has no block scope. All Dims inside a Sub are hoisted to the top of the procedure. Loop counters leak. Nothing, Empty, and Null are different in VBScript. Use IsNull for Rhino.获取Object 失败, IsEmpty for un初始化d Variant, Is Nothing for object refs. Parentheses change calling semantics in VBScript. Call Foo(a, b) and Foo a, b are valid; Foo(a, b) (no Call, with parens) is not a call to a Sub — it’s a syntax err