Beispiel #1
0
        public static Dictionary <string, Element> ByHostAndCurve(Element host, Curve curve)
        {
            AD.Document   currentDBDocument = DocumentManager.Instance.CurrentDBDocument;
            AD.Element    internalElement   = host.InternalElement;
            AD.CurveArray curveArray        = new AD.CurveArray();
            try
            {
                curveArray.Append(ProtoToRevitCurve.ToRevitType(curve, true));
            }
            catch (Exception)
            {
                PolyCurve polyCurve = (PolyCurve)curve;
                Curve[]   array     = polyCurve.Curves();
                for (int i = 0; i < array.Length; i++)
                {
                    Curve crv = array[i];
                    curveArray.Append(ProtoToRevitCurve.ToRevitType(crv, true));
                }
            }
            TransactionManager.Instance.EnsureInTransaction(currentDBDocument);
            AD.Opening opening = currentDBDocument.Create.NewOpening(internalElement, curveArray, true);
            Element    value   = ElementWrapper.ToDSType(opening, false);

            TransactionManager.Instance.TransactionTaskDone();
            return(new Dictionary <string, Element>
            {
                {
                    "Opening",
                    value
                }
            });
        }
Beispiel #2
0
        public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.CurveArray revitCurves,
                                                                           bool performHostUnitConversion = true)
        {
            if (revitCurves == null)
            {
                throw new ArgumentNullException("revitCurves");
            }

            var protoCurves = revitCurves.Cast <Autodesk.Revit.DB.Curve>().Select(x => x.ToProtoType(false));
            var converted   = PolyCurve.ByJoinedCurves(protoCurves.ToArray());

            foreach (var curve in protoCurves)
            {
                curve.Dispose();
            }

            if (converted == null)
            {
                throw new Exception("An unexpected failure occurred when attempting to convert the curve");
            }

            if (performHostUnitConversion)
            {
                UnitConverter.ConvertToDynamoUnits(ref converted);
            }

            return(converted);
        }
        public Result Execute(ExternalCommandData commandData,
                              ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.Creation.Application creApp = uiDoc.Document.Application.Create;
            Autodesk.Revit.Creation.Document    creDoc = uiDoc.Document.Create;
            Autodesk.Revit.DB.CurveArray        curves = creApp.NewCurveArray();
            //create rectangular curve: wall length: 60 , wall width: 40
            Line line1 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 0, 0),
                                        new Autodesk.Revit.DB.XYZ(0, 60, 0), true);
            Line line2 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 60, 0),
                                        new Autodesk.Revit.DB.XYZ(0, 60, 40), true);
            Line line3 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 60, 40),
                                        new Autodesk.Revit.DB.XYZ(0, 0, 40), true);
            Line line4 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 0, 40),
                                        new Autodesk.Revit.DB.XYZ(0, 0, 0), true);

            curves.Append(line1);
            curves.Append(line2);
            curves.Append(line3);
            curves.Append(line4);
            //create wall
            creDoc.NewWall(curves, false);

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Beispiel #4
0
        public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.CurveArray revitCurves)
        {
            if (revitCurves == null)
            {
                throw new ArgumentNullException("revitCurves");
            }

            var protoCurves = revitCurves.Cast <Autodesk.Revit.DB.Curve>().Select(x => x.ToProtoType());

            return(PolyCurve.ByJoinedCurves(protoCurves.ToArray()));
        }
Beispiel #5
0
        /// <summary>
        /// Converts a <see cref="DB.CurveArray"/> into a Rhino <see cref="Curve"/>[]
        /// </summary>
        /// <seealso cref="ToPolyCurves(DB.CurveArrArray)"/>
        public static Curve[] ToCurves(this DB.CurveArray value)
        {
            var count  = value.Size;
            var curves = new Curve[count];

            int index = 0;

            foreach (var curve in value.Cast <DB.Curve>())
            {
                curves[index++] = curve.ToCurve();
            }

            return(curves);
        }
Beispiel #6
0
        /// <summary>
        /// The constructor of RoofsManager class.
        /// </summary>
        /// <param name="commandData">The ExternalCommandData</param>
        public RoofsManager(ExternalCommandData commandData)
        {
            m_commandData     = commandData;
            m_levels          = new List <Level>();
            m_roofTypes       = new List <RoofType>();
            m_referencePlanes = new List <ReferencePlane>();

            m_footPrint = new CurveArray();
            m_profile   = new CurveArray();

            m_footPrintRoofManager = new FootPrintRoofManager(commandData);
            m_extrusionRoofManager = new ExtrusionRoofManager(commandData);
            m_selection            = commandData.Application.ActiveUIDocument.Selection;

            m_transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");

            RoofKind = CreateRoofKind.FootPrintRoof;
            Initialize();
        }
Beispiel #7
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));
            }
                                            ));
        }
Beispiel #8
0
        /// <summary>
        /// The constructor of RoofsManager class.
        /// </summary>
        /// <param name="commandData">The ExternalCommandData</param>
        public RoofsManager(ExternalCommandData commandData)
        {
            m_commandData = commandData;
            m_levels = new List<Level>();
            m_roofTypes = new List<RoofType>();
            m_referencePlanes = new List<ReferencePlane>();

            m_footPrint = new CurveArray();
            m_profile = new CurveArray();

            m_footPrintRoofManager = new FootPrintRoofManager(commandData);
            m_extrusionRoofManager = new ExtrusionRoofManager(commandData);
            m_selection = commandData.Application.ActiveUIDocument.Selection;

            m_transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");

            RoofKind = CreateRoofKind.FootPrintRoof;
            Initialize();
        }