Grasshopper

algorithmic modeling for Rhino

I am getting a funny error. I take inputs to a component, then pass some of them outside to a static method to perform a task that is common to some parts of my suite of components, but I am getting a DocumentCollectedException on a brep which does not allow me to perform any operations.

public static List<Curve> Evaluate(List<Point3d> Points, List<Curve> ClosedCurves, double Tolerance, out List<Point3d> FailedPoints)
        {
            //Sorts in order of points
            //Naive implementation
            //Can update to KD tree if necessary            
            List<Curve> OrderedCurves = new List<Curve>();
            List<Point3d> fPoints = new List<Point3d>();
            
            foreach (Point3d Point in Points)
            {
                //Backwards loop to allow removal
                bool assigned = false;
                
                for (int i = ClosedCurves.Count - 1; i >= 0; i--)
                {
                    if (ClosedCurves[i].IsClosed == false)
                    {
                        throw new Exception("Curve is not closed");
                    }

                    Brep cc = Brep.TryConvertBrep(ClosedCurves[i]);

                    //Offending line here, brep 'cc' is the problem!
                    Curve[] edge = cc.DuplicateEdgeCurves();
                    edge = Rhino.Geometry.Curve.JoinCurves(edge, Tolerance);

                    if (edge[0].Contains(Point) == PointContainment.Inside)
                    {
                        OrderedCurves.Add(ClosedCurves[i]);
                        Points.RemoveAt(i);
                        assigned = true;
                        break;
                    }
                }

                //If point not within any of the given breps put null in the list
                if (assigned == false)
                {
                    OrderedCurves.Add(null);
                    fPoints.Add(Point);
                }
            }

            FailedPoints = fPoints;
            return OrderedCurves;
        }

Views: 656

Replies to This Discussion

not sure why you'd be getting that error in particular, so just taking a shot in the dark - are you certain that TryConvertBrep is yielding a Brep and not a null value? There are cases where your closed curves might not give back a brep.

I have created a C# component and tried to run Brep.TryConvertBrep(x), it throws the same Document Collected Exception even though I gave it a planar rectangle which surely must work!

OK so I had a reply from McNeel which was very clear, I quote it here:

"TryConvertBrep() attempts to convert a generic Geometry - GeometryBase - object into a Brep. You would use this function if you had a GeometryBase object, knew it was a Brep, and wanted it as a Brep object. In your case, you have a Curve, which is not a Brep. Thus, calling TryConvertBrep in this case in inappropriate.

To create a planar Brep from the input curve, you might do something like this:

A = Brep.CreatePlanarBreps(x);"

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