Ejemplo n.º 1
0
        public static (string, string, string) chtoto(Cube cube)
        {
            string a = "";
            string b = "-";
            string c = "";

            switch (cube.mType)
            {
            case myTypes.matVol:
                a = "-";
                c = cube.TotalVolume.ToString("F2") + " м³";
                break;

            case myTypes.matArea:
                a = "-";
                c = cube.TotalArea.ToString("F1") + " м²";
                break;

            case myTypes.kmLen:
                break;

            case myTypes.kmNum:
                break;

            case myTypes.armLen:
                a = "-";
                b = cube.Massa.ToString("F3");
                c = cube.TotalMassa.ToString("F2") + " кг";
                break;

            case myTypes.armNum:
                a = cube.Quantity.ToString();
                b = cube.Massa.ToString("F3");
                c = cube.TotalMassa.ToString("F2") + " кг";

                break;

            case myTypes.allNum:
                a = cube.Quantity.ToString();
                b = "-";
                c = "шт";
                break;

            case myTypes.commonLength:
                a = cube.TotalLength.ToString("F1");
                c = "м.п.";
                break;

            case myTypes.plastini:
                a = cube.Quantity.ToString();
                b = cube.Massa.ToString("F2");
                c = cube.TotalMassa.ToString("F2") + " кг";
                break;

            case myTypes.totalArea:
                a = "-";
                b = cube.Massa.ToString("F2");
                c = cube.TotalMassa.ToString("F2") + " кг";
                break;

            default:
                a = cube.Quantity.ToString();
                b = "-";
                c = "шт";
                break;
            }
            return(a, b, c);
        }
Ejemplo n.º 2
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;


            PhaseArray xcom      = doc.Phases;
            Phase      lastPhase = xcom.get_Item(xcom.Size - 1);
            ElementId  idPhase   = lastPhase.Id;


            FilterableValueProvider    valueProvider = new ParameterValueProvider(new ElementId(BuiltInParameter.PHASE_CREATED));
            FilterNumericRuleEvaluator evaluator     = new FilterNumericEquals();
            ElementId ruleValue = idPhase;
            ElementParameterFilter stageFilter = new ElementParameterFilter(new FilterElementIdRule(valueProvider, evaluator, ruleValue));

            List <List <Element> > collectFromModel = new List <List <Element> >();

            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Where(x => ((FamilyInstance)x).StructuralType.ToString() != "NonStructural")
                                 .Cast <Element>()
                                 .ToList());
            //collectFromModel.Add(karkas);

            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());

            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Rebar))
                                 .WherePasses(stageFilter)
                                 .ToElements().ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(RebarInSystem))
                                 .WherePasses(stageFilter)
                                 .ToElements().ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Railing))
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .ToElements()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(HostedSweep))
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .ToElements()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionPlates)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionAnchors)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .Where(x => x.Name != "cube")
                                 .ToList());


            List <Element> floors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors)
                                    .WhereElementIsNotElementType()
                                    .WherePasses(stageFilter)
                                    .Cast <Element>()
                                    .ToList();
            List <Element> walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
                                   .WhereElementIsNotElementType()
                                   .WherePasses(stageFilter)
                                   .Cast <Element>()
                                   .ToList();
            List <Element> fundament = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFoundation)
                                       .WhereElementIsNotElementType()
                                       .WherePasses(stageFilter)
                                       .Cast <Element>()
                                       .ToList();
            List <Element> lestnici = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Stairs)
                                      .WhereElementIsNotElementType()
                                      .WherePasses(stageFilter)
                                      .Cast <Element>()
                                      .ToList();



            //genModel = genModel.Where(x => x.Name != "cube").ToList();
            List <Cube> allCube = new List <Cube>();

            foreach (List <Element> a in collectFromModel)
            {
                foreach (Element e in a)
                {
                    Cube abc = new Cube(e);
                    if (abc.out_Name == null | abc.out_Name == "")
                    {
                        abc.out_Name = "Исключение: " + abc.typeName;
                    }
                    allCube.Add(abc);
                }
            }

            foreach (Element f in floors)
            {
                foreach (ElementId m in f.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }

            foreach (Element w in walls)
            {
                foreach (ElementId m in w.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), w);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }

            foreach (Element f in fundament)
            {
                foreach (ElementId m in f.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }
            foreach (Element f in lestnici)
            {
                foreach (ElementId m in f.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }



            List <List <Cube> > groupingCube = new List <List <Cube> >();

            //List<string> groupNum=allCube.Select(x => x.Group).Distinct().ToList();

            foreach (string eqGroup in allCube.Select(x => x.out_Group).Distinct())
            {
                List <Cube> similarGroup = new List <Cube>();
                foreach (Cube c in allCube)
                {
                    if (c.out_Group == eqGroup)
                    {
                        similarGroup.Add(c);
                    }
                }
                groupingCube.Add(similarGroup);
            }

            List <Cube> outCube = new List <Cube>();

            foreach (List <Cube> item in groupingCube)
            {
                int a = 1;
                //int addpos = 1;

                foreach (string eqName in item.Select(x => x.out_Name).Distinct())
                {
                    List <Cube> b = new List <Cube>();

                    foreach (Cube i in item)
                    {
                        if (i.out_Name == eqName)
                        {
                            b.Add(i);
                        }
                    }
                    (Cube addCube, int addpos) = Meta.forgeCube(b, a);
                    if (addCube.out_Name.Contains("Исключение"))
                    {
                        a--;
                    }
                    a += addpos;
                    outCube.Add(addCube);
                }
            }
            List <ElementId>   argh   = uidoc.Selection.GetElementIds().ToList();
            List <wtf.Product> TabSel = new List <wtf.Product>();

            foreach (var item in argh)
            {
                TabSel.Add(new wtf.TABSCreator().Create(doc.GetElement(item)));
            }
            foreach (var item in TabSel)
            {
                foreach (Cube c in outCube)
                {
                    if (item.grouping == c.out_Group)
                    {
                        item.linkedElt.Add(c);
                    }
                }
            }
            using (Transaction tr = new Transaction(doc, "SetCurrentSpec"))
            {
                tr.Start();
                foreach (wtf.Product i in TabSel)
                {
                    if (i.linkedElt.Count < 2)
                    {
                        continue;
                    }
                }
                int rowCount = 0;
                foreach (wtf.Product e in TabSel)
                {
                    e.refElt.refElement.setP("Лист", doc.GetElement(e.refElt.refElement.OwnerViewId).getP("Номер листа"));
                    e.refElt.refElement.setP("Строк", e.linkedElt.Count);
                    e.linkedElt = e.linkedElt.OrderBy(x => x.Prior).ToList();
                    foreach (Cube cube in e.linkedElt)
                    {
                        if (cube.out_Name.Contains("Исключение"))
                        {
                            continue;
                        }
                        rowCount++;
                        e.refElt.refElement.setP($"Поз__{rowCount}", cube.out_Pos);
                        e.refElt.refElement.setP($"Обозначение__{rowCount}", cube.out_Gost);
                        e.refElt.refElement.setP($"Наименование__{rowCount}", cube.out_Name);
                        e.refElt.refElement.setP($"К__{rowCount}", cube.out_Kol_vo);
                        e.refElt.refElement.setP($"М__{rowCount}", cube.out_Mass);
                        e.refElt.refElement.setP($"Прим__{rowCount}", cube.out_Other);
                    }
                    rowCount = 0;
                }
                tr.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 3
0
        public static (Cube, int) forgeCube(List <Cube> IN, int position)
        {
            int addpos = 1;

            if (IN[0].DontSetPos)
            {
                addpos = 0;
            }
            string grName = IN[0].out_Group == null ?"Без группы": IN[0].out_Group;
            Cube   nova   = new Cube(grName, IN[0].out_Name);

            foreach (Cube c in IN)
            {
                try
                {
                    //nova.
                    nova.posElements.Add(c.refElement);
                }
                catch
                {
                }
            }
            nova.textUP = IN[0].textUP;
            nova.mType  = IN[0].mType;
            nova.Length = IN[0].Length;
            //nova
            //nova.Quantity=IN.Where(x=>x.Quantity)
            foreach (Cube i in IN)
            {
                if (i.Quantity <= 1)
                {
                    nova.Quantity += 1;
                }
                else
                {
                    nova.Quantity += i.Quantity;
                }
            }
            if (IN[0].mType == myTypes.matArea | IN[0].mType == myTypes.matVol)
            {
                addpos       = 0;
                nova.out_Pos = "";
                nova.Prior   = 1000;
            }
            else
            {
                nova.out_Pos = position.ToString();
                nova.Prior   = 10;
            }
            if (IN[0].mType == myTypes.totalArea)
            {
                addpos       = 0;
                nova.out_Pos = IN[0].typeName;
                nova.Prior   = 100;
            }

            //nova.Quantity = IN.Count;
            nova.Massa = IN[0].Massa;


            foreach (Cube b in IN)
            {
                nova.TotalLength += b.Length;
                nova.TotalMassa  += b.Length > 0?b.Length * b.Massa: b.Massa;
                nova.TotalArea   += b.Area;
                nova.TotalVolume += b.Volume;
            }
            switch (nova.mType)
            {
            case myTypes.matVol:
                break;

            case myTypes.matArea:
                break;

            case myTypes.kmLen:
                break;

            case myTypes.kmNum:
                break;

            case myTypes.armLen:
                nova.out_Name = nova.out_Name + " l=" + nova.TotalLength.ToString("F1") + " м.п.";
                break;

            case myTypes.armNum:
                nova.TotalMassa = nova.Massa * nova.Quantity;
                nova.out_Name   = nova.out_Name + " L=" + (Math.Round(nova.Length / 10) * 10).ToString("F0") + " мм";
                break;

            case myTypes.allNum:
                break;

            case myTypes.plastini:
                break;

            case myTypes.totalArea:
                nova.out_Name   = nova.out_Name + " S=" + (nova.TotalArea * FT * FT).ToString("F2") + " м²";
                nova.TotalMassa = nova.Massa * nova.TotalArea * FT * FT;
                break;

            case myTypes.commonLength:
                break;

            default:
                break;
            }

            nova.out_Gost = IN[0].out_Gost;
            //nova.Prior = IN[0].Prior;
            (nova.out_Kol_vo, nova.out_Mass, nova.out_Other) = Meta.chtoto(nova);
            return(nova, addpos);
        }
Ejemplo n.º 4
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            //Application app = uiapp.Application;
            Document doc = uidoc.Document;

            PhaseArray xcom      = doc.Phases;
            Phase      lastPhase = xcom.get_Item(xcom.Size - 1);
            ElementId  idPhase   = lastPhase.Id;

            //ICollection<ElementId> selectedElementIds = uidoc.Selection.GetElementIds();
            //List<Element> selElem = selectedElementIds.Select(x => doc.GetElement(x)).ToList();
            //Element foundtype = doc.GetElement(selElem[0].GetTypeId());
            //List<string> parlist = new List<string>();
            //foreach (Parameter item in foundtype.Parameters)
            //{
            //    parlist.Add(item.Definition.Name);
            //}
            //int parvalue = foundtype.LookupParameter("шт/м/м2/м3").AsInteger();
            FilterableValueProvider valueProvider = new ParameterValueProvider(new ElementId(BuiltInParameter.PHASE_CREATED));

            FilterNumericRuleEvaluator evaluator = new FilterNumericEquals();
            ElementId ruleValue = idPhase;
            ElementParameterFilter stageFilter = new ElementParameterFilter(new FilterElementIdRule(valueProvider, evaluator, ruleValue));

            List <List <Element> > collectFromModel = new List <List <Element> >();

            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Where(x => ((FamilyInstance)x).StructuralType.ToString() != "NonStructural")
                                 .Cast <Element>()
                                 .ToList());
            //collectFromModel.Add(karkas);

            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());

            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Rebar))
                                 .WherePasses(stageFilter)
                                 .ToElements().ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(RebarInSystem))
                                 .WherePasses(stageFilter)
                                 .ToElements().ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(Railing))
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .ToElements()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(HostedSweep))
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .ToElements()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfClass(typeof(FabricSheet))
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .ToElements()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionPlates)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructConnectionAnchors)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .ToList());
            collectFromModel.Add(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel)
                                 .WhereElementIsNotElementType()
                                 .WherePasses(stageFilter)
                                 .Cast <Element>()
                                 .Where(x => x.Name != "cube")
                                 .ToList());


            List <Element> floors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors)
                                    .WhereElementIsNotElementType()
                                    .WherePasses(stageFilter)
                                    .Cast <Element>()
                                    .ToList();
            List <Element> walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
                                   .WhereElementIsNotElementType()
                                   .WherePasses(stageFilter)
                                   .Cast <Element>()
                                   .ToList();
            List <Element> fundament = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFoundation)
                                       .WhereElementIsNotElementType()
                                       .WherePasses(stageFilter)
                                       .Cast <Element>()
                                       .ToList();
            List <Element> lestnici = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Stairs)
                                      .WhereElementIsNotElementType()
                                      .WherePasses(stageFilter)
                                      .Cast <Element>()
                                      .ToList();
            List <string> ororo = fundament.Select(x => x.Name).ToList();

            //genModel = genModel.Where(x => x.Name != "cube").ToList();
            List <Cube> allCube = new List <Cube>();

            //List<Cube> someCube = new List<Cube>();

            foreach (Element f in floors)
            {
                foreach (ElementId m in f.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }

            foreach (Element w in walls)
            {
                foreach (ElementId m in w.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), w);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }

            foreach (Element f in fundament)
            {
                if (doc.GetElement(f.GetTypeId()).LookupParameter("шт/м/м2/м3") != null && doc.GetElement(f.GetTypeId()).LookupParameter("шт/м/м2/м3").AsInteger() == 0)
                {
                    Cube abc = new Cube(f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
                else
                {
                    foreach (ElementId m in f.GetMaterialIds(false))
                    {
                        Cube abc = new Cube(doc.GetElement(m), f);
                        if (abc.out_Name != null)
                        {
                            allCube.Add(abc);
                        }
                    }
                }
            }
            foreach (Element f in lestnici)
            {
                foreach (ElementId m in f.GetMaterialIds(false))
                {
                    Cube abc = new Cube(doc.GetElement(m), f);
                    if (abc.out_Name != null)
                    {
                        allCube.Add(abc);
                    }
                }
            }
            foreach (List <Element> a in collectFromModel)
            {
                foreach (Element e in a)
                {
                    Cube abc = new Cube(e);
                    if (abc.out_Name == null)
                    {
                        abc.out_Name   = "Исключение: " + abc.typeName;
                        abc.DontSetPos = true;
                    }
                    allCube.Add(abc);
                }
            }
            List <List <Cube> > groupingCube = new List <List <Cube> >();

            //List<string> groupNum=allCube.Select(x => x.Group).Distinct().ToList();

            foreach (string eqGroup in allCube.Select(x => x.out_Group).Distinct())
            {
                if (eqGroup == "" | eqGroup == null)
                {
                    continue;
                }
                List <Cube> similarGroup = new List <Cube>();
                foreach (Cube c in allCube)
                {
                    if (c.out_Group == eqGroup)
                    {
                        similarGroup.Add(c);
                    }
                }
                groupingCube.Add(similarGroup);
            }

            List <Cube> outCube = new List <Cube>();

            foreach (List <Cube> item in groupingCube)
            {
                int a = 1;
                //int addpos = 1;
                foreach (myTypes mt in item.Select(x => x.mType).Distinct())
                {
                    foreach (string eqName in item.Select(x => x.out_Name).Distinct())
                    {
                        List <Cube> b = item
                                        .Where(x => x.mType == mt)
                                        .Where(y => y.out_Name == eqName)
                                        .ToList();
                        if (b.Count == 0)
                        {
                            continue;
                        }
                        (Cube addCube, int addpos) = Meta.forgeCube(b, a);
                        if (!addCube.DontSetPos)
                        {
                            a += addpos;
                        }


                        outCube.Add(addCube);
                    }
                }
            }

            List <List <Cube> > secondOutCube = new List <List <Cube> >();

            foreach (string eqGr in outCube.Select(x => x.out_Name).Distinct())
            {
                foreach (Cube cube in outCube)
                {
                }
            }
            //foreach (string eqGroup in outCube.Select(x => x.out_Group).Distinct())
            //{
            //    List<Cube> similarGroup = new List<Cube>();
            //    foreach (Cube c in allCube)
            //    {
            //        if (c.out_Group == eqGroup)
            //        {
            //            similarGroup.Add(c);
            //        }
            //    }
            //    int i = 1;
            //    similarGroup.OrderBy(x => x.Prior);
            //    foreach (var item in similarGroup)
            //    {
            //        item.out_Pos = i.ToString();
            //        i++;
            //        secondOutCube.Add(item);
            //    }

            //    //similarGroup.short
            //    //secondOutCube.Add(similarGroup.Select());
            //}
            //outCube = secondOutCube;



            ElementParameterFilter cubeFilter = new ElementParameterFilter(new FilterStringRule(new ParameterValueProvider(new ElementId((int)BuiltInParameter.ALL_MODEL_TYPE_NAME)), new FilterStringEquals(), "cube", false));
            List <FamilyInstance>  existCubes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().WherePasses(cubeFilter).Cast <FamilyInstance>().ToList();


            using (Transaction tr = new Transaction(doc, "ModelledSpec"))
            {
                tr.Start();
                foreach (FamilyInstance i in existCubes)
                {
                    doc.Delete(i.Id);
                }
                foreach (Cube i in outCube)
                {
                    if (i.posElements.Count != 0)
                    {
                        foreach (ElementExt e in i.posElements)
                        {
                            try
                            {
                                e.refElement.LookupParameter("СП_Позиция").Set(i.out_Pos);
                                e.refElement.LookupParameter("АН__Верх").Set(i.textUP);
                                e.refElement.LookupParameter("АН__Низ").Set(e.textDOWN);
                            }
                            catch
                            {
                            }
                        }
                    }

                    i.Create(doc);
                }

                tr.Commit();
            }

            TaskDialog msg = new TaskDialog("Info");

            msg.MainInstruction = outCube.Count.ToString();
            msg.Show();
            return(Result.Succeeded);
        }