Grasshopper

algorithmic modeling for Rhino

 

 

Hi All...

Recently Giulio spent 30mins of his time introducing me to how to do custom components and debugging in VS. (thanks, Guilio :-) )

I have started, and have managed to do a component that creates a dimension in the rhino viewport.

When I change input parameters, It creates a new dimension, without removing the old one. That makes sense from the script I have, but it is not quite what I want.

How can I make it replace or delete the old dimension line when a new one is created?

 

Heres a part of the code:

 

if (((((((DA.GetData<Point3d>(0, ref pointd) && DA.GetData<Point3d>(1, ref pointd2)) && DA.GetData<Point3d>(2, ref pointd3)) && DA.GetData<Plane>(3, ref plane)) && pointd.IsValid) && pointd2.IsValid) && pointd3.IsValid) && plane.IsValid)
            {
                double u, v;
                plane.ClosestParameter(pointd, out u, out v);
                Point2d ext1 = new Point2d(u, v);

                plane.ClosestParameter(pointd2, out u, out v);
                Point2d ext2 = new Point2d(u, v);

                plane.ClosestParameter(pointd3, out u, out v);
                Point2d linePt = new Point2d(u, v);

                LinearDimension dimension = new LinearDimension(plane, ext1, ext2, linePt);
                Rhino.RhinoDoc.ActiveDoc.Objects.AddLinearDimension(dimension);

                DA.SetData(0, Rhino.Commands.Result.Success);
            };

 

 

 

cheers

Views: 1557

Replies to This Discussion

Hi Jes,

 

you'll need to store the ID of the annotation in some variable that doesn't get nuked when the SolveInstance method finishes. Basically you'll need to use a Shared variable, or even store the data somewhere on the disk.

 

Rhino.RhinoDoc.ActiveDoc.Objects.AddLinearDimension(dimension);

 

this function returns an ID, which you need to store, then delete that object the next time the script runs:

 

// Somewhere inside your GH_Component derived class, but outside of any methods in that class

private static Guid annotationID = Guid.Empty;

 

// Inside your SolveInstance

if (annotationID != Guid.Empty)

{ Rhino.RhinoDoc.ActiveDoc.Objects.Delete(annotationID); }

annotationID = Rhino.RhinoDoc.ActiveDoc.Objects.AddLinearDimension(dimension);

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

looking forward to play with!

Thanks David.

 

I had the idea that this whas what I needed, but I put the Guid declaring inside the instance solver, which as you said "nuked" the id whenever the function updated. putting it as "private static" did the trick.

I found the Rhino.RhinoDoc.Active.Objects.Replace() method, but it seems that it only works for text instances?, In principle it would be easier to do a replace rather than a "record ID, delete previous, create new" setup

... but hey, it works.

 

I'll try to add a little more functionallity to the script and add a bit of robustnesss in the code... I'll keep you updated.

(And btw, david, thanks for adressing the curve offset issue in the new version. Will test today if it works now :-)  )

Hmm.. I kinda feared that that would happen.

Now only the dimension of the last object is drawn for list inputs...

 

I'm wondering how I should tackle that issue. Maybe adding GUIDs to "annotaionID" incrementally, and then flush that entire list of objects on an input update event.

 

Is the some method in the GH namespace that would return a true or false if the input is changed or not? I could then add that to this snippet:

if (annotationID != Guid.Empty)

{ Rhino.RhinoDoc.ActiveDoc.Objects.Delete(annotationID); }

 

 

 

Yes, if you want this to work on a list of IDs, then you should use a static List<Guid> instead of a static Guid.

 

// class level

private static List<Guid> m_ids;

 

// method level

RhinoDoc doc = RhinoDoc.ActiveDoc;

if (DA.Iteration == 0)

{

  if (m_ids != null)

  {

    doc.Objects.Delete(m_ids)  

  }

  m_ids = new List<Guid>();

}

...

m_ids.Add(doc.Objects.AddLinearDimension(dimension))

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service