Exemplo n.º 1
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var pts = ((Value.List)args[0]).Item.Select(
               e => ((ReferencePoint)((Value.Container)e).Item).Position
            ).ToList();

            foreach (ElementId el in this.Elements)
            {
                Element e;
                if (dynUtils.TryGetElement(el, out e))
                {
                    this.UIDocument.Document.Delete(el);
                }
            }
            if (pts.Count <= 1)
            {
                throw new Exception("Not enough reference points to make a curve.");
            }

            //make a curve
            NurbSpline ns = this.UIDocument.Application.Application.Create.NewNurbSpline(
               pts, Enumerable.Repeat(1.0, pts.Count).ToList()
            );

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

            XYZ norm = t.BasisZ;

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

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

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

            this.Elements.Add(c.Id);

            return Value.NewContainer(c);
        }
Exemplo n.º 2
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            Point origin = (Point)((Value.Container)args[0]).Item;
            Vector normal = (Vector)((Value.Container)args[1]).Item;

            _plane = Plane.by_origin_normal(origin, normal);

            return Value.NewContainer(_plane);
        }
Exemplo n.º 3
0
        public void SelectReferenceASTGeneration()
        {
            Form extrude;

            using (var trans = new Transaction(DocumentManager.Instance.CurrentDBDocument, "Create an extrusion Form"))
            {
                trans.Start();

                FailureHandlingOptions fails = trans.GetFailureHandlingOptions();
                fails.SetClearAfterRollback(true);
                trans.SetFailureHandlingOptions(fails);

                var p = new Plane(new XYZ(0, 0, 1), new XYZ());
                var arc = Arc.Create(p, 2, 0, System.Math.PI);
                var sp = SketchPlane.Create(DocumentManager.Instance.CurrentDBDocument, p);
                var mc = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewModelCurve(arc, sp);

                var profiles = new ReferenceArray();
                profiles.Append(mc.GeometryCurve.Reference);
                extrude = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewExtrusionForm(false, profiles, new XYZ(0,0,1));
                trans.Commit();
            }

            var geom = extrude.get_Geometry(new Options()
            {
                ComputeReferences = true,
                DetailLevel = ViewDetailLevel.Medium,
                IncludeNonVisibleObjects = true
            });

            var solid = geom.FirstOrDefault(x => x is Solid) as Solid;
            var face = solid.Faces.get_Item(0);
            Assert.Greater(solid.Faces.Size, 0);

            var sel = new DSFaceSelection() { SelectedElement = face.Reference };

            var buildOutput = sel.BuildOutputAst(new List<AssociativeNode>());

            var funCall = (FunctionCallNode)((IdentifierListNode)((BinaryExpressionNode)buildOutput.First()).RightNode).RightNode;

            Assert.IsInstanceOf<IdentifierNode>(funCall.Function);
            Assert.AreEqual(1, funCall.FormalArguments.Count);
            Assert.IsInstanceOf<StringNode>(funCall.FormalArguments[0]);

            var stableRef = face.Reference.ConvertToStableRepresentation(DocumentManager.Instance.CurrentDBDocument);
            Assert.AreEqual(stableRef, ((StringNode)funCall.FormalArguments[0]).value);
        }
Exemplo n.º 4
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var pts = ((Value.List)args[0]).Item.Select(
               e => ((ReferencePoint)((Value.Container)e).Item).Position
            ).ToList();

            foreach (ElementId el in this.Elements)
            {
                Element e;
                if (dynUtils.TryGetElement(el, out e))
                {
                    DeleteElement(el);
                    ns = null;
                    c = null;
                }

            }

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

            if (ns == null)
            {
                //make a curve
                ns = this.UIDocument.Application.Application.Create.NewNurbSpline(
                    pts, Enumerable.Repeat(1.0, pts.Count).ToList());
            }
            else
            {
                DoubleArray arr = new DoubleArray();

                var weights = Enumerable.Repeat(1.0, pts.Count).ToList();
                foreach (double weight in weights)
                {
                    double d = weight;
                    arr.Append(ref d);
                }

                //update the existing curve
                ns.SetControlPointsAndWeights(pts, arr);
            }

            if (c == null)
            {
                double rawParam = ns.ComputeRawParameter(.5);
                Transform t = ns.ComputeDerivatives(rawParam, false);

                XYZ norm = t.BasisZ;

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

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

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

                this.Elements.Add(c.Id);
            }
            else
            {
                c.GeometryCurve = ns;
            }

            return Value.NewContainer(c);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates two model curves separated in Z.
        /// </summary>
        /// <param name="mc1"></param>
        /// <param name="mc2"></param>
        private void CreateTwoModelCurves(out ModelCurve mc1, out ModelCurve mc2)
        {
            //create two model curves
            using (_trans = _trans = new Transaction(dynRevitSettings.Doc.Document, "CreateTwoModelCurves"))
            {
                _trans.Start();

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

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

                _trans.Commit();
            }
        }
Exemplo n.º 6
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var pts = ((Value.List)args[0]).Item.Select(
               x => ((ReferencePoint)((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;
            Element e;

            if (Elements.Any() && dynUtils.TryGetElement(Elements[0],typeof(ModelCurve), out e))
            {
                c = e as ModelNurbSpline;

                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;
                }

                Plane p = new Plane(norm, t.Origin);
                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 Value.NewContainer(c);
        }