algorithmic modeling for Rhino
Hi all,
I'm struggling through writing a custom component in C# with Visual Studio. Most everything is working, but right now I'm stumped on this.
I'm writing a very basic set of components to aid in generating KRL code for a KUKA robot arm. The function below is going to convert from an orientation transform to Euler coordinates, which is the format used in KRL code.
using System;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
namespace krl_toolbox
{
public class Convert
{
public void TransformToEuler(Rhino.Geometry.Plane p1, Rhino.Geometry.Plane p2)
{
GH_Transform t = Grasshopper.Kernel.Types.Transforms.Orientation.Orientation(p1, p2);
}
}
}
According to the object browser in VS, ...Orientation.Orientation is a constructor (I think that's the right terminology here?) for creating a GH_Transform object. However, VS won't compile, complaining that the Orientation method doesn't exist. When I type "Grasshopper.Kernel.Types.Transforms.Orientation.", the code completion popup only shows the methods "Equals" and "ReferenceEquals".
I think it must be something stupidly simple, but I don't know what to do. Any thoughts?
Thanks,
Trygve
Tags:
There are a few things here:
1. with a constructor in C#, you need the "new" keyword
2. You don't need to type "orientation" a second time - new Grasshopper.Kernel.Types.Transforms.Orientation(p1, p2);
will suffice
3. This constructor returns an "Orientation" type, rather than a GH_Transform type. This type also implements ITransform so you can write it as Grasshopper.Kernel.Types.Transforms.ITransform t = new Grasshopper.Kernel.Types.Transforms.Orientation(p1, p2);
4. the ITransform interface (as I understand it) represents only a single transform - the GH_Transform type can include compound transforms and perhaps other complexity. Without knowing what you intend to do with the GH_Transform I can't tell you if it's necessary, but if you need to you can create a new GH_Transform from your ITransform like so:
GH_Transform ght = new GH_Transform(t);
(where t is the ITransform as created above.)
Hope that's helpful!
Hi Trygve,
The new alpha version for HAL0050 including ABB, KUKA and Universal Robots compatibility is now available for testers if you want to give it a try. If so, just send me a message.
Have a nice day,
T.
That makes so much more sense. Slowly, slowly. Thanks for the insights!
Thibault - On it!
Trygve
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