예제 #1
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);
            }
        }
예제 #2
0
        private static ElementId createModelCurve(Document document, Curve curve, SketchPlane sp = null)
        {
            Line          line     = curve as Line;
            Arc           arc      = curve as Arc;
            Ellipse       ellipse  = curve as Ellipse;
            HermiteSpline spline   = curve as HermiteSpline;
            NurbSpline    nbSpline = curve as NurbSpline;

            if (line != null && null == sp)
            {
                XYZ normal = getVertVec(line.Direction).Normalize();
                XYZ origin = line.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }
            else if (arc != null && null == sp)
            {
                XYZ normal = arc.Normal;
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, arc.Center));
            }
            else if (ellipse != null && null == sp)
            {
                XYZ normal = ellipse.Normal;
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, ellipse.Center));
            }
            else if (spline != null && null == sp)
            {
                Transform tran   = spline.ComputeDerivatives(0, false);
                XYZ       normal = getVertVec(tran.BasisX).Normalize();
                XYZ       origin = spline.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }
            else if (nbSpline != null && null == sp)
            {
                Transform tran   = nbSpline.ComputeDerivatives(0, false);
                XYZ       normal = getVertVec(tran.BasisX).Normalize();
                XYZ       origin = nbSpline.GetEndPoint(0);
                sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin));
            }

            if (sp == null)
            {
                throw new ArgumentException("Not valid sketchplane to create curve:" + curve.GetType().Name);
            }
            //
            // create model line with curve and the specified sketch plane.
            ModelCurve mCurve = document.Create.NewModelCurve(curve, sp);

            return((null != mCurve) ? mCurve.Id : ElementId.InvalidElementId);
        }