Grasshopper

algorithmic modeling for Rhino

GH Python error "MissingMemberException: 'Guid' object has no attribute 'length'"

Hi Guys,

I am trying to get the length of a curve but I am getting the message: "MissingMemberException: 'Guid' object has no attribute 'length'"

The same script in C# works well. What is the problem with the python translation?

PYTHON:

import rhinoscriptsyntax as rs

ln = rs.AddLine(pt1, pt2)

a = ln
b = ln.Length

C#:

Line ln;

ln = new Line(pt1, pt2);

A = ln;
B = ln.Length;

Many thanks,

Arthur

Views: 3953

Replies to This Discussion

Ok sorry, I solved this using a different method as I was getting the GUID of the new line, not the line itself (Documentation):

b = rs.CurveLength(ln) as opposed to b = ln.Length

Nevertheless, if I replace the rs.AddLine method with the following RhinoCommon method I though I would get the line, like in C#:

import Rhino as Rhino

ln = Rhino.Geometry.Line(pt1,pt2)

a = ln
b = ln.Length

but I also get the GUID as mentionned in the error message:

"(ArgumentTypeException): expected Point3d, got Guid"

Why is that?

Hi Arthur,

Basically, it's because rhinoscript was built to work with GUIDs and not directly with geometry objects. the C# script is not using rhinoscript. If you mix RhinoCommon and rhinoscript you will likely see more of these messages.

Here's more details, since this is a common problem:

the rhinoscript package is built in python, and is essentially a set of functions that wrap the functionality of RhinoCommon, making it easier to do various common scripting tasks.

Behind rhinoscript is RhinoCommon, which is accessed by any .NET language (C#, VB.NET, IronPython). The functions in RhinoCommon expect all kinds of different objects: Point3d, Curve, GeometryBase, ...

RhinoCommon, in other words, deals with all kinds of stuff, while rhinoscript focuses on GUIDs.

Why GUIDs? Well, a GUID is a link to a specific object in a Rhino Document (now Grasshopper has GUIDs too). With a GUID, you get the full object, called a "RhinoObject", not just the geometry. "RhinoObjects" are, in one sense, wrappers around geometry. 

If we look at a curve that you have sitting in your Rhino model, the curve itself will be represented as a Rhino.Geometry.Curve object, which inherits from the parent class, Rhino.Geometry.GeometryBase. For the curve to exist in your Rhino model it has to be wrapped with more information: it needs a GUID, it needs to be on a layer, it needs to know if it is hidden or not, etc. So it is wrapped up in a Rhino.DocObjects.RhinoObject. the RhinoObject contains a Geometry property, which if accessed will return the Rhino.Geometry.Curve object.

By working with GUIDs, you only have to deal with RhinoObjects that are already sitting in your model. If you work in RhinoCommon, you will work with different kinds of geometry that do not exist in your model, and you will have to explicitly add them to the Rhino document in order to see them.

Great! Very clear, thanks a lot Ben.

(Just for search purposes): see a similar discussion.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service