Quantcast
Channel: Grasshopper - McNeel Forum
Viewing all articles
Browse latest Browse all 39513

Using GH_ActiveObject.AddRuntimeException() in Custom Class

$
0
0

@alan2 wrote:

Hi there!

This is more a question about best practices than an actual problem, but here it goes:

I have created a custom class that will be used inside a custom GH_Component. I have copied a made-up version of the class at the bottom of the message to make my point.

What I want to do is being able to call AddRuntimeException(), to throw an alert if the Surface.ClosestPoint()method did not succeed. Since AddRuntimeException() is only accesible from the actual component, I have created a new variable in my class to hold a reference to it’s owner (the component that initialized it).

So, my question is as follows:

  1. Is this an actual good idea?
  2. Is there an better way to do this?

Since my end goal is to create a family of components that talk to each other, and I would be passing around this custom classes:

  1. Should I be deriving them from IGH_Goo and creating GH_Param wrappers for all the classes I would be passing around?
  2. Would deriving from IGH_Goo give me access to throwing exceptions?

I guess they would be only 2 or 3 classes that I would need to pass around so it wouldn’t be a lot of work… Just asking!

This is the class:

    public class ChebychevAxis
    {
        Surface _surface;
        double u, v;
        ChebychevNetGHComponent owner;
        DataTree<Point3d> _axisPoints;

        public ChebychevAxis(Surface surface, Point3d startPoint)
        {
            _surface = surface;
            bool success = _surface.ClosestPoint(startPoint, out u, out v);
            if (!success) owner.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "OOPS!! Something happend while setting the starting point");
        }
    }

Thanks in advance!

P.D. Markdown text is fun :slight_smile:

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 39513

Trending Articles