Beispiel #1
0
        private Curve moveModelLine(ExternalCommandData commandData)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;                         //取得文档

            Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application; //取得应用程序
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;                                   //取得当前活动文档

            Curve curve;

            Selection sel       = uiDoc.Selection;
            Reference ref1      = sel.PickObject(ObjectType.Element, "选择一条模型线作为平曲线/纵曲线");
            Element   elem      = revitDoc.GetElement(ref1);
            ModelLine modelLine = elem as ModelLine;

            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve = modelLine.GeometryCurve;
            }


            //移动平曲线
            XYZ moveVec = new XYZ(curve.Length, curve.Length, curve.Length);

            ElementTransformUtils.MoveElement(uiDoc.Document, elem.Id, moveVec);
            return(curve);
        }
Beispiel #2
0
        private double SelectPoint(ExternalCommandData commandData)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Selection sel        = uiDoc.Selection;
            Reference ref1       = sel.PickObject(ObjectType.Element, "选择一条模型线");
            Element   elem       = revitDoc.GetElement(ref1);
            ModelLine modelLine1 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve1;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine1 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve1 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve1 = modelLine1.GeometryCurve;
            }


            Reference ref2 = sel.PickObject(ObjectType.Element, "选择一条模型线");

            elem = revitDoc.GetElement(ref2);
            ModelLine modelLine2 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve2;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine2 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve2 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve2 = modelLine2.GeometryCurve;
            }


            //删除第二条选中的线
            uiDoc.Document.Delete(elem.Id);
            //求交点
            curve1.Intersect(curve2, out IntersectionResultArray intersectionResultArray);
            XYZ pointIntersect = intersectionResultArray.get_Item(0).XYZPoint;

            //交点和线都转化为dynamo的点和线
            DG.Point dgP   = pointIntersect.ToPoint(false);
            DG.Curve dgC   = curve1.ToProtoType(false);
            double   ratio = dgC.ParameterAtPoint(dgP);

            return(ratio);
        }
Beispiel #3
0
        public void Process(DataTreeBranch b, DataTreeBranch currentBranch)
        {
            List <XYZ>    ptArr   = new List <XYZ>();
            List <double> weights = new List <double>();

            foreach (object o in b.Leaves)
            {
                ReferencePoint pt = o as ReferencePoint;
                ptArr.Add(pt.Position);
                weights.Add(1);
            }

            //only make a curve if
            //there's enough points
            if (ptArr.Count > 1)
            {
                //make a curve
                NurbSpline ns       = dynElementSettings.SharedInstance.Doc.Application.Application.Create.NewNurbSpline(ptArr, weights);
                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 = dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewSketchPlane(p);
                sps.Add(sp);

                ModelNurbSpline c = (ModelNurbSpline)dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewModelCurve(ns, sp);

                //add the element to the collection
                //so it can be deleted later
                Elements.Append(c);

                //create a leaf node on the local branch
                currentBranch.Leaves.Add(c);
            }

            foreach (DataTreeBranch b1 in b.Branches)
            {
                //every time you read a branch
                //create a branch
                DataTreeBranch newBranch = new DataTreeBranch();
                this.Tree.Trunk.Branches.Add(newBranch);

                Process(b1, newBranch);
            }
        }
        private void Stream( ArrayList data, ModelNurbSpline modelCrv )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( ModelNurbSpline ) ) );

              // no data at this level
        }
Beispiel #5
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);
        }