Esempio n. 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
                }
            });
        }
        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);
        }
Esempio n. 3
0
        /// <summary>
        /// Select elements in Revit to obtain the footprint roof lines.
        /// </summary>
        /// <returns>A curve array to hold the footprint roof lines.</returns>
        public CurveArray SelectFootPrint()
        {
            m_footPrint.Clear();
            while (true)
            {
                ElementSet es = new ElementSet();
                foreach (ElementId elementId in m_selection.GetElementIds())
                {
                    es.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
                }
                es.Clear();
                IList <Element> selectResult;
                try
                {
                    selectResult = m_selection.PickElementsByRectangle();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    break;
                }

                if (selectResult.Count != 0)
                {
                    foreach (Autodesk.Revit.DB.Element element in selectResult)
                    {
                        Wall wall = element as Wall;
                        if (wall != null)
                        {
                            LocationCurve wallCurve = wall.Location as LocationCurve;
                            m_footPrint.Append(wallCurve.Curve);
                            continue;
                        }

                        ModelCurve modelCurve = element as ModelCurve;
                        if (modelCurve != null)
                        {
                            m_footPrint.Append(modelCurve.GeometryCurve);
                        }
                    }
                    break;
                }
                else
                {
                    TaskDialogResult result = TaskDialog.Show("Warning", "You should select a curve loop, or a wall loop, or loops combination \r\nof walls and curves to create a footprint roof.", TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);
                    if (result == TaskDialogResult.Cancel)
                    {
                        break;
                    }
                }
            }

            return(m_footPrint);
        }
Esempio n. 4
0
        /// <summary>
        /// Select elements in Revit to obtain the footprint roof lines.
        /// </summary>
        /// <returns>A curve array to hold the footprint roof lines.</returns>
        public CurveArray SelectFootPrint()
        {
            m_footPrint.Clear();
            while (true)
            {
                m_selection.Elements.Clear();
                IList <Element> selectResult;
                try
                {
                    selectResult = m_selection.PickElementsByRectangle();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    break;
                }

                if (selectResult.Count != 0)
                {
                    foreach (Autodesk.Revit.DB.Element element in selectResult)
                    {
                        Wall wall = element as Wall;
                        if (wall != null)
                        {
                            LocationCurve wallCurve = wall.Location as LocationCurve;
                            m_footPrint.Append(wallCurve.Curve);
                            continue;
                        }

                        ModelCurve modelCurve = element as ModelCurve;
                        if (modelCurve != null)
                        {
                            m_footPrint.Append(modelCurve.GeometryCurve);
                        }
                    }
                    break;
                }
                else
                {
                    DialogResult result = MessageBox.Show("You should select a curve loop, or a wall loop, or loops combination \r\nof walls and curves to create a footprint roof.", "Warning",
                                                          MessageBoxButtons.OKCancel);
                    if (result == DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }

            return(m_footPrint);
        }
Esempio n. 5
0
 /// <summary>
 /// Select elements in Revit to obtain the extrusion profile lines.
 /// </summary>
 /// <returns>A curve array to hold the extrusion profile lines.</returns>
 public CurveArray SelectProfile()
 {
     m_profile.Clear();
     while (true)
     {
         m_selection.Elements.Clear();
         IList <Element> selectResult;
         try
         {
             selectResult = m_selection.PickElementsByRectangle();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             break;
         }
         if (selectResult.Count != 0)
         {
             foreach (Autodesk.Revit.DB.Element element in selectResult)
             {
                 ModelCurve modelCurve = element as ModelCurve;
                 if (modelCurve != null)
                 {
                     m_profile.Append(modelCurve.GeometryCurve);
                     continue;
                 }
             }
             break;
         }
         else
         {
             DialogResult result = MessageBox.Show("You should select a  connected lines or arcs, \r\nnot closed in a loop to create extrusion roof.", "Warning",
                                                   MessageBoxButtons.OKCancel);
             if (result == DialogResult.Cancel)
             {
                 break;
             }
         }
     }
     return(m_profile);
 }
Esempio n. 6
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));
            }
                                            ));
        }