algorithmic modeling for Rhino
Very simple problem here that Im sure is just due to my inexperience, but I keep running into an error when I try to use 'FindByObjectType'. The error I'm getting is
"Error (CSo120): An object Reference is required for the non-static field, method, or property 'Rhino.DocObjects.Tables.ObjectTable.FindByObjecType(Rhino.DocObjects.ObjectType)'"
The script is very simple:
List<Rhino.DocObjects.RhinoObject> AllPoints = new List<Rhino.DocObjects.RhinoObject>();
AllPoints = Rhino.DocObjects.Tables.ObjectTable.FindByObjectType(Rhino.DocObjects.ObjectType.Point);
Any clue what I'm doing wrong?
Tags:
"An object Reference is required for the non-static field, method, or property "
Means you cannot just call the FindByObjectType out of the blue, you have to call it on an instance of the ObjectTable class.
So first you need to make sure you have an instance of a RhinoDoc. If your code runs inside a C# script component, then you can use:
RhinoDocument.Objects.FindByObjectType()
Because the RhinoDocument variable actually points to a real Rhino document.
So I modified the "Rhino.DocObjects.Tables" to "RhinoDocument.Objects" and combined those two lines I posted into one line that looks like this:
List<Rhino.DocObjects.RhinoObject> AllPoints = new List<Rhino.DocObjects.RhinoObject>(RhinoDocument.Objects.FindByObjectType(Rhino.DocObjects.ObjectType.Point));
and it works now, so thanks for the help with that!
Now, I want to make sure I understand WHY it works now...
Is it because "Rhino.DocObjects.Tables" looks for any objects in any instance of Rhino, where "RhinoDocument.Objects" looks for only objects in the referenced instance of rhino?
To clarify, I am using this in a C# Component in Grasshopper
Rhino.DocObjects.Tables is a namespace.
Rhino.DocObjects.Tables.ObjectTable is a type definition (a class in this case).
Rhino.DocObjects.Tables.ObjectTable.FindByObjectType() is a method definition, which belongs to the ObjectTable class.
If FindByObjectType were a static method, then you should call it the way you originally did, as static methods can just be called whenever. However FindByObjectType() is not static, and it can only be called via an actual instance of the ObjectTable class instead of the class name itself.
The reason is that FindByObjectType() only works within a single document, so there's no way it could be static as then it wouldn't know in what document to search.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by