Autonomous Scripting

"Self-contained Scripting" or "Autonomous Scripting"
Creating a script which,apart from the initial input, can run to completion
and produce and/or modify an object in a pre-determined manner without additional user input.

(An example of the application of such a script would be to produce a representation of a steel beam.)

When trying to use CreateRailRevolvedSurface in the Autonomous Script listed below I get following error message:
"expected Curve, got Guid"
The first two are curves, the third is a line and the fourth boolean?

Parameters required by CreateRailRevolvedSurface
profile: Profile curve for revolution.
| rail: Rail curve for revolution.
| axis: Axis of revolution.
| scaleHeight: If true, surface will be locally scaled.
| Returns: A NurbsSurface or null on failure.

When using AddSweep1 get error message “iteration over non-sequence of type Guid”

Question 1: How do I get Rhino.Geometry.NurbsSurface.CreateRailRevolvedSurface
to function in an Autonomous Script?
Question 2: How do I get rs.AddSweep1 to function in an Autonomous Script?

import rhinoscriptsyntax as rs
import math
import Rhino.Geometry.NurbsSurface as rgns
import System

Length = 20.0
Radius = 3.0
Pitch = 2.0
Turns = 10.0

StartPt = rs.AddPoint(0,0,0)
EndPt = rs.AddPoint(Length,0,0)
RadiusPt= rs.AddPoint(0,Radius,0)

SweepAxis = (StartPt,EndPt)
FullHelixLn=rs.AddLine((0,0,0), EndPt)

plane = (0,3,0)
Outline = rs.AddCircle(plane,0.25)
plane = rs.WorldXYPlane()
plane = (0,0,0)

rs.CurrentLayer( “Layer 04”)
Helix_Path = rs.AddSpiral(StartPt,EndPt,Pitch,Turns,Radius,Radius)
rs.CurrentLayer( “Layer 01”)

Surface1 = rgns.CreateRailRevolvedSurface(Outline,Helix_Path,FullHelixLn,scaleHeight=False)

Surface2 = rs.AddSweep1(Helix_Path,Outline,closed=True)

Since, as your name suggests, you’re a novice python scripter, I’ll give you a few pieces of semi-unsolicited advice.

  1. Doing things like:

import Rhino.Geometry.NurbsSurface as rgns

is generally considered bad form. It lessens the readability of your code, goes against typical OOP principles, and, since you only use it once, doesn’t save a lot of typing.

  1. Variable names. While there’s nothing inherently wrong with yours, having a scheme that you stick to will serve you well in the long run. IIRC, in python variable names are generally recommended to be in a form such as:


i.e. all lower case with underscores

  1. SweepAxis=(startpt,endpt) is giving you what’s called a “Tuple”, and not a line. Tuples are one of the basic builtin Python data-storage types, and you should read up on them along with lists and dictionaries.

Now, the errors you’re getting.

The rs functions typically add geometry to your document and return what’s called a GUID. You can think of this as an “ID” for each object in the document, and each object has one that is completely unique. You use this to reference the object in order to pass it to an rs function. In other words, rs functions typically take IDs as arguments, and return them as results.

When you use RhinoCommon Functions (e.g. Rhino.Geometry.NurbsSurface…) things are a little different. These functions typically take as input RhinoCommon Types. That’s why you see things like “profile: Curve, rail: Curve” in the documentation for these functions. What that’s telling you is that these parameters need to be a Rhino.Geometry.Curve object or a Rhino.Geometry.Line object etc.

CreateRailRevolvedSurface() is failing because you are passing it an ID from your document and not the Geometry itself. The easiest solution to this is to use one of the rs.coerce… functions to “cast” your ID to its underlying Geometry type.In the curve case, rs.coercecurve(outline) should do the trick.

rs.AddSweep1 is failing because plane=(0,3,0) is not a valid plane that rs.AddCircle can use. Therefore Outline ends up as type “None” and rs.AddSweep gets confused by that.

Hope this helps you on your journey!


One thing you’re not understanding here is the difference between working with rhinoscriptsyntax functions and RhinoCommon. In general rhinoscriptsyntax functions reference from and add objects to the document, whereas RhinoCommon is often working with “virtual” geometry that does not exist in the document (yet). When it says “expected curve, got Guid”, it means you passed the ID of an existing curve, when Rhinocommon wants the actual geometry.

Working with Rhinocommon is quite a bit more complex than rhinoscriptsyntax; although very powerful , it uses lower level functions and more abstract concepts…