Esempio n. 1
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));
        }
Esempio n. 2
0
        bool resetPlaneofSketchPlaneElement(SketchPlane sp, Plane p)
        {
            XYZ newOrigin = p.Origin;
            XYZ newNorm = p.Normal;
            var oldP = sp.Plane;
            XYZ oldOrigin = oldP.Origin;
            XYZ oldNorm = oldP.Normal;

            Transform trfP = null;
            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;
        }