generative modeling for Rhino
Hello, somethings I still dont understand...
What 'is not working?
Thanks
RG
Private Sub RunScript(ByVal pt_1 As Point3d, ByVal pt_2 As Point3d, ByRef A As Object)
A = Rhino.Geometry.Point3d.DistanceTo(Pt_1, Pt_2)
end sub
Tags:

Hi RG,
DistanceTo() is a method available from any Point3d you might have. It is not a static (Shared in VB) method which is available via the type-name. It would have been called DistanceBetween() if it required two inputs.
The difference between shared and non-shared method is that shared methods should be called with the class name as a prefix. For example:
Point3d.Origin
Origin is a shared property on the Point3d struct. I.e. you do not need an existing point to get the world origin location. DistanceTo() is a non-shared method that operates on the instance of the point you're calling it on. The signature of DistanceTo() requires a single point as an input parameter, so when you're shoving both Pt_1 and Pt_2 into that function it is going to choke.
This in itself is already a bit of a give-away. DistanceTo() clearly computes the distance between two points, but it only accepts a single input. That must mean that the function should be called on the second point in this drama.
Pt_1.DistanceTo(Pt_2)
is what you're looking for.
The big advantage of Shared methods over Non-Shared methods is that you do not need an instance of a type to call the method. It is always available, where ever you are and whatever data you might have at your disposal. All RhinoScript methods are Shared in this respect.
The big advantage of Non-Shared methods over Shared methods is that you can get away with a smaller signature. You are calling the method on a specific object, which reduces the amount of code you have to type. I.e.
Pt_1.DistanceTo(Pt_2)
is shorter than
Point3d.DistanceTo(Pt_1, Pt_2)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Permalink Reply by James S on September 30, 2011 at 10:32pm Hi David,
I would like to know why the command can not be used with C# as per attached file.
Thanks,
James

Hi James,
DistanceTo() is a member of Point3d. Since you haven't assigned a type-hint to your variables they come in as System.Object.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Permalink Reply by James S on October 2, 2011 at 6:58am 
When I open your file, I get the same answer out of all 4 components. What happens when you close and then open that file?
VB is a more forgiving language than C#. It will accept certain mistakes in capitalization, brackets as well as the odd type mismatch.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Permalink Reply by James S on October 2, 2011 at 7:07am Yes, it works after closed and reopened.
Thanks,
James
Permalink Reply by RG on January 21, 2011 at 8:48am Thanks,
Why I dont need to put Rhino.Geometry....before?
:)

Rhino and Rhino.Geometry are namespaces. A namespace is just like a folder in Windows Explorer. The classes are like the files, and all files are located in some folder.
If you import a namespace into a source code file then you do not need to include these prefixes before you use a class name. Look at the top of the file, if there's a statement like:
Imports Rhino.Geometry
then that means you can leave out the "Rhino.Geometry." part for classes that are part of that namespace (such as Curve, Point3d, or Plane for example)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Permalink Reply by Arthur Mamou-Mani on January 21, 2011 at 1:41pm Added by David Stasiuk 8 Comments 24 Likes
Added by stefano 5 Comments 8 Likes
© 2013 Created by Scott Davidson.
Powered by