Beispiel #1
0
        public static DB.CurveArrArray ToCurveArrayArray(this IList <Curve> value)
        {
            var curveArrayArray = new DB.CurveArrArray();

            foreach (var curve in value)
            {
                curveArrayArray.Append(curve.ToCurveArray());
            }

            return(curveArrayArray);
        }
Beispiel #2
0
        /// <summary>
        /// Converts a <see cref="DB.CurveArrArray"/> into a <see cref="PolyCurve"/>[]
        /// </summary>
        /// <seealso cref="ToCurves(DB.CurveArrArray)"/>
        public static PolyCurve[] ToPolyCurves(this DB.CurveArrArray value)
        {
            var count = value.Size;
            var list  = new PolyCurve[count];

            int index = 0;

            foreach (var curveArray in value.Cast <DB.CurveArray>())
            {
                var polycurve = new PolyCurve();

                foreach (var curve in curveArray.Cast <DB.Curve>())
                {
                    polycurve.AppendSegment(curve.ToCurve());
                }

                list[index++] = polycurve;
            }

            return(list);
        }
Beispiel #3
0
        public RevitPipeConverter()
        {
            var ptConv = new PointConverter();

            AddConverter(ptConv);
            var planeConv = AddConverter(new PipeConverter <rg.Plane, ppg.Plane>(
                                             (rpl) => {
                return(new ppg.Plane(ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.Origin), ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.XVec),
                                     ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.YVec), ptConv.ToPipe <rg.XYZ, ppg.Vec>(rpl.Normal)));
            },
                                             (ppl) => {
                return(rg.Plane.CreateByOriginAndBasis(ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.Origin),
                                                       ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.X), ptConv.FromPipe <rg.XYZ, ppg.Vec>(ppl.Y)));
            }
                                             ));

            var geomConv = new GeometryConverter(ptConv, planeConv);

            AddConverter(geomConv);

            var polylineListConv = AddConverter(new PipeConverter <rg.Line[], ppc.Polyline>(
                                                    (rlg) =>
            {
                List <rg.XYZ> pts = rlg.Select((ln) => ln.GetEndPoint(0)).ToList();
                pts.Add(rlg.LastOrDefault().GetEndPoint(1));
                return(new ppc.Polyline(pts.Select((pt) => ptConv.ToPipe <rg.XYZ, ppg.Vec>(pt)).ToList()));
            },
                                                    (ppl) =>
            {
                List <ppc.Line> lines = ppl.ExplodedLines();
                return(lines.Select((ln) => (rg.Line)geomConv.FromPipe <rg.GeometryObject, IPipeMemberType>(ln)).ToArray());
            }
                                                    ));

            //extrusions
            var extrConv = AddConverter(new PipeConverter <rg.Extrusion, pps.Extrusion>(
                                            (rext) => {
                rg.XYZ norm   = rext.Sketch.SketchPlane.GetPlane().Normal.Normalize();
                var startNorm = norm.Multiply(rext.StartOffset);
                var endNorm   = norm.Normalize().Multiply(rext.EndOffset);
                var depthVec  = norm.Normalize().Multiply(rext.EndOffset - rext.StartOffset);

                List <ppc.Curve> curs = new List <ppc.Curve>();
                foreach (rg.Curve cur in rext.Sketch.Profile)
                {
                    curs.Add(geomConv.CurveConverter.ToPipe <rg.Curve, ppc.Curve>(cur.CreateTransformed(
                                                                                      rg.Transform.CreateTranslation(startNorm))));
                }

                return(new pps.Extrusion(new ppc.PolyCurve(curs), ptConv.ToPipe <rg.XYZ, ppg.Vec>(depthVec),
                                         rext.EndOffset - rext.StartOffset));
            },
                                            (pe) => {
                double tolerance         = 1e-3;
                rg.CurveArrArray profile = new rg.CurveArrArray();
                rg.CurveArray curs       = new rg.CurveArray();
                List <ppc.Curve> pCurs   = pe.ProfileCurve.FlattenedCurveList();
                rg.Plane plane           = null;
                pCurs.ForEach((cur) => {
                    rg.Curve revitCur = geomConv.CurveConverter.FromPipe <rg.Curve, ppc.Curve>(cur);
                    curs.Append(revitCur);
                    rg.Plane newPl = Utils.SketchPlaneUtil.GetPlaneForCurve(revitCur);

                    if (plane == null)
                    {
                        plane = newPl;
                    }
                    else if (Math.Abs(plane.Normal.Normalize().DotProduct(newPl.Normal.Normalize()) - 1) > tolerance)
                    {
                        //the two planes are not aligned so throw exception
                        throw new InvalidOperationException("Cannot create a Revit Extrusion because the profile " +
                                                            "curves are not in the same plane");
                    }
                });
                profile.Append(curs);
                rg.XYZ dir = ptConv.FromPipe <rg.XYZ, ppg.Vec>(pe.Direction);
                if (Math.Abs(plane.Normal.Normalize().DotProduct(dir.Normalize()) - 1) > tolerance)
                {
                    throw new NotImplementedException("Extrusions with direction not perpendicular to curve" +
                                                      "cannot be imported into revit, try converting it to a mesh before sending through the pipe");
                }
                return(PipeForRevit.ActiveDocument.FamilyCreate.NewExtrusion(false, profile,
                                                                             rg.SketchPlane.Create(PipeForRevit.ActiveDocument, plane), pe.Height));
            }
                                            ));
        }