algorithmic modeling for Rhino
Tags:
att.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
Hi Marc,
I am trying to understand your code. The logic of the steps are clear to me, but there is a -somehow- technical detail that i cant resolve:
When you use doc.objects.addpoints(...) i understand that "Doc" is the name of a class, but i cannot find this class anywhere in rhinocommon sdk (I limit my search to those namespaces that the vb componets imports by default, assuming this -hypothetical- class should be there:
Imports Rhino
Imports Rhino.Geometry
Imports Rhino.Collections
but nothing, cant find "doc" class anywhere. Where is the mistake?
thanks
leceta
doc is declared inside the Grasshopper Script component. Have a look at the Members section in the Script_Instance class.
I basically put it there so you don't have to call RhinoDoc.ActiveDoc all the time.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
i see...
My missunderstood was that doc it´s not the actual name of a class, but of an instance of the property (¿shouldnt be a class?) ActiveDoc inside the class RhinoDoc under the namespace rhino. Is this right?
Should i considere that a property of a class can be in turn a class itself.
Effectively i´m just starting with OOP
I also get into account that this was explained -implictly- in Rajaa´s introduction to vb.net. (pg.99)
thanks for the clarification.
leceta
This is correct. Rhino is the main Namespace in our SDK. There's other namespaces inside Rhino, for example Rhino.Geometry and Rhino.Collections. Every type in .NET is part of some namespace. Namespaces only have one raison d'être, which is to group types into logical chunks.
A Type is the definition of a class or a structure. Classes and structures are very similar entities (they can both contain any number of methods, properties and other types), but because they behave differently, you need to know which is which.
An Instance of a type is a single object that actually exists. For example, the class Human is the definition of what it means to be human. You are an instance of this class. I am a different instance of this class. Damien is yet another instance of this class. Every instance can assign unique values to all its properties and fields. If for example the type Human had a property for height, then in my case it would say 1.97m. In Damien's case it would be set to something much less, as Damien isn't anywhere near as handsome and tall as I am.
A Reference is a piece of information that tells you where a certain instance is. Think of a reference as an address. When you mail a letter (or e-mail), you must specify a valid and unambiguous address or the letter won't arrive. Similarly, every piece of data stored in the memory of your computer also has a unique address, but instead of "3670, Woodland Park Avenue, Seattle", it looks like this 0x12345678. Trying to access an instance through an invalid reference is like sending a letter without an address.
References are sometimes also called "variables", though sometimes the word variable is only used to indicate primitive types, such as Booleans, Integers and such. A reference is not the instance itself. Take the following code:
1. Dim crv As Rhino.Geometry.Curve
2. Dim dup As Rhino.Geometry.Curve
3. crv = GetACurveFromSomewhere()
4. dup = crv
5. If (dup IsNot Nothing) Then dup = dup.DuplicateCurve()
One lines (1) and (2) I declare two references, one is called "crv", the other "dup". Because Visual Basic is a strongly typed language, I can assign limitations to what sort of data crv and dup are allowed to reference. In this case they can only point to instances of the Rhino.Geometry.Curve class or any class which derives from Rhino.Geometry.Curve (such as Rhino.Geometry.NurbsCurve, or Rhino.Geometry.LineCurve).
On line (3) I assign an actual curve instance to the crv reference/variable. At least, assuming the GetACurveFromSomewhere() function actually returns a proper instance. If it doesn't, crv will remain a "null reference".
Line (4) is interesting, because both crv and dup will now point to the same curve instance. So even though there is only 1 curve in memory, both crv and dup provide access to it. This means that when we change the curve via crv, then dup will notice that change.
On line (5) two things happen. I want to duplicate my curve data so I can change the data via dup, without affecting the data available via crv. The best way to duplicate a curve (i.e. create a second curve in memory, that has the same shape as the first curve) is to use the DuplicateCurve() method on the Rhino.Geometry.Curve class. However I cannot call a method on an instance that doesn't exist, so before I do that, I need to check whether or not dup actually points to a real curve object, or whether it is a null reference.
Finally, it is also possible to have an instance of a class in memory, without any references to it. In this case nobody can reach that curve any more and it is essentially dead weight, taking up pointless memory. In C++ this is called a Memory Leak and it's considered a serious bug. In VB.NET and C# this memory will automatically be cleaned up by the .NET Garbage Collector. In my opinion the Garbage Collector is the single most important feature in .NET. It's what turns VB and C# from frustration central into a friendly and flexible coding platform.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
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