コード例 #1
0
ファイル: DynamoRevitTests.cs プロジェクト: jtabtabai/Dynamo
        /// <summary>
        /// Creates one model curve on a plane with an origin at 0,0,0
        /// </summary>
        /// <param name="mc1"></param>
        protected void CreateOneModelCurve(out ModelCurve mc1)
        {
            //create two model curves
            using (_trans = _trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "CreateTwoModelCurves"))
            {
                _trans.Start();

                var p1 = new Plane(XYZ.BasisZ, XYZ.Zero);

                SketchPlane sp1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p1);
                Curve       c1  = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0));
                mc1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c1, sp1);

                _trans.Commit();
            }
        }
コード例 #2
0
ファイル: DynamoRevitTests.cs プロジェクト: jimmplan/Dynamo
        /// <summary>
        /// Creates one model curve on a plane with an origin at 0,0,0
        /// </summary>
        /// <param name="mc1"></param>
        protected void CreateOneModelCurve(out ModelCurve mc1)
        {
            //create two model curves
            using (_trans = _trans = new Transaction(dynRevitSettings.Doc.Document, "CreateTwoModelCurves"))
            {
                _trans.Start();

                Plane p1 = new Plane(XYZ.BasisZ, XYZ.Zero);

                SketchPlane sp1 = dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(p1);
                Curve       c1  = dynRevitSettings.Revit.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0));
                mc1 = dynRevitSettings.Doc.Document.FamilyCreate.NewModelCurve(c1, sp1);

                _trans.Commit();
            }
        }
コード例 #3
0
        public static Curve Flatten3dCurveOnPlane(Curve c, Plane plane)
        {
            XYZ        meanPt = null;
            List <XYZ> orderedEigenvectors;
            XYZ        normal;

            if (c is HermiteSpline)
            {
                var hs = c as HermiteSpline;
                if (plane == null)
                {
                    plane = GetPlaneFromCurve(c, false);
                }
                var projPoints = new List <XYZ>();
                foreach (var pt in hs.ControlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return(dynRevitSettings.Revit.Application.Create.NewHermiteSpline(projPoints, false));
            }

            if (c is NurbSpline)
            {
                var ns = c as NurbSpline;
                BestFitLine.PrincipalComponentsAnalysis(ns.CtrlPoints.ToList(), out meanPt, out orderedEigenvectors);
                normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]).Normalize();
                if (plane == null)
                {
                    plane = dynRevitSettings.Doc.Application.Application.Create.NewPlane(normal, meanPt);
                }

                var projPoints = new List <XYZ>();
                foreach (var pt in ns.CtrlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return(dynRevitSettings.Revit.Application.Create.NewNurbSpline(projPoints, ns.Weights, ns.Knots, ns.Degree, ns.isClosed, ns.isRational));
            }

            return(c);
        }
コード例 #4
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var pts = ((FScheme.Value.List)args[0]).Item.Select(
                x => ((ReferencePoint)((FScheme.Value.Container)x).Item).Position
                ).ToList();

            if (pts.Count <= 1)
            {
                throw new Exception("Not enough reference points to make a curve.");
            }

            var ns = UIDocument.Application.Application.Create.NewNurbSpline(
                pts, Enumerable.Repeat(1.0, pts.Count).ToList());

            ModelNurbSpline c;

            if (Elements.Any() && dynUtils.TryGetElement(Elements[0], out c))
            {
                ModelCurve.setCurveMethod(c, ns); //c.GeometryCurve = ns;
            }
            else
            {
                Elements.Clear();

                double    rawParam = ns.ComputeRawParameter(.5);
                Transform t        = ns.ComputeDerivatives(rawParam, false);

                XYZ norm = t.BasisZ;

                if (norm.GetLength() == 0)
                {
                    norm = XYZ.BasisZ;
                }

                Autodesk.Revit.DB.Plane       p  = new Autodesk.Revit.DB.Plane(norm, t.Origin);
                Autodesk.Revit.DB.SketchPlane sp = this.UIDocument.Document.FamilyCreate.NewSketchPlane(p);
                //sps.Add(sp);

                c = UIDocument.Document.FamilyCreate.NewModelCurve(ns, sp) as ModelNurbSpline;

                Elements.Add(c.Id);
            }

            return(FScheme.Value.NewContainer(c));
        }
コード例 #5
0
        public Autodesk.Revit.DB.ModelCurve MakeLine(Document doc, XYZ ptA, XYZ ptB)
        {
            Autodesk.Revit.ApplicationServices.Application app = doc.Application;
            // Create plane by the points
            Line   line   = app.Create.NewLine(ptA, ptB, true);
            XYZ    norm   = ptA.CrossProduct(ptB);
            double length = norm.GetLength();

            if (length == 0)
            {
                norm = XYZ.BasisZ;
            }
            Autodesk.Revit.DB.Plane       plane   = app.Create.NewPlane(norm, ptB);
            Autodesk.Revit.DB.SketchPlane skplane = doc.FamilyCreate.NewSketchPlane(plane);
            // Create line here
            Autodesk.Revit.DB.ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(line, skplane);
            return(modelcurve);
        }
コード例 #6
0
ファイル: Plane.cs プロジェクト: l2obin/Dynamo
        bool resetPlaneofSketchPlaneElement(Autodesk.Revit.DB.SketchPlane sp, Autodesk.Revit.DB.Plane p)
        {
            XYZ newOrigin = p.Origin;
            XYZ newNorm   = p.Normal;
            var oldP      = sp.Plane;
            XYZ oldOrigin = oldP.Origin;
            XYZ oldNorm   = oldP.Normal;

            if (oldNorm.IsAlmostEqualTo(newNorm))
            {
                XYZ moveVec = newOrigin - oldOrigin;
                if (moveVec.GetLength() > 0.000000001)
                {
                    ElementTransformUtils.MoveElement(this.UIDocument.Document, sp.Id, moveVec);
                }
                return(true);
            }
            //rotation might not work for sketch planes
            return(false);
        }
コード例 #7
0
ファイル: SketchPlane.cs プロジェクト: vtaran/Dynamo
        /// <summary>
        /// Make a SketchPlane from a plane
        /// </summary>
        /// <param name="p"></param>
        private SketchPlane(Autodesk.Revit.DB.Plane p)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.SketchPlane>(Document);

            //There was an element, bind & mutate
            if (oldEle != null)
            {
                InternalSetSketchPlane(oldEle);
                if (InternalSetPlane(p))
                {
                    return;
                }

                // if setting the plane fails, we delete the old Element
                // in order to create a new one
                DocumentManager.Instance.DeleteElement(oldEle.Id);
            }

            //Phase 2- There was no existing element, create new
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.SketchPlane sp;

            if (Document.IsFamilyDocument)
            {
                sp = Document.FamilyCreate.NewSketchPlane(p);
            }
            else
            {
                sp = Document.Create.NewSketchPlane(p);
            }

            InternalSetSketchPlane(sp);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
コード例 #8
0
        /// <summary>
        /// Convert a DS Arc to a Revit arc
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Arc arc)
        {
            // convert
            var center = arc.CenterPoint.ToXyz();
            var sp     = arc.StartPoint.ToXyz();

            // get the xaxis of the arc base plane
            var x = (sp - center).Normalize();

            // get a second vector in the plane
            var vecY = (arc.PointAtParameter(0.1).ToXyz() - center);

            // get the normal to the plane
            var n2 = x.CrossProduct(vecY).Normalize();

            // obtain the y axis in the plane - perp to x and z
            var y = n2.CrossProduct(x);

            var plane = new Autodesk.Revit.DB.Plane(x, y, center);

            return(Autodesk.Revit.DB.Arc.Create(plane, arc.Radius, 0, arc.SweepAngle.ToRadians()));
        }
コード例 #9
0
ファイル: ModelCurve.cs プロジェクト: ikeough/DynamoRevit
        /// <summary>
        /// Set the plane and the curve internally.
        /// </summary>
        private void InternalSetSketchPlaneFromCurve(Curve newCurve)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            Plane newPlane = CurveUtils.GetPlaneFromCurve(newCurve, false);
            Plane oldPlane = InternalCurveElement.SketchPlane.GetPlane();

            var angleBetweenPlanes     = newPlane.Normal.AngleTo(oldPlane.Normal);
            var distanceBetweenOrigins = newPlane.Origin.DistanceTo(oldPlane.Origin);

            Autodesk.Revit.DB.SketchPlane sp = null;

            // Planes are different.
            if (angleBetweenPlanes > tolerance || distanceBetweenOrigins > tolerance)
            {
                sp = GetSketchPlaneFromCurve(newCurve);
                InternalCurveElement.SetSketchPlaneAndCurve(sp, newCurve);
            }
            // Planes are the same.
            else
            {
                InternalSetCurve(newCurve);
            }

            string idSpUnused = String.Empty;

            if (sp != null && InternalCurveElement.SketchPlane.Id != sp.Id)
            {
                idSpUnused = sp.UniqueId;
            }

            // if we got a valid id, delete the old sketch plane
            if (idSpUnused != String.Empty)
            {
                DocumentManager.Instance.DeleteElement(new ElementUUID(idSpUnused));
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
コード例 #10
0
        private static Curve Flatten3dCurveOnPlane(Curve c, Plane plane)
        {
            if (c is Autodesk.Revit.DB.HermiteSpline)
            {
                var hs = c as Autodesk.Revit.DB.HermiteSpline;
                plane = CurveUtils.GetPlaneFromCurve(c, false);
                var projPoints = new List <XYZ>();
                foreach (var pt in hs.ControlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return(Autodesk.Revit.DB.HermiteSpline.Create(projPoints, false));
            }

            if (c is Autodesk.Revit.DB.NurbSpline)
            {
                var ns = c as Autodesk.Revit.DB.NurbSpline;
                if (plane == null)
                {
                    var bestFitPlane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(
                        ns.CtrlPoints.ToList().ToPoints(false));

                    plane = bestFitPlane.ToPlane(false);
                }

                var projPoints = new List <XYZ>();
                foreach (var pt in ns.CtrlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return(Autodesk.Revit.DB.NurbSpline.Create(projPoints, ns.Weights.Cast <double>().ToList(), ns.Knots.Cast <double>().ToList(), ns.Degree, ns.isClosed, ns.isRational));
            }

            return(c);
        }
コード例 #11
0
        /// <summary>
        /// Attempt to set the plane of an existing SketchPlane
        /// </summary>
        /// <param name="p"></param>
        /// <returns>False if the new sketch plane is not parallel to the existing one</returns>
        private bool InternalSetPlane(Autodesk.Revit.DB.Plane p)
        {
            var sp = this.InternalSketchPlane;

            XYZ newOrigin = p.Origin;
            XYZ newNorm   = p.Normal;
            var oldP      = sp.GetPlane();
            XYZ oldOrigin = oldP.Origin;
            XYZ oldNorm   = oldP.Normal;

            if (oldNorm.IsAlmostEqualTo(newNorm))
            {
                XYZ moveVec = newOrigin - oldOrigin;
                if (moveVec.GetLength() > 0.000000001)
                {
                    ElementTransformUtils.MoveElement(Document, sp.Id, moveVec);
                }
                return(true);
            }

            return(false);
        }
コード例 #12
0
        private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Circle circ)
        {
            // convert
            var center = circ.CenterPoint.ToXyz(false);
            var sp     = circ.StartPoint.ToXyz(false);

            // get the xaxis of the arc base plane normalized
            var x = (sp - center).Normalize();

            // get a second vector in the plane
            var vecY = (circ.PointAtParameter(0.1).ToXyz(false) - center);

            // get the normal to the plane
            var n2 = x.CrossProduct(vecY).Normalize();

            // obtain the y axis in the plane - perp to x and z
            var y = n2.CrossProduct(x);

            var plane = new Autodesk.Revit.DB.Plane(x, y, center);

            return(Autodesk.Revit.DB.Arc.Create(plane, circ.Radius, 0, 2 * System.Math.PI));
        }
コード例 #13
0
ファイル: Intersect.cs プロジェクト: l2obin/Dynamo
        private XYZ linePlaneIntersection(Autodesk.Revit.DB.Plane plane, XYZ p0, XYZ p1)
        {
            //http://www.thepolygoners.com/tutorials/lineplane/lineplane.html

            var v     = (p1 - p0);
            var n     = plane.Normal;
            var p2    = plane.Origin;
            var denom = n.DotProduct(v);

            //line is parallel to plane
            if (denom == 0.0)
            {
                return(null);
            }

            var t = n.DotProduct(p2 - p0) / denom;

            if (t >= 0 && t <= 1)
            {
                return(p0 + v.Multiply(t));
            }

            return(null);
        }
コード例 #14
0
 static public Rhino.Geometry.Plane ToRhino(this Autodesk.Revit.DB.Plane plane)
 {
     return(new Rhino.Geometry.Plane(plane.Origin.ToRhino(), (Vector3d)plane.XVec.ToRhino(), (Vector3d)plane.YVec.ToRhino()));
 }
コード例 #15
0
        private static Autodesk.Revit.DB.SketchPlane GetSketchPlaneFromCurve(Curve c)
        {
            Plane plane = CurveUtils.GetPlaneFromCurve(c, false);

            return(Autodesk.Revit.DB.SketchPlane.Create(Document, plane));
        }
コード例 #16
0
ファイル: RevitUtils.cs プロジェクト: kscalvin/Dynamo
        public static XYZ ProjectPointOnPlane(XYZ pt, Plane plane)
        {
            var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;

            return proj;
        }
コード例 #17
0
ファイル: ReferenceCurve.cs プロジェクト: jimmplan/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var c = (Curve)((FScheme.Value.Container)args[0]).Item;

            Autodesk.Revit.DB.ModelCurve mc = null;

            Curve flattenCurve = null;

            Autodesk.Revit.DB.Plane plane = dynRevitUtils.GetPlaneFromCurve(c, false);

            //instead of changing Revit curve keep it "as is"
            //user might have trouble modifying curve in Revit if it is off the sketch plane

            if (this.Elements.Any())
            {
                bool needsRemake = false;
                if (dynUtils.TryGetElement(this.Elements[0], out mc))
                {
                    ElementId idSpUnused = ModelCurve.resetSketchPlaneMethod(mc, c, plane, out needsRemake);

                    if (idSpUnused != ElementId.InvalidElementId)
                    {
                        this.DeleteElement(idSpUnused);
                    }
                    //mc.SketchPlane = sp;
                    if (!needsRemake)
                    {
                        if (!mc.GeometryCurve.IsBound && c.IsBound)
                        {
                            c = c.Clone();
                            c.MakeUnbound();
                        }
                        ModelCurve.setCurveMethod(mc, c);  //mc.GeometryCurve = c;
                    }
                    else
                    {
                        this.DeleteElement(this.Elements[0]);
                    }
                }
                else
                {
                    needsRemake = true;
                }
                if (needsRemake)
                {
                    var sp = dynRevitUtils.GetSketchPlaneFromCurve(c);

                    if (dynRevitUtils.GetPlaneFromCurve(c, true) == null)
                    {
                        flattenCurve = dynRevitUtils.Flatten3dCurveOnPlane(c, plane);
                        mc           = this.UIDocument.Document.IsFamilyDocument
                             ? this.UIDocument.Document.FamilyCreate.NewModelCurve(flattenCurve, sp)
                                : this.UIDocument.Document.Create.NewModelCurve(flattenCurve, sp);

                        ModelCurve.setCurveMethod(mc, c);
                    }
                    else
                    {
                        mc = this.UIDocument.Document.IsFamilyDocument
                       ? this.UIDocument.Document.FamilyCreate.NewModelCurve(c, sp)
                       : this.UIDocument.Document.Create.NewModelCurve(c, sp);
                    }
                    mc.ChangeToReferenceLine();
                    this.Elements[0] = mc.Id;
                    //mc.SketchPlane = sp;
                    if (mc.SketchPlane.Id != sp.Id)
                    {
                        //THIS BIZARRE as Revit could use different existing SP, so if Revit had found better plane  this sketch plane has no use
                        this.DeleteElement(sp.Id);
                    }
                    this.Elements[0] = mc.Id;
                }
            }
            else
            {
                var sp = dynRevitUtils.GetSketchPlaneFromCurve(c);

                if (dynRevitUtils.GetPlaneFromCurve(c, true) == null)
                {
                    flattenCurve = dynRevitUtils.Flatten3dCurveOnPlane(c, plane);
                    mc           = this.UIDocument.Document.IsFamilyDocument
                         ? this.UIDocument.Document.FamilyCreate.NewModelCurve(flattenCurve, sp)
                            : this.UIDocument.Document.Create.NewModelCurve(flattenCurve, sp);

                    ModelCurve.setCurveMethod(mc, c);
                }
                else
                {
                    mc = this.UIDocument.Document.IsFamilyDocument
                       ? this.UIDocument.Document.FamilyCreate.NewModelCurve(c, sp)
                       : this.UIDocument.Document.Create.NewModelCurve(c, sp);
                }
                this.Elements.Add(mc.Id);
                mc.ChangeToReferenceLine();
                //mc.SketchPlane = sp;
                if (mc.SketchPlane.Id != sp.Id)
                {
                    //found better plane
                    this.DeleteElement(sp.Id);
                }
            }

            return(FScheme.Value.NewContainer(mc));
        }
コード例 #18
0
ファイル: ModelCurve.cs プロジェクト: jimmplan/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            Autodesk.Revit.DB.CurveLoop cl = (Autodesk.Revit.DB.CurveLoop)((FScheme.Value.Container)args[0]).Item;

            if (cl == null)
            {
                throw new InvalidOperationException("No curve loop");
            }

            Autodesk.Revit.DB.Plane plane = cl.GetPlane();
            if (plane == null)
            {
                throw new InvalidOperationException("Curve loop is not planar");
            }

            var mcs = new System.Collections.Generic.List <Autodesk.Revit.DB.ModelCurve>();

            var listCurves           = new System.Collections.Generic.List <Curve> ();
            CurveLoopIterator CLiter = cl.GetCurveLoopIterator();

            for (; CLiter.MoveNext();)
            {
                listCurves.Add(CLiter.Current.Clone());
            }

            int numCurves = listCurves.Count;

            Autodesk.Revit.DB.SketchPlane sp = null;
            for (int index = 0; index < numCurves; index++)
            {
                //instead of changing Revit curve keep it "as is"
                //user might have trouble modifying curve in Revit if it is off the sketch plane
                Autodesk.Revit.DB.ModelCurve mc = null;
                if (this.Elements.Any() && index < this.Elements.Count)
                {
                    bool needsRemake = false;
                    if (dynUtils.TryGetElement(this.Elements[index], out mc))
                    {
                        ElementId idSpUnused = ModelCurve.resetSketchPlaneMethod(mc, listCurves[index], plane, out needsRemake);

                        if (idSpUnused != ElementId.InvalidElementId && index == numCurves - 1)
                        {
                            this.DeleteElement(idSpUnused);
                        }
                        if (!needsRemake)
                        {
                            if (!mc.GeometryCurve.IsBound && listCurves[index].IsBound)
                            {
                                listCurves[index] = listCurves[index].Clone();
                                listCurves[index].MakeUnbound();
                            }
                            ModelCurve.setCurveMethod(mc, listCurves[index]); // mc.GeometryCurve = c;
                        }
                        else
                        {
                            this.DeleteElement(this.Elements[index]);
                        }
                    }
                    else
                    {
                        needsRemake = true;
                    }
                    if (needsRemake)
                    {
                        if (sp == null)
                        {
                            sp = dynRevitSettings.Doc.Document.IsFamilyDocument ?
                                 dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(plane) :
                                 dynRevitSettings.Doc.Document.Create.NewSketchPlane(plane);
                        }
                        if (dynRevitUtils.GetPlaneFromCurve(listCurves[index], true) == null)
                        {
                            mc = this.UIDocument.Document.IsFamilyDocument
                                ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp)
                                : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp);

                            ModelCurve.setCurveMethod(mc, listCurves[index]);
                        }
                        else
                        {
                            mc = this.UIDocument.Document.IsFamilyDocument
                                ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp)
                                : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp);
                        }
                        if (index < this.Elements.Count)
                        {
                            this.Elements[index] = mc.Id;
                        }
                        else
                        {
                            this.Elements.Add(mc.Id);
                        }
                        if (mc.SketchPlane.Id != sp.Id && index == numCurves - 1)
                        {
                            //THIS BIZARRE as Revit could use different existing SP, so if Revit had found better plane  this sketch plane has no use
                            this.DeleteElement(sp.Id);
                        }
                    }
                }
                else
                {
                    if (sp == null)
                    {
                        sp = dynRevitSettings.Doc.Document.IsFamilyDocument ?
                             dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(plane) :
                             dynRevitSettings.Doc.Document.Create.NewSketchPlane(plane);
                    }

                    if (dynRevitUtils.GetPlaneFromCurve(listCurves[index], true) == null)
                    {
                        mc = this.UIDocument.Document.IsFamilyDocument
                            ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp)
                            : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp);

                        ModelCurve.setCurveMethod(mc, listCurves[index]);
                    }
                    else
                    {
                        mc = this.UIDocument.Document.IsFamilyDocument
                            ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp)
                            : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp);
                    }
                    this.Elements.Add(mc.Id);
                    if (mc.SketchPlane.Id != sp.Id && index == numCurves - 1)
                    {
                        //found better plane
                        this.DeleteElement(sp.Id);
                    }
                }
                if (mc != null)
                {
                    mcs.Add(mc);
                }
            }
            FSharpList <FScheme.Value> results = FSharpList <FScheme.Value> .Empty;

            foreach (var mc in mcs)
            {
                results = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(mc), results);
            }
            return(FScheme.Value.NewList(Utils.SequenceToFSharpList(results.Reverse())));
        }
コード例 #19
0
        public static XYZ ProjectPointOnPlane(XYZ pt, Plane plane)
        {
            var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;

            return(proj);
        }
コード例 #20
0
 public static Plane ToPlane(this DB.Plane value)
 {
     var rhino = RawDecoder.AsPlane(value); UnitConverter.Scale(ref rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
コード例 #21
0
 public static Plane ToRhino(DB.Plane plane)
 {
     return(new Plane(ToRhino(plane.Origin), (Vector3d)ToRhino(plane.XVec), (Vector3d)ToRhino(plane.YVec)));
 }
コード例 #22
0
        //returns unused sketch plane id
        static public ElementId resetSketchPlaneMethod(Autodesk.Revit.DB.ModelCurve mc, Curve c, Autodesk.Revit.DB.Plane flattenedOnPlane, out bool needsSketchPlaneReset)
        {
            //do we need to reset?
            needsSketchPlaneReset = false;
            Autodesk.Revit.DB.Plane newPlane = flattenedOnPlane != null ? flattenedOnPlane : dynRevitUtils.GetPlaneFromCurve(c, false);

            Autodesk.Revit.DB.Plane curPlane = mc.SketchPlane.Plane;

            bool resetPlane = false;

            {
                double llSqCur         = curPlane.Normal.DotProduct(curPlane.Normal);
                double llSqNew         = newPlane.Normal.DotProduct(newPlane.Normal);
                double dotP            = newPlane.Normal.DotProduct(curPlane.Normal);
                double dotSqNormalized = (dotP / llSqCur) * (dotP / llSqNew);
                double angleTol        = Math.PI / 1800.0;
                if (dotSqNormalized < 1.0 - angleTol * angleTol)
                {
                    resetPlane = true;
                }
            }
            Autodesk.Revit.DB.SketchPlane sp = null;

            if (!resetPlane)
            {
                double originDiff = curPlane.Normal.DotProduct(curPlane.Origin - newPlane.Origin);
                double tolerance  = 0.000001;
                if (originDiff > tolerance || originDiff < -tolerance)
                {
                    sp             = dynRevitUtils.GetSketchPlaneFromCurve(c);
                    mc.SketchPlane = dynRevitUtils.GetSketchPlaneFromCurve(c);
                }
                return((sp == null || mc.SketchPlane.Id == sp.Id) ? ElementId.InvalidElementId : sp.Id);
            }

            //do reset if method is available

            bool foundMethod = false;

            if (hasMethodResetSketchPlane)
            {
                Type          CurveElementType        = typeof(Autodesk.Revit.DB.CurveElement);
                MethodInfo[]  curveElementMethods     = CurveElementType.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                System.String nameOfMethodSetCurve    = "ResetSketchPlaneAndCurve";
                System.String nameOfMethodSetCurveAlt = "SetSketchPlaneAndCurve";

                foreach (MethodInfo m in curveElementMethods)
                {
                    if (m.Name == nameOfMethodSetCurve || m.Name == nameOfMethodSetCurveAlt)
                    {
                        object[] argsM = new object[2];
                        sp       = dynRevitUtils.GetSketchPlaneFromCurve(c);
                        argsM[0] = sp;
                        argsM[1] = null;

                        foundMethod = true;
                        m.Invoke(mc, argsM);
                        break;
                    }
                }
            }
            if (!foundMethod)
            {
                //sp = dynRevitUtils.GetSketchPlaneFromCurve(c);
                hasMethodResetSketchPlane = false;
                needsSketchPlaneReset     = true;
                //expect exception, so try to keep old plane?
                //mc.SketchPlane = sp;
                return(ElementId.InvalidElementId);
            }

            if (sp != null && mc.SketchPlane.Id != sp.Id)
            {
                return(sp.Id);
            }

            return(ElementId.InvalidElementId);
        }
コード例 #23
0
ファイル: ProtoToRevitCurve.cs プロジェクト: heegwon/Dynamo
        private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Circle circ)
        {
            // convert
            var center = circ.CenterPoint.ToXyz(false);
            var sp = circ.StartPoint.ToXyz(false);

            // get the xaxis of the arc base plane normalized
            var x = (sp - center).Normalize();

            // get a second vector in the plane
            var vecY = (circ.PointAtParameter(0.1).ToXyz(false) - center);

            // get the normal to the plane
            var n2 = x.CrossProduct(vecY).Normalize();

            // obtain the y axis in the plane - perp to x and z
            var y = n2.CrossProduct(x);

            var plane = new Autodesk.Revit.DB.Plane(x, y, center);
            return Autodesk.Revit.DB.Arc.Create(plane, circ.Radius, 0, 2 * System.Math.PI);
        }
コード例 #24
0
        /***************************************************/
        /****              Private Methods              ****/
        /***************************************************/

        private static Dictionary <PlanarSurface, List <PlanarSurface> > PanelSurfaces_HostDocument(this HostObject hostObject, IEnumerable <ElementId> insertsToIgnore = null, RevitSettings settings = null)
        {
            List <Autodesk.Revit.DB.Plane> planes = hostObject.IPanelPlanes();

            if (planes.Count == 0)
            {
                return(null);
            }

            Document doc = hostObject.Document;
            Dictionary <PlanarSurface, List <PlanarSurface> > result = new Dictionary <PlanarSurface, List <PlanarSurface> >();

            IList <ElementId> inserts = hostObject.FindInserts(true, true, true, true);

            if (insertsToIgnore != null)
            {
                inserts = inserts.Where(x => insertsToIgnore.All(y => x.IntegerValue != y.IntegerValue)).ToList();
            }

            Transaction            t = new Transaction(doc);
            FailureHandlingOptions failureHandlingOptions = t.GetFailureHandlingOptions().SetClearAfterRollback(true);

            t.Start("Temp Delete Inserts And Unjoin Geometry");

            try
            {
                foreach (ElementId id in JoinGeometryUtils.GetJoinedElements(doc, hostObject))
                {
                    JoinGeometryUtils.UnjoinGeometry(doc, hostObject, doc.GetElement(id));
                }

                if (hostObject is Wall)
                {
                    WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 0);
                    WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 1);
                }

                if (insertsToIgnore != null)
                {
                    doc.Delete(insertsToIgnore.ToList());
                }

                doc.Regenerate();

                List <Solid> solidsWithOpenings = hostObject.Solids(new Options());
                List <Solid> fullSolids;

                if (inserts.Count != 0)
                {
                    solidsWithOpenings = solidsWithOpenings.Select(x => SolidUtils.Clone(x)).ToList();

                    doc.Delete(inserts);
                    doc.Regenerate();

                    fullSolids = hostObject.Solids(new Options());
                }
                else
                {
                    fullSolids = solidsWithOpenings;
                }

                fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList();
                if (hostObject is Wall)
                {
                    fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, planes[0]));
                    Autodesk.Revit.DB.Plane flippedPlane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin + planes[0].Normal * 1e-3);
                    fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, flippedPlane));
                    fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList();
                    planes[0]  = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin);
                }


                foreach (Autodesk.Revit.DB.Plane plane in planes)
                {
                    foreach (Solid s in fullSolids)
                    {
                        List <CurveLoop> loops = new List <CurveLoop>();
                        foreach (Autodesk.Revit.DB.Face f in s.Faces)
                        {
                            PlanarFace pf = f as PlanarFace;
                            if (pf == null)
                            {
                                continue;
                            }

                            if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance)
                            {
                                loops.AddRange(pf.GetEdgesAsCurveLoops());
                            }
                        }

                        CurveLoop            outline  = loops.FirstOrDefault(x => x.IsCounterclockwise(plane.Normal));
                        PlanarSurface        surface  = new PlanarSurface(outline.FromRevit(), null);
                        List <PlanarSurface> openings = new List <PlanarSurface>();
                        foreach (CurveLoop loop in loops.Where(x => x != outline))
                        {
                            openings.Add(new PlanarSurface(loop.FromRevit(), null));
                        }

                        if (inserts.Count != 0)
                        {
                            List <Solid> openingVolumes = new List <Solid>();
                            foreach (Solid s2 in solidsWithOpenings)
                            {
                                openingVolumes.Add(BooleanOperationsUtils.ExecuteBooleanOperation(s, s2, BooleanOperationsType.Difference));
                            }

                            foreach (Solid s2 in openingVolumes)
                            {
                                foreach (Autodesk.Revit.DB.Face f in s2.Faces)
                                {
                                    PlanarFace pf = f as PlanarFace;
                                    if (pf == null)
                                    {
                                        continue;
                                    }

                                    if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance)
                                    {
                                        foreach (CurveLoop cl in pf.GetEdgesAsCurveLoops())
                                        {
                                            openings.Add(new PlanarSurface(cl.FromRevit(), null));
                                        }
                                    }
                                }
                            }
                        }

                        result.Add(surface, openings);
                    }
                }
            }
            catch
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Geometrical processing of a Revit element failed due to an internal Revit error. Converted panel might be missing one or more of its surfaces. Revit ElementId: {0}", hostObject.Id));
            }

            t.RollBack(failureHandlingOptions);

            return(result);
        }
コード例 #25
0
 public static Plane ToRhino(this DB.Plane plane)
 {
     return(new Plane(plane.Origin.ToRhino(), (Vector3d)plane.XVec.ToRhino(), (Vector3d)plane.YVec.ToRhino()));
 }
コード例 #26
0
        /// <summary>
        /// Convert a DS Arc to a Revit arc
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        private static Autodesk.Revit.DB.Arc Convert(Autodesk.DesignScript.Geometry.Arc arc)
        {
            // convert
            var center = arc.CenterPoint.ToXyz();
            var sp = arc.StartPoint.ToXyz();

            // get the xaxis of the arc base plane
            var x = (sp - center).Normalize();

            // get a second vector in the plane
            var vecY = (arc.PointAtParameter(0.1).ToXyz() - center);

            // get the normal to the plane
            var n2 = x.CrossProduct(vecY).Normalize();

            // obtain the y axis in the plane - perp to x and z
            var y = n2.CrossProduct(x);

            var plane = new Autodesk.Revit.DB.Plane(x, y, center);
            return Autodesk.Revit.DB.Arc.Create(plane, arc.Radius, 0, arc.SweepAngle.ToRadians());
        }
コード例 #27
0
 public static PlaneSurface ToRhino(this DB.Plane surface, DB.BoundingBoxUV bboxUV) => RawDecoder.ToRhino(surface, bboxUV);
コード例 #28
0
        /// <summary>
        /// Creates one model curve on a plane with an origin at 0,0,0
        /// </summary>
        /// <param name="mc1"></param>
        protected void CreateOneModelCurve(out ModelCurve mc1)
        {
            //create two model curves
            using (_trans = _trans = new Transaction(dynRevitSettings.Doc.Document, "CreateTwoModelCurves"))
            {
                _trans.Start();

                Plane p1 = new Plane(XYZ.BasisZ, XYZ.Zero);

                SketchPlane sp1 = dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(p1);
                Curve c1 = dynRevitSettings.Revit.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0));
                mc1 = dynRevitSettings.Doc.Document.FamilyCreate.NewModelCurve(c1, sp1);

                _trans.Commit();
            }
        }
コード例 #29
0
ファイル: Intersect.cs プロジェクト: l2obin/Dynamo
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var  crv  = (Curve)((Value.Container)args[0]).Item;
            Face face = null;

            Autodesk.Revit.DB.Plane thisPlane = null;

            var geo = ((Value.Container)args[1]).Item;

            IntersectionResultArray xsects = null;

            if (geo is Face)
            {
                face = geo as Face;
            }
            else if (geo is Autodesk.Revit.DB.Plane)
            {
                #region plane processing

                thisPlane = geo as Autodesk.Revit.DB.Plane;

                face = buildFaceOnPlaneByCurveExtensions(crv, thisPlane);

                #endregion
            }

            var result = face.Intersect(crv, out xsects);

            //var xsect_results = FSharpList<Value>.Empty;
            var xsect_xyzs        = FSharpList <Value> .Empty;
            var xsect_face_uvs    = FSharpList <Value> .Empty;
            var xsect_params      = FSharpList <Value> .Empty;
            var xsect_edges       = FSharpList <Value> .Empty;
            var xsect_edge_params = FSharpList <Value> .Empty;

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

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

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

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

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

            outPuts[_edgeTPort]  = Value.NewList(xsect_edge_params);
            outPuts[_edgePort]   = Value.NewList(xsect_edges);
            outPuts[_tPort]      = Value.NewList(xsect_params);
            outPuts[_uvPort]     = Value.NewList(xsect_face_uvs);
            outPuts[_xyzPort]    = Value.NewList(xsect_xyzs);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }
コード例 #30
0
 /// <summary>
 /// Make a SketchPlane from a plane
 /// </summary>
 /// <param name="p"></param>
 private SketchPlane(Autodesk.Revit.DB.Plane p)
 {
     SafeInit(() => InitSketchPlane(p));
 }
コード例 #31
0
ファイル: Annotation.cs プロジェクト: riteshchandawar/Dynamo
        private static Autodesk.Revit.DB.ModelText CreateModelText(XYZ normal, XYZ position, XYZ up, string text, ModelTextType mtt,
                                                 double depth)
        {
            Autodesk.Revit.DB.ModelText mt = null;
            var xAxis = normal.CrossProduct(up).Normalize();
            var yAxis = normal.CrossProduct(xAxis).Normalize();
            var plane = new Autodesk.Revit.DB.Plane(xAxis, yAxis, position);

            var sp = Autodesk.Revit.DB.SketchPlane.Create(dynRevitSettings.Doc.Document, plane);
            mt = dynRevitSettings.Doc.Document.FamilyCreate.NewModelText(text, mtt, sp, position, HorizontalAlign.Left, depth);
            return mt;
        }
コード例 #32
0
ファイル: Intersect.cs プロジェクト: l2obin/Dynamo
        public static Face buildFaceOnPlaneByCurveExtensions(Curve crv, Autodesk.Revit.DB.Plane thisPlane)
        {
            Face face = null;
            // tesselate curve and find uv envelope in projection to the plane
            IList <XYZ> tessCurve      = crv.Tessellate();
            var         curvePointEnum = tessCurve.GetEnumerator();
            var         corner1        = new XYZ();
            var         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;

            var cLoop = new Autodesk.Revit.DB.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);
            }
            var listCLoops = new List <Autodesk.Revit.DB.CurveLoop> {
                cLoop
            };

            Solid 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)
                {
                    var 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.");
            }

            return(face);
        }
コード例 #33
0
 public static Plane AsPlane(DB.Plane plane)
 {
     return(new Plane(AsPoint3d(plane.Origin), AsVector3d(plane.XVec), AsVector3d(plane.YVec)));
 }
コード例 #34
0
ファイル: ModelCurve.cs プロジェクト: algobasket/Dynamo
        private static Curve Flatten3dCurveOnPlane(Curve c, Plane plane)
        {
            XYZ meanPt = null;
            List<XYZ> orderedEigenvectors;
            XYZ normal;

            if (c is Autodesk.Revit.DB.HermiteSpline)
            {
                var hs = c as Autodesk.Revit.DB.HermiteSpline;
                plane = GetPlaneFromCurve(c, false);
                var projPoints = new List<XYZ>();
                foreach (var pt in hs.ControlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return Autodesk.Revit.DB.HermiteSpline.Create(projPoints, false);
            }

            if (c is Autodesk.Revit.DB.NurbSpline)
            {
                var ns = c as Autodesk.Revit.DB.NurbSpline;
                if (plane == null)
                {
                   PrincipalComponentsAnalysis(ns.CtrlPoints.ToList(), out meanPt, out orderedEigenvectors);
                   normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]).Normalize();

                   plane = Document.Application.Create.NewPlane(normal, meanPt);
                }

                var projPoints = new List<XYZ>();
                foreach (var pt in ns.CtrlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return Autodesk.Revit.DB.NurbSpline.Create(projPoints, ns.Weights.Cast<double>().ToList(), ns.Knots.Cast<double>().ToList(), ns.Degree, ns.isClosed, ns.isRational);
            }

            return c;
        }
コード例 #35
0
 public static Autodesk.DesignScript.Geometry.Plane ToPlane(this Autodesk.Revit.DB.Plane plane, bool convertUnits = true)
 {
     return(Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(plane.Origin.ToPoint(convertUnits), plane.Normal.ToVector()));
 }
コード例 #36
0
ファイル: ModelCurve.cs プロジェクト: RobertiF/Dynamo
        private static Curve Flatten3dCurveOnPlane(Curve c, Plane plane)
        {
            if (c is Autodesk.Revit.DB.HermiteSpline)
            {
                var hs = c as Autodesk.Revit.DB.HermiteSpline;
                plane = CurveUtils.GetPlaneFromCurve(c, false);
                var projPoints = new List<XYZ>();
                foreach (var pt in hs.ControlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return Autodesk.Revit.DB.HermiteSpline.Create(projPoints, false);
            }

            if (c is Autodesk.Revit.DB.NurbSpline)
            {
                var ns = c as Autodesk.Revit.DB.NurbSpline;
                if (plane == null)
                {
                    var bestFitPlane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(
                        ns.CtrlPoints.ToList().ToPoints(false));

                    plane = bestFitPlane.ToPlane(false);
                }

                var projPoints = new List<XYZ>();
                foreach (var pt in ns.CtrlPoints)
                {
                    var proj = pt - (pt - plane.Origin).DotProduct(plane.Normal) * plane.Normal;
                    projPoints.Add(proj);
                }

                return Autodesk.Revit.DB.NurbSpline.Create(projPoints, ns.Weights.Cast<double>().ToList(), ns.Knots.Cast<double>().ToList(), ns.Degree, ns.isClosed, ns.isRational);
            }

            return c;
        }
コード例 #37
0
        public RevitPipeConverter()
        {
            var ptConv = new PointConverter();

            AddConverter(ptConv);
            var planeConv = AddConverter(new PipeConverter <rg.Plane, ppg.Plane>(
                                             (rpl) => {
                return(new ppg.Plane(ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.Origin), ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.XVec),
                                     ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.YVec), ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.Normal)));
            },
                                             (ppl) => {
                return(rg.Plane.CreateByOriginAndBasis(ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.Origin),
                                                       ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.X), ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.Y)));
            }
                                             ));

            var geomConv = new GeometryConverter(ptConv, planeConv);

            AddConverter(geomConv);

            var polylineListConv = AddConverter(new PipeConverter <rg.Line[], ppc.Polyline>(
                                                    (rlg) =>
            {
                List <rg.XYZ> pts = rlg.Select((ln) => ln.GetEndPoint(0)).ToList();
                pts.Add(rlg.LastOrDefault().GetEndPoint(1));
                return(new ppc.Polyline(pts.Select((pt) => ptConv.ToPipe <rg.XYZ, ppg.Vec>(pt)).ToList()));
            },
                                                    (ppl) =>
            {
                List <ppc.Line> lines = ppl.ExplodedLines();
                return(lines.Select((ln) => (rg.Line)geomConv.FromPipe <rg.GeometryObject, IPipeMemberType>(ln)).ToArray());
            }
                                                    ));

            //extrusions
            var extrConv = AddConverter(new PipeConverter <rg.Extrusion, pps.Extrusion>(
                                            (rext) => {
                rg.XYZ norm   = rext.Sketch.SketchPlane.GetPlane().Normal.Normalize();
                var startNorm = norm.Multiply(rext.StartOffset);
                var endNorm   = norm.Normalize().Multiply(rext.EndOffset);
                var depthVec  = norm.Normalize().Multiply(rext.EndOffset - rext.StartOffset);

                List <ppc.Curve> curs = new List <ppc.Curve>();
                foreach (rg.Curve cur in rext.Sketch.Profile)
                {
                    curs.Add(geomConv.CurveConverter.ToPipe <rg.Curve, ppc.Curve>(cur.CreateTransformed(
                                                                                      rg.Transform.CreateTranslation(startNorm))));
                }

                return(new pps.Extrusion(new ppc.PolyCurve(curs), ptConv.ToPipe <rg.XYZ, ppg.Vec>(depthVec),
                                         rext.EndOffset - rext.StartOffset));
            },
                                            (pe) => {
                double tolerance         = 1e-3;
                rg.CurveArrArray profile = new rg.CurveArrArray();
                rg.CurveArray curs       = new rg.CurveArray();
                List <ppc.Curve> pCurs   = pe.ProfileCurve.FlattenedCurveList();
                rg.Plane plane           = null;
                pCurs.ForEach((cur) => {
                    rg.Curve revitCur = geomConv.CurveConverter.FromPipe <rg.Curve, ppc.Curve>(cur);
                    curs.Append(revitCur);
                    rg.Plane newPl = Utils.SketchPlaneUtil.GetPlaneForCurve(revitCur);

                    if (plane == null)
                    {
                        plane = newPl;
                    }
                    else if (Math.Abs(plane.Normal.Normalize().DotProduct(newPl.Normal.Normalize()) - 1) > tolerance)
                    {
                        //the two planes are not aligned so throw exception
                        throw new InvalidOperationException("Cannot create a Revit Extrusion because the profile " +
                                                            "curves are not in the same plane");
                    }
                });
                profile.Append(curs);
                rg.XYZ dir = ptConv.FromPipe <rg.XYZ, ppg.Vec>(pe.Direction);
                if (Math.Abs(plane.Normal.Normalize().DotProduct(dir.Normalize()) - 1) > tolerance)
                {
                    throw new NotImplementedException("Extrusions with direction not perpendicular to curve" +
                                                      "cannot be imported into revit, try converting it to a mesh before sending through the pipe");
                }
                return(PipeForRevit.ActiveDocument.FamilyCreate.NewExtrusion(false, profile,
                                                                             rg.SketchPlane.Create(PipeForRevit.ActiveDocument, plane), pe.Height));
            }
                                            ));
        }
コード例 #38
0
        /// <summary>
        /// Creates one model curve on a plane with an origin at 0,0,0
        /// </summary>
        /// <param name="mc1"></param>
        protected void CreateOneModelCurve(out ModelCurve mc1)
        {
            //create two model curves
            using (_trans = _trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "CreateTwoModelCurves"))
            {
                _trans.Start();

                var p1 = new Plane(XYZ.BasisZ, XYZ.Zero);

                SketchPlane sp1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p1);
                Curve c1 = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0));
                mc1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c1, sp1);

                _trans.Commit();
            }
        }
コード例 #39
-1
ファイル: ModelCurve.cs プロジェクト: klubeley/Dynamo
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            var pts = ((FScheme.Value.List)args[0]).Item.Select(
               x => ((ReferencePoint)((FScheme.Value.Container)x).Item).Position
            ).ToList();

            if (pts.Count <= 1)
            {
                throw new Exception("Not enough reference points to make a curve.");
            }

            var ns = UIDocument.Application.Application.Create.NewNurbSpline(
                    pts, Enumerable.Repeat(1.0, pts.Count).ToList());

            ModelNurbSpline c;

            if (Elements.Any() && dynUtils.TryGetElement(Elements[0], out c))
            {
                ModelCurve.setCurveMethod(c, ns); //c.GeometryCurve = ns;
            }
            else
            {
                Elements.Clear();

                double rawParam = ns.ComputeRawParameter(.5);
                Transform t = ns.ComputeDerivatives(rawParam, false);

                XYZ norm = t.BasisZ;

                if (norm.GetLength() == 0)
                {
                    norm = XYZ.BasisZ;
                }

                Autodesk.Revit.DB.Plane p = new Autodesk.Revit.DB.Plane(norm, t.Origin);
                Autodesk.Revit.DB.SketchPlane sp = this.UIDocument.Document.FamilyCreate.NewSketchPlane(p);
                //sps.Add(sp);

                c = UIDocument.Document.FamilyCreate.NewModelCurve(ns, sp) as ModelNurbSpline;

                Elements.Add(c.Id);
            }

            return FScheme.Value.NewContainer(c);
        }