Is it possible to override the Point3d constructor directly or should I override the Rhino.Geometry.Point class then somehow create my own constructor mimicking Rhino.Geometry.Point3d but adding some new properties to it?
See what I do below, is this correct?
I want a custom class that when run will place a point on x=0.0, y=0.0, z=0.0, always.
The problem is that you can inherit from Rhino.Geometry.Point, since its a class, but you can’t inherit from Rhino.Geometry.Point3d since it’s a struct.
C# structs are sealed, which means that you can’t inherit from them. It has to do with structs being value types, and value types are always sealed, I believe.
The problem with Rhino.Geometry.Point is that it takes at least 2 arguments during initialisation, which are self and a Rhino.Geometry.Point3d. This means that when inheriting from it, you always have to provide both arguments. You can’t simply initialise your own class, which inherits, without arguments, which is inconvenient, since you want to initialise as an origin point, right?
Overriding this is probably not possible, so you have two options that I can think of:
The first one, would be to inherit from Rhino.Geometry.Point, extend it with your custom attributes and methods, and pass in a Rhino.Geometry.Point3d.Origin, when you initialise it. This way you can benefit from the already available attributes and methods, as well as your very own extensions.
The other option would be to create your very own, customised Point class. Of course, you’d have to start pretty much from scratch. However, if your custom attributes and method are, what you would primarily use either way, this would be the way to go.
Even Rhino.Geometry.Point is a pretty simple class. It’s basically just composed of three coordinates.
Interestingly enough, I started doing the same thing in my first try, the same structure and overriden methods. The only difference was instead of creating the class from scratch I tried to derive it from Rhino.Geometry.Point3d . Of course that failed so I ended up deriving from Rhino.Geometry.Point instead which lead me to a dead end.
Does it make sense to implement sc.doc.objects.addpoint() from inside my class?
One of the things I wished I could put to the point is upon creation to add some usertext to the object. And since this is a property of a point object not virtual point I don’t know which is the proper way to go. Make it as a method to my custom class or as a separate event that triggers every time the class is instantiated.
I don’t know, since I don’t have a lot of experience with scriptcontext. As I understand, from reading the documentation, sc.doc.objects.addpoint() adds a point to your document. If that’s what you want to achieve, implement it. However, it’s also not inheritable, since it’s a method, not a class.