Esempio n. 1
0
        /// <summary>
        /// On the interior 4 curves, set the override flag
        /// and flip the hooks on the top 2 layers to "up"
        /// </summary>
        /// <param name="areaRein"></param>
        private void ChangeAreaReinCurves(AreaReinforcement areaRein)
        {
            //interior 4 curves are listed in the back of the curves,
            //this order is decided when we create it
            IList <ElementId> curveIds = areaRein.GetBoundaryCurveIds();

            for (int i = 4; i < 8; i++)
            {
                AreaReinforcementCurve areaReinCurve =
                    m_doc.GetElement(curveIds[i]) as AreaReinforcementCurve;
                //remove hooks, set the hook the top 2 layers to 'up'
                ParameterUtil.SetParaInt(areaReinCurve,
                                         BuiltInParameter.REBAR_SYSTEM_OVERRIDE, -1);
                ParameterUtil.SetParaInt(areaReinCurve,
                                         BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1,
                                         (int)HookOrientation.Up);
                ParameterUtil.SetParaInt(areaReinCurve,
                                         BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2,
                                         (int)HookOrientation.Up);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// check whether the selected is expected, prepare necessary data
        /// </summary>
        /// <param name="selected">selected elements</param>
        /// <returns>whether the selected AreaReinforcement is expected</returns>
        private bool PreData(ElementSet selected)
        {
            //selected is not only one AreaReinforcement
            if (selected.Size != 1)
            {
                return(false);
            }
            foreach (Object o in selected)
            {
                m_areaRein = o as AreaReinforcement;
                if (null == m_areaRein)
                {
                    return(false);
                }
            }

            //whether the selected AreaReinforcement is rectangular
            CurveArray curves = new CurveArray();

            m_areaReinCurves = new List <AreaReinforcementCurve>();
            IList <ElementId> curveIds = m_areaRein.GetBoundaryCurveIds();

            foreach (ElementId o in curveIds)
            {
                AreaReinforcementCurve areaCurve = m_doc.GetElement(o) as AreaReinforcementCurve;
                if (null == areaCurve)
                {
                    ApplicationException appEx = new ApplicationException
                                                     ("There is unexpected error with selected AreaReinforcement.");
                    throw appEx;
                }
                m_areaReinCurves.Add(areaCurve);
                curves.Append(areaCurve.Curve);
            }
            bool flag = GeomUtil.IsRectangular(curves);

            return(flag);
        }
Esempio n. 3
0
        private void Stream( ArrayList data, AreaReinforcement areaReinf )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( AreaReinforcement ) ) );

              data.Add( new Snoop.Data.Object( "Area reinforcement type", areaReinf.AreaReinforcementType ) );
              // jeremy migrated from Revit 2014 to 2015:
              //data.Add( new Snoop.Data.Enumerable( "Curves", areaReinf.GetCurveElementIds(), areaReinf.Document ) ); // 2014
              data.Add( new Snoop.Data.Enumerable( "Curves", areaReinf.GetBoundaryCurveIds(), areaReinf.Document ) ); // 2015
              data.Add( new Snoop.Data.Xyz( "Direction", areaReinf.Direction ) );

              data.Add( new Snoop.Data.CategorySeparator( "Bar Descriptions" ) );
              System.Collections.Generic.IList<ElementId> rebarIds = areaReinf.GetRebarInSystemIds();
              data.Add( new Snoop.Data.Int( "Number of RebarInSystem", rebarIds.Count ) );
              for( int i = 0; i < rebarIds.Count; i++ )
              {
            data.Add( new Snoop.Data.Object( string.Format( "RebarInSystem [{0:d}]", i ), areaReinf.Document.GetElement( rebarIds[i] ) ) );
              }
        }
Esempio n. 4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            string assemblyPath   = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string assemblyFolder = System.IO.Path.GetDirectoryName(assemblyPath);

            string shortcutsXmlPath = System.IO.Path.Combine(assemblyFolder, "KeyboardShortcuts.xml");
            string idsFilePath      = System.IO.Path.Combine(assemblyFolder, "ids.txt");
            string speedFilePath    = System.IO.Path.Combine(assemblyFolder, "speed.txt");

            string speedString = "5";

            if (System.IO.File.Exists(speedFilePath))
            {
                speedString = System.IO.File.ReadAllText(speedFilePath);
            }
            int speed = int.Parse(speedString);
            DialogWindowRestoreAreaRebar form = new DialogWindowRestoreAreaRebar(shortcutsXmlPath, speed);

            if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(Result.Cancelled);
            }
            speed = form.speed;

            Document         doc    = commandData.Application.ActiveUIDocument.Document;
            Selection        sel    = commandData.Application.ActiveUIDocument.Selection;
            List <ElementId> selids = sel.GetElementIds().ToList();

            List <AreaReinforcement> ars = new List <AreaReinforcement>();

            foreach (ElementId id in selids)
            {
                AreaReinforcement ar = doc.GetElement(id) as AreaReinforcement;
                if (ar != null)
                {
                    ars.Add(ar);
                }
            }

            if (ars.Count == 0)
            {
                message += "Выберите арматуру по площади";
                return(Result.Failed);
            }


            if (System.IO.File.Exists(idsFilePath))
            {
                System.IO.File.Delete(idsFilePath);
            }

            using (System.IO.StreamWriter idsFileWriter = System.IO.File.CreateText(idsFilePath))
            {
                foreach (AreaReinforcement ar in ars)
                {
                    string           line     = ar.Id.IntegerValue.ToString() + ":";
                    List <ElementId> curveIds = ar.GetBoundaryCurveIds().ToList();
                    foreach (ElementId id in curveIds)
                    {
                        line = line + id.IntegerValue.ToString() + ",";
                    }
                    idsFileWriter.WriteLine(line);
                }
                idsFileWriter.Close();
            }

            using (System.IO.StreamWriter speedFileWriter = System.IO.File.CreateText(speedFilePath))
            {
                speedFileWriter.Write(speed.ToString());
                speedFileWriter.Close();
            }


            string scriptPath = System.IO.Path.Combine(assemblyFolder, "RestoreAreaRebar.exe");

            //нужно сбросить выделение, если есть выбранные элементы
            commandData.Application.ActiveUIDocument.Selection.SetElementIds(new List <ElementId>());

            //запускаю супер-програмку
            System.Diagnostics.Process.Start(scriptPath);



            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("AreeRebarMark"));
            Debug.WriteLine("Start area rebar mark");
            double offset = 0; //мм

            //собираю все элементы армирования по площади и траектории
            Document doc = commandData.Application.ActiveUIDocument.Document;
            FilteredElementCollector areas = new FilteredElementCollector(doc)
                                             .OfClass(typeof(Autodesk.Revit.DB.Structure.AreaReinforcement))
                                             .WhereElementIsNotElementType();
            FilteredElementCollector paths = new FilteredElementCollector(doc)
                                             .OfClass(typeof(Autodesk.Revit.DB.Structure.PathReinforcement))
                                             .WhereElementIsNotElementType();
            List <Element> col   = areas.Concat(paths).ToList();
            int            count = 0;

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Area rebar mark");
                //и Path, и Area попытаюсь обрабатываю в одном цикле, чтобы компактнее было
                foreach (Element rebarAreaPath in col)
                {
                    //благодаря hashset можно собрать только уникальный марки стержней
                    HashSet <string> marks           = new HashSet <string>();
                    string           rebarSystemMark = "";

                    List <ElementId> rebarIds = null;
                    List <ElementId> curveIds = null;

                    double maxZ = 0;
                    double minZ = 0;

                    if (rebarAreaPath is AreaReinforcement)
                    {
                        AreaReinforcement ar = rebarAreaPath as AreaReinforcement;
                        rebarIds = ar.GetRebarInSystemIds().ToList();
                        curveIds = ar.GetBoundaryCurveIds().ToList();

                        //определяю нижнюю и верзнюю точку зоны
                        List <double> zs = new List <double>();
                        foreach (ElementId curveId in curveIds)
                        {
                            AreaReinforcementCurve curve =
                                doc.GetElement(curveId) as AreaReinforcementCurve;

                            XYZ    start = curve.Curve.GetEndPoint(0);
                            double z1    = start.Z;
                            zs.Add(z1);

                            XYZ    end = curve.Curve.GetEndPoint(1);
                            double z2  = end.Z;
                            zs.Add(z2);
                        }

                        maxZ  = zs.Max();
                        maxZ += offset / 304.8;
                        minZ  = zs.Min();
                        minZ += offset / 304.8;
                    }

                    if (rebarAreaPath is PathReinforcement)
                    {
                        PathReinforcement pr = rebarAreaPath as PathReinforcement;
                        rebarIds = pr.GetRebarInSystemIds().ToList();

                        maxZ = pr.get_BoundingBox(doc.ActiveView).Max.Z;
                        minZ = pr.get_BoundingBox(doc.ActiveView).Min.Z;
                    }

                    //получаю общие параметры, в которые буду записывать отметку верха и низа, они должны быть заранее добавлены
                    Parameter topelev = rebarAreaPath.LookupParameter("АрмПлощ.ОтмВерха");
                    Parameter botelev = rebarAreaPath.LookupParameter("АрмПлощ.ОтмНиза");

                    if (topelev == null)
                    {
                        topelev = rebarAreaPath.LookupParameter("Рзм.ОтмВерха");
                    }
                    if (botelev == null)
                    {
                        botelev = rebarAreaPath.LookupParameter("Рзм.ОтмНиза");
                    }

                    if (topelev != null && botelev != null)
                    {
                        topelev.Set(maxZ);
                        botelev.Set(minZ);
                    }

                    //еще хочу записать в зону длину самого длинного арматурного стержня в ней
                    double length = 0;

                    //обрабатываю арматурные стержни в составе зоны
                    foreach (ElementId rebarId in rebarIds)
                    {
                        Element rebar     = doc.GetElement(rebarId);
                        string  rebarMark = rebar.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString();
                        marks.Add(rebarMark);
                        double tempLength = rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_LENGTH).AsDouble();
                        if (tempLength > length)
                        {
                            length = tempLength;
                        }
                    }

                    //сортирую марки и записываю через запятую
                    List <string> marksList = marks.ToList();
                    marksList.Sort();
                    for (int i = 0; i < marks.Count; i++)
                    {
                        rebarSystemMark += marksList[i];
                        if (i < marks.Count - 1)
                        {
                            rebarSystemMark += ", ";
                        }
                    }
                    rebarAreaPath.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).Set(rebarSystemMark);

                    //записываю длину арматуры а зону
                    Parameter lengthParam = rebarAreaPath.LookupParameter("Рзм.Длина");
                    if (lengthParam != null)
                    {
                        lengthParam.Set(length);
                    }

                    count++;
                }
                t.Commit();
            }

            BalloonTip.Show("Успешно!", "Обработано зон: " + count.ToString());
            Debug.WriteLine("Success, elements: " + count.ToString());

            return(Result.Succeeded);
        }