Ejemplo n.º 1
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects = new IntersectionResultArray();
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);
            var results = FSharpList <Value> .Empty;

            var xsect_results = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xsect);

                    xsect_results = FSharpList <Value> .Cons(Value.NewList(xsect), xsect_results);

                    pts.Add(ir.XYZPoint);
                }
            }
            results = FSharpList <Value> .Cons(Value.NewList(xsect_results), results);

            results = FSharpList <Value> .Cons(Value.NewString(result.ToString()), results);

            return(Value.NewList(results));
        }
Ejemplo n.º 2
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects;
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);

            var xyz = FSharpList <Value> .Empty;
            var u   = FSharpList <Value> .Empty;
            var v   = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    xyz = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xyz);

                    u = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), u);

                    v = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), v);

                    pts.Add(ir.XYZPoint);
                }
            }

            outPuts[_vPort]      = Value.NewList(v);
            outPuts[_uPort]      = Value.NewList(u);
            outPuts[_xyzPort]    = Value.NewList(xyz);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }
Ejemplo n.º 3
0
        //求两个直线的交点
        public double GetIntersectionParameter(Line line1, Line line2)
        {
            IntersectionResultArray results;
            SetComparisonResult     result = line1.Intersect(line2, out results);

            MessageBox.Show(result.ToString());
            MessageBox.Show(results.Size.ToString());
            if (result != SetComparisonResult.Overlap)
            {
                throw new NotImplementedException("选择的两个线条的关系为平行或者重叠");
            }
            if (results == null || results.Size != 1)
            {
                throw new InvalidOperationException("测试的两个线条的关系相交异常");
            }
            IntersectionResult iResult   = results.get_Item(0);
            double             indexPara = iResult.Parameter;

            return(indexPara);
        }
Ejemplo n.º 4
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var   crv       = (Curve)((Value.Container)args[0]).Item;
            Face  face      = null;
            Solid tempSolid = null;
            Plane thisPlane = null;

            if (((Value.Container)args[1]).Item is Face)
            {
                face = (Autodesk.Revit.DB.Face)((Value.Container)args[1]).Item;
            }
            else if (((Value.Container)args[1]).Item is Plane)
            {
                thisPlane = ((Value.Container)args[1]).Item as Plane;
                // tesselate curve and find uv envelope in projection to the plane
                IList <XYZ> tessCurve      = crv.Tessellate();
                var         curvePointEnum = tessCurve.GetEnumerator();
                XYZ         corner1        = new XYZ();
                XYZ         corner2        = new XYZ();
                bool        cornersSet     = false;
                for (; curvePointEnum.MoveNext();)
                {
                    if (!cornersSet)
                    {
                        corner1    = curvePointEnum.Current;
                        corner2    = curvePointEnum.Current;
                        cornersSet = true;
                    }
                    else
                    {
                        for (int coord = 0; coord < 3; coord++)
                        {
                            if (corner1[coord] > curvePointEnum.Current[coord])
                            {
                                corner1 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner1[coord],
                                                  coord == 1 ? curvePointEnum.Current[coord] : corner1[coord],
                                                  coord == 2 ? curvePointEnum.Current[coord] : corner1[coord]);
                            }
                            if (corner2[coord] < curvePointEnum.Current[coord])
                            {
                                corner2 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner2[coord],
                                                  coord == 1 ? curvePointEnum.Current[coord] : corner2[coord],
                                                  coord == 2 ? curvePointEnum.Current[coord] : corner2[coord]);
                            }
                        }
                    }
                }

                double dist1    = thisPlane.Origin.DistanceTo(corner1);
                double dist2    = thisPlane.Origin.DistanceTo(corner2);
                double sizeRect = 2.0 * (dist1 + dist2) + 100.0;


                CurveLoop cLoop = new CurveLoop();
                for (int index = 0; index < 4; index++)
                {
                    double coord0 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                    double coord1 = (index < 2) ? -sizeRect : sizeRect;
                    XYZ    pnt0   = thisPlane.Origin + coord0 * thisPlane.XVec + coord1 * thisPlane.YVec;

                    double coord3 = (index < 2) ? sizeRect : -sizeRect;
                    double coord4 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                    XYZ    pnt1   = thisPlane.Origin + coord3 * thisPlane.XVec + coord4 * thisPlane.YVec;
                    Line   cLine  = dynRevitSettings.Revit.Application.Create.NewLineBound(pnt0, pnt1);
                    cLoop.Append(cLine);
                }
                List <CurveLoop> listCLoops = new List <CurveLoop> ();
                listCLoops.Add(cLoop);

                tempSolid = GeometryCreationUtilities.CreateExtrusionGeometry(listCLoops, thisPlane.Normal, 100.0);

                //find right face

                FaceArray facesOfExtrusion = tempSolid.Faces;
                for (int indexFace = 0; indexFace < facesOfExtrusion.Size; indexFace++)
                {
                    Face faceAtIndex = facesOfExtrusion.get_Item(indexFace);
                    if (faceAtIndex is PlanarFace)
                    {
                        PlanarFace pFace = faceAtIndex as PlanarFace;
                        if (Math.Abs(thisPlane.Normal.DotProduct(pFace.Normal)) < 0.99)
                        {
                            continue;
                        }
                        if (Math.Abs(thisPlane.Normal.DotProduct(thisPlane.Origin - pFace.Origin)) > 0.1)
                        {
                            continue;
                        }
                        face = faceAtIndex;
                        break;
                    }
                }
                if (face == null)
                {
                    throw new Exception("Curve Face Intersection could not process supplied Plane.");
                }
            }

            IntersectionResultArray xsects = new IntersectionResultArray();
            SetComparisonResult     result = face.Intersect(crv, out xsects);

            var xsect_results = FSharpList <Value> .Empty;
            var results       = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    try
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.EdgeParameter), xsect);
                    }
                    catch
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewNumber(0), xsect);
                    }
                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.EdgeObject), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.Parameter), xsect);

                    if (thisPlane != null)
                    {
                        UV planeUV = new UV(thisPlane.XVec.DotProduct(ir.XYZPoint - thisPlane.Origin),
                                            thisPlane.YVec.DotProduct(ir.XYZPoint - thisPlane.Origin));
                        xsect = FSharpList <Value> .Cons(Value.NewContainer(planeUV), xsect);
                    }
                    else
                    {
                        xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.UVPoint), xsect);
                    }

                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xsect);

                    xsect_results = FSharpList <Value> .Cons(Value.NewList(xsect), xsect_results);
                }
            }
            results = FSharpList <Value> .Cons(Value.NewList(xsect_results), results);

            results = FSharpList <Value> .Cons(Value.NewString(result.ToString()), results);

            return(Value.NewList(results));
        }
Ejemplo n.º 5
0
            public FindIntersection(
                FamilyInstance jbox,
                UIDocument uiDoc)
            {
                XYZ jboxPoint = (jbox.Location
                                 as LocationPoint).Point;

                FilteredElementCollector filteredCloserConduits
                    = new FilteredElementCollector(uiDoc.Document);

                List <Element> listOfCloserConduit
                    = filteredCloserConduits
                      .OfClass(typeof(Conduit))
                      .ToList()
                      .Where(x
                             => ((x as Conduit).Location as LocationCurve).Curve
                             .GetEndPoint(0).DistanceTo(jboxPoint) < 30 ||
                             ((x as Conduit).Location as LocationCurve).Curve
                             .GetEndPoint(1).DistanceTo(jboxPoint) < 30)
                      .ToList();

                // getting the location of the box and all conduit around.

                Options opt = new Options();

                opt.View = uiDoc.ActiveView;
                GeometryElement geoEle = jbox.get_Geometry(opt);

                // getting the geometry of the element to
                // access the geometry of the instance.

                foreach (GeometryObject geomObje1 in geoEle)
                {
                    GeometryElement geoInstance = (geomObje1
                                                   as GeometryInstance).GetInstanceGeometry();

                    // the geometry of the family instance can be
                    // accessed by this method that returns a
                    // GeometryElement type. so we must get the
                    // GeometryObject again to access the Face of
                    // the family instance.

                    if (geoInstance != null)
                    {
                        foreach (GeometryObject geomObje2 in geoInstance)
                        {
                            Solid geoSolid = geomObje2 as Solid;
                            if (geoSolid != null)
                            {
                                foreach (Face face in geoSolid.Faces)
                                {
                                    foreach (Element cond in listOfCloserConduit)
                                    {
                                        Conduit             con      = cond as Conduit;
                                        Curve               conCurve = (con.Location as LocationCurve).Curve;
                                        SetComparisonResult set      = face.Intersect(conCurve);
                                        if (set.ToString() == "Overlap")
                                        {
                                            //getting the conduit the intersect the box.

                                            GetListOfConduits.Add(con);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
Ejemplo n.º 6
0
        // Main execution
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;
            Selection     sel   = uidoc.Selection;


            // Grab the current building level
            FilteredElementCollector colLevels = new FilteredElementCollector(doc)
                                                 .WhereElementIsNotElementType()
                                                 .OfCategory(BuiltInCategory.INVALID)
                                                 .OfClass(typeof(Level));
            Level firstLevel = colLevels.FirstElement() as Level;


            // LineStyle filter
            CurveElementFilter       filter       = new CurveElementFilter(CurveElementType.ModelCurve);
            FilteredElementCollector collector    = new FilteredElementCollector(doc);
            ICollection <Element>    founds       = collector.WherePasses(filter).ToElements();
            List <CurveElement>      importCurves = new List <CurveElement>();

            foreach (CurveElement ce in founds)
            {
                importCurves.Add(ce);
            }
            var          wallCurves = importCurves.Where(x => x.LineStyle.Name == "WALL").ToList();
            List <Curve> wallLines  = new List <Curve>(); // Algorithm only support walls of line type

            foreach (CurveElement ce in wallCurves)
            {
                wallLines.Add(ce.GeometryCurve as Curve);
            }

            //double parasStart = wallLines[0].GetEndParameter(0);
            //double parasEnd = wallLines[0].GetEndParameter(1);
            //wallLines[0].MakeUnbound();

            //double _parasStart = wallLines[1].GetEndParameter(0);
            //double _parasEnd = wallLines[1].GetEndParameter(1);
            //wallLines[1].MakeUnbound();

            SetComparisonResult result = wallLines[0].Intersect(wallLines[1], out IntersectionResultArray results);

            Debug.Assert(result != SetComparisonResult.Overlap, "Overlap");
            Debug.Assert(result != SetComparisonResult.BothEmpty, "BothEmpty");
            Debug.Assert(result != SetComparisonResult.Disjoint, "Disjoint");
            Debug.Assert(result != SetComparisonResult.Equal, "Equal");
            Debug.Assert(result != SetComparisonResult.LeftEmpty, "LeftEmpty");
            Debug.Assert(result != SetComparisonResult.RightEmpty, "RightEmpty");
            Debug.Assert(result != SetComparisonResult.Subset, "Subset");
            Debug.Assert(result != SetComparisonResult.Superset, "Superset");



            double radius  = Misc.MmToFoot(50);
            XYZ    ptStart = wallLines[0].GetEndPoint(0);
            XYZ    ptEnd   = wallLines[0].GetEndPoint(1);
            XYZ    xAxis   = new XYZ(1, 0, 0); // The x axis to define the arc plane. Must be normalized
            XYZ    yAxis   = new XYZ(0, 1, 0); // The y axis to define the arc plane. Must be normalized
            Curve  knob1   = Arc.Create(ptStart, radius, 0, 2 * Math.PI, xAxis, yAxis);
            Curve  knob2   = Arc.Create(ptEnd, radius, 0, 2 * Math.PI, xAxis, yAxis);
            SetComparisonResult result1 = knob1.Intersect(wallLines[1], out IntersectionResultArray results1);
            SetComparisonResult result2 = knob2.Intersect(wallLines[1], out IntersectionResultArray results2);

            // if (result1 == SetComparisonResult.Disjoint && result2 == SetComparisonResult.Disjoint)
            if ((result1 == SetComparisonResult.Overlap || result1 == SetComparisonResult.Subset ||
                 result1 == SetComparisonResult.Superset || result1 == SetComparisonResult.Equal) ||
                (result2 == SetComparisonResult.Overlap || result2 == SetComparisonResult.Subset ||
                 result2 == SetComparisonResult.Superset || result2 == SetComparisonResult.Equal))
            {
                Debug.Print("INTERSECTED!");
            }
            else
            {
                Debug.Print("DISJOINT!");
            }


            XYZ  ptStart1 = wallLines[0].GetEndPoint(0);
            XYZ  ptEnd1   = wallLines[0].GetEndPoint(1);
            XYZ  ptStart2 = wallLines[1].GetEndPoint(0);
            XYZ  ptEnd2   = wallLines[1].GetEndPoint(1);
            Line baseline = wallLines[1].Clone() as Line;

            baseline.MakeUnbound();
            XYZ _ptStart = baseline.Project(ptStart1).XYZPoint;
            XYZ _ptEnd   = baseline.Project(ptEnd1).XYZPoint;

            Debug.Print("_start: " + Misc.PointString(_ptStart));
            Debug.Print("_end: " + Misc.PointString(_ptEnd));
            Line checkline = Line.CreateBound(_ptStart, _ptEnd);
            SetComparisonResult projection = checkline.Intersect(wallLines[1] as Line, out IntersectionResultArray projections);

            Debug.Print("Shadowing?" + projection.ToString());
            if (projection == SetComparisonResult.Equal)
            {
                Debug.Print("Shadowing");
            }
            {
                Debug.Print("Departed");
            }
            Curve proj1 = Arc.Create(_ptStart, radius, 0, 2 * Math.PI, xAxis, yAxis);
            Curve proj2 = Arc.Create(_ptEnd, radius, 0, 2 * Math.PI, xAxis, yAxis);


            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate sub-surface and its mark");

                Plane       Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
                SketchPlane sketch    = SketchPlane.Create(doc, Geomplane);

                ModelCurve modelline1 = doc.Create.NewModelCurve(proj1, sketch) as ModelCurve;
                ModelCurve modelline2 = doc.Create.NewModelCurve(proj2, sketch) as ModelCurve;

                tx.Commit();
            }

            return(Result.Succeeded);
        }