コード例 #1
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));
        }
コード例 #2
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));
        }
コード例 #3
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())));
        }