Esempio n. 1
0
        public Result setup_levels(Document doc)
        {
            Transaction trans = new Transaction(doc);
            FilteredElementCollector levels_col
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(Level));

            /*
             * Level[] levels = new Level[5];
             * foreach (Level lvl_ in levels_col)
             * {
             *  if (lvl_.Name == "Level 1")
             *  {
             *      levels[1] = lvl_;
             *  }
             *  if (lvl_.Name == "Level 2")
             *  {
             *      levels[2] = lvl_;
             *  }
             *  if (lvl_.Name == "Basement")
             *  {
             *      levels[0] = lvl_;
             *  }
             * }
             */

            // FIXME : delete Floor plans/Level 1


            using (Transaction t = new Transaction(doc))
            {
                t.Start("Activate door");
                doc.Regenerate();
                t.Commit();
            }

            FilteredElementCollector floorplans
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ViewPlan));



            List <ViewPlan> ViewPlans = floorplans.Cast <ViewPlan>().ToList();

            using (trans = new Transaction(doc))
            {
                trans.Start("Clean up views");

                foreach (ViewPlan view in ViewPlans)
                {
                    if (view.Name == "Level 2")
                    {
                        doc.Delete(view.Id);
                    }
                }

                trans.Commit();
            }


            using (trans = new Transaction(doc))
            {
                trans.Start("Basement");
                Level lvl = Level.Create(doc, -8.5);
                lvl.Name = "Basement";
                trans.Commit();
            }

            using (trans = new Transaction(doc))
            {
                trans.Start("Roof");
                Level lvl = Level.Create(doc, 20);
                lvl.Name = "Roof";
                trans.Commit();
            }

            using (trans = new Transaction(doc))
            {
                trans.Start("Garage");
                Level lvl = Level.Create(doc, -2);
                lvl.Name = "Garage";
                trans.Commit();
            }


            FilteredElementCollector DimensionTypeCollector = new FilteredElementCollector(doc);

            DimensionTypeCollector.OfClass(typeof(DimensionType));

            DimensionType dimensionType = DimensionTypeCollector.Cast <DimensionType>().ToList().FirstOrDefault();

            using (trans = new Transaction(doc))
            {
                trans.Start("SetDimensionsTypes");
                DimensionType newdimensionType = dimensionType.Duplicate("type-correct") as DimensionType;
                newdimensionType.LookupParameter("Color").Set(0);

                newdimensionType = dimensionType.Duplicate("type-unknown") as DimensionType;
                newdimensionType.LookupParameter("Color").Set(125);

                newdimensionType = dimensionType.Duplicate("type-incorrect") as DimensionType;
                newdimensionType.LookupParameter("Color").Set(255);

                trans.Commit();
            }
            return(Result.Succeeded);
        }