Exemple #1
0
        private static ListViewItem ListViewItemFromZone(ZoneData zone, Units docUnits)
        {
            ListViewItem listViewItem = new ListViewItem(zone.Name);

            listViewItem.Tag = zone;
            string[] array = new string[12]
            {
                "Bottom",
                FormatDatumOffsetString(zone.BaseLevel, zone.BaseOffset, docUnits),
                "Top",
                FormatDatumOffsetString(zone.TopLevel, zone.TopOffset, docUnits),
                "North",
                FormatDatumOffsetString(zone.NorthGrid, zone.NorthOffset, docUnits),
                "South",
                FormatDatumOffsetString(zone.SouthGrid, zone.SouthOffset, docUnits),
                "East",
                FormatDatumOffsetString(zone.EastGrid, zone.EastOffset, docUnits),
                "West",
                FormatDatumOffsetString(zone.WestGrid, zone.WestOffset, docUnits)
            };
            for (int i = 0; i < array.Length; i += 2)
            {
                ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
                listViewSubItem.Name = array[i];
                listViewSubItem.Text = array[i + 1];
                listViewItem.SubItems.Add(listViewSubItem);
            }
            return(listViewItem);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication          val          = commandData.get_Application();
            Document               doc          = val.get_ActiveUIDocument().get_Document();
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(doc);
            IList <ElementId>      list         = (from z in (IEnumerable <FamilyInstance>) projectZones
                                                   select z.get_Id()).ToList();
            bool        flag = projectZones.All((FamilyInstance z) => z.IsHidden(doc.get_ActiveView()));
            Transaction val2 = new Transaction(doc, flag ? "Unhide Zones" : "Hide Zones");

            try
            {
                val2.Start();
                if (flag)
                {
                    doc.get_ActiveView().UnhideElements((ICollection <ElementId>)list);
                }
                else
                {
                    doc.get_ActiveView().HideElements((ICollection <ElementId>)list);
                }
                val2.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
        public void Execute(UpdaterData data)
        {
            Document         doc  = data.GetDocument();
            List <ElementId> list = data.GetAddedElementIds().ToList();

            list.AddRange(data.GetModifiedElementIds());
            IList <Element> first = (from ElementId id in list
                                     select doc.GetElement(id)).ToList();
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(doc);
            IList <ElementId>      list2        = (from Element pZ in projectZones
                                                   select pZ.get_Id()).ToList();
            Parameter val = (from FamilyInstance pZ in projectZones
                             let param = pZ.LookupParameter("Name")
                                         where param != null
                                         select param).First();
            Definition zoneNameDef = val.get_Definition();

            foreach (Element item in first.Except((IEnumerable <Element>)projectZones))
            {
                BoundingBoxXYZ val2 = item.get_BoundingBox(null);
                if (val2 != null)
                {
                    BoundingBoxIntersectsFilter val3   = new BoundingBoxIntersectsFilter(ToOutline(val2));
                    IList <Element>             source = new FilteredElementCollector(doc, (ICollection <ElementId>)list2).WherePasses(val3).ToElements();
                    IEnumerable <string>        values = from Element zone in source
                                                         let name = zone.get_Parameter(zoneNameDef).AsString()
                                                                    where !string.IsNullOrWhiteSpace(name)
                                                                    select name;
                    string text = string.Join(", ", values);
                    item.LookupParameter("Zone").Set(text);
                }
            }
        }
Exemple #4
0
        private void buttonNew_Click(object sender, EventArgs e)
        {
            ZoneData     zone         = new ZoneData();
            ListViewItem listViewItem = ListViewItemFromZone(zone, m_docUnits);

            listView.Items.Add(listViewItem);
            EditProjectZone(listViewItem);
        }
Exemple #5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication              val  = commandData.get_Application();
            Document                   val2 = val.get_ActiveUIDocument().get_Document();
            Selection                  val3 = val.get_ActiveUIDocument().get_Selection();
            IList <ZoneData>           projectZonesAsZoneData = ZoneData.GetProjectZonesAsZoneData(val2);
            IEnumerable <Element>      enumerable             = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(Level)).ToElements();
            SortedList <double, Level> sortedList             = new SortedList <double, Level>(enumerable.Count());

            foreach (Level item in enumerable)
            {
                Level val4 = item;
                sortedList.Add(val4.get_Elevation(), val4);
            }
            IList <Element>           list        = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(Grid)).ToElements();
            SortedList <double, Grid> sortedList2 = new SortedList <double, Grid>();
            SortedList <double, Grid> sortedList3 = new SortedList <double, Grid>();

            foreach (Grid item2 in list)
            {
                Grid val5 = item2;
                if (isNorthSouth(val5))
                {
                    sortedList2.Add(val5.get_Curve().GetEndPoint(0).get_X(), val5);
                }
                else if (isEastWest(val5))
                {
                    sortedList3.Add(val5.get_Curve().GetEndPoint(0).get_Y(), val5);
                }
            }
            editZonesForm = new EditZonesForm(projectZonesAsZoneData, sortedList, sortedList2, sortedList3, val2.GetUnits());
            editZonesForm.ShowDialog();
            if (editZonesForm.DialogResult == DialogResult.OK)
            {
                IList <ZoneData> editedZones = editZonesForm.EditedZones;
                Transaction      val6        = new Transaction(val2, "Update Project Zones");
                try
                {
                    val6.Start();
                    ZoneData.UpdateRevitProjectZones(val2, editedZones);
                    val6.Commit();
                }
                catch (OperationCanceledException)
                {
                    return(1);
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return(-1);
                }
                return(0);
            }
            return(1);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication  val   = commandData.get_Application();
            Document       val2  = val.get_ActiveUIDocument().get_Document();
            IList <View3D> views = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(View3D)).ToElements()
                                   .Cast <View3D>()
                                   .ToList();
            ViewsForZonesForm viewsForZonesForm = new ViewsForZonesForm(views, val2.get_ActiveView() as View3D);

            viewsForZonesForm.ShowDialog();
            if (viewsForZonesForm.DialogResult != DialogResult.OK)
            {
                return(1);
            }
            View3D selectedView = viewsForZonesForm.SelectedView;
            XYZ    val3         = new XYZ(0.0 - VIEW_CROP_OFFSETS[5], 0.0 - VIEW_CROP_OFFSETS[3], 0.0 - VIEW_CROP_OFFSETS[1]);
            XYZ    val4         = new XYZ(VIEW_CROP_OFFSETS[4], VIEW_CROP_OFFSETS[2], VIEW_CROP_OFFSETS[0]);
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(val2);
            Transaction            val5         = new Transaction(val2, "Create Views for Project Zones");

            try
            {
                val5.Start();
                foreach (FamilyInstance item in projectZones)
                {
                    ElementId      val6 = selectedView.Duplicate(0);
                    View3D         val7 = val2.GetElement(val6) as View3D;
                    BoundingBoxXYZ val8 = item.get_BoundingBox(null);
                    BoundingBoxXYZ val9 = new BoundingBoxXYZ();
                    val9.set_Min(val8.get_Min() + val3);
                    val9.set_Max(val8.get_Max() + val4);
                    val7.set_Name("3D " + item.LookupParameter("Name").AsString());
                    val7.SetSectionBox(val9);
                }
                val5.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
Exemple #7
0
        private void EditProjectZone(ListViewItem zoneItem)
        {
            ZoneData           zoneData           = zoneItem.Tag as ZoneData;
            EditZoneBoundsForm editZoneBoundsForm = new EditZoneBoundsForm(zoneData, m_Levels, m_GridsNorthSouth, m_GridsEastWest, m_docUnits);

            editZoneBoundsForm.ShowDialog();
            if (editZoneBoundsForm.DialogResult == DialogResult.OK)
            {
                zoneData.Name        = editZoneBoundsForm.ZoneName;
                zoneData.TopLevel    = editZoneBoundsForm.SelectedTopLevel;
                zoneData.BaseLevel   = editZoneBoundsForm.SelectedBaseLevel;
                zoneData.NorthGrid   = editZoneBoundsForm.SelectedNorthGrid;
                zoneData.SouthGrid   = editZoneBoundsForm.SelectedSouthGrid;
                zoneData.EastGrid    = editZoneBoundsForm.SelectedEastGrid;
                zoneData.WestGrid    = editZoneBoundsForm.SelectedWestGrid;
                zoneData.TopOffset   = editZoneBoundsForm.TopOffset;
                zoneData.BaseOffset  = editZoneBoundsForm.BaseOffset;
                zoneData.NorthOffset = editZoneBoundsForm.NorthOffset;
                zoneData.SouthOffset = editZoneBoundsForm.SouthOffset;
                zoneData.EastOffset  = editZoneBoundsForm.EastOffset;
                zoneData.WestOffset  = editZoneBoundsForm.WestOffset;
            }
            zoneItem.ListView.Items[zoneItem.Index] = ListViewItemFromZone(zoneData, m_docUnits);
        }
Exemple #8
0
        private void CreateZonesByLevel()
        {
            CreateZonesByLevelForm createZonesByLevelForm = new CreateZonesByLevelForm(m_Levels, m_GridsNorthSouth, m_GridsEastWest, m_docUnits);

            createZonesByLevelForm.ShowDialog();
            if (createZonesByLevelForm.DialogResult == DialogResult.OK)
            {
                SortedList <double, Level> selectedLevels          = createZonesByLevelForm.SelectedLevels;
                SortedList <double, Grid>  selectedGridsNorthSouth = createZonesByLevelForm.SelectedGridsNorthSouth;
                SortedList <double, Grid>  selectedGridsEastWest   = createZonesByLevelForm.SelectedGridsEastWest;
                double overallLevelOffset   = createZonesByLevelForm.OverallLevelOffset;
                List <LevelOffsetPair> list = new List <LevelOffsetPair>(selectedLevels.Count + 2);
                Level val = m_Levels.Values.FirstOrDefault();
                if (createZonesByLevelForm.HasLowerBound && val != null)
                {
                    list.Add(new LevelOffsetPair(val, -20.0));
                }
                foreach (Level value in selectedLevels.Values)
                {
                    list.Add(new LevelOffsetPair(value, overallLevelOffset));
                }
                Level val2 = m_Levels.Values.LastOrDefault();
                if (createZonesByLevelForm.HasUpperBound && val2 != null)
                {
                    list.Add(new LevelOffsetPair(val2, 20.0));
                }
                List <GridOffsetPair> list2 = new List <GridOffsetPair>(selectedGridsNorthSouth.Count + 2);
                if (createZonesByLevelForm.HasWestBound)
                {
                    list2.Add(new GridOffsetPair(null, 0.0));
                }
                foreach (Grid value2 in selectedGridsNorthSouth.Values)
                {
                    list2.Add(new GridOffsetPair(value2, 0.0));
                }
                if (createZonesByLevelForm.HasEastBound)
                {
                    list2.Add(new GridOffsetPair(m_GridsNorthSouth.Values.LastOrDefault(), 20.0));
                }
                List <GridOffsetPair> list3 = new List <GridOffsetPair>(selectedGridsEastWest.Count + 2);
                if (createZonesByLevelForm.HasSouthBound)
                {
                    list3.Add(new GridOffsetPair(null, 0.0));
                }
                foreach (Grid value3 in selectedGridsEastWest.Values)
                {
                    list3.Add(new GridOffsetPair(value3, 0.0));
                }
                if (createZonesByLevelForm.HasNorthBound)
                {
                    list3.Add(new GridOffsetPair(m_GridsEastWest.Values.LastOrDefault(), 20.0));
                }
                bool             flag  = list3.Count > 2 || list2.Count > 2;
                IList <ZoneData> list4 = new List <ZoneData>();
                for (int i = 0; i < list.Count - 1; i++)
                {
                    char c = 'A';
                    for (int j = 0; j < list2.Count - 1; j++)
                    {
                        for (int k = 0; k < list3.Count - 1; k++)
                        {
                            ZoneData zoneData = new ZoneData();
                            if (flag)
                            {
                                ZoneData zoneData2 = zoneData;
                                object   arg       = i;
                                char     num       = c;
                                c = (char)(num + 1);
                                zoneData2.Name = $"Z-{arg:00}{num}";
                            }
                            else
                            {
                                zoneData.Name = $"Z-{i:00}";
                            }
                            zoneData.BaseLevel   = list[i].Level;
                            zoneData.BaseOffset  = list[i].Offset;
                            zoneData.WestGrid    = list2[j].Grid;
                            zoneData.WestOffset  = list2[j].Offset;
                            zoneData.SouthGrid   = list3[k].Grid;
                            zoneData.SouthOffset = list3[k].Offset;
                            zoneData.TopLevel    = list[i + 1].Level;
                            zoneData.TopOffset   = list[i + 1].Offset;
                            zoneData.EastGrid    = list2[j + 1].Grid;
                            zoneData.EastOffset  = list2[j + 1].Offset;
                            zoneData.NorthGrid   = list3[k + 1].Grid;
                            zoneData.NorthOffset = list3[k + 1].Offset;
                            list4.Add(zoneData);
                        }
                    }
                }
                ListViewItem[] items = (from zd in list4
                                        select ListViewItemFromZone(zd, m_docUnits)).ToArray();
                listView.Items.AddRange(items);
            }
        }
        public EditZoneBoundsForm(ZoneData zone, SortedList <double, Level> levels, SortedList <double, Grid> gridsNorthSouth, SortedList <double, Grid> gridsEastWest, Units docUnits)
        {
            InitializeComponent();
            if (!string.IsNullOrWhiteSpace(zone.Name))
            {
                textBoxName.Text = zone.Name;
            }
            else
            {
                textBoxName.Text = "Zone";
            }
            m_Levels          = levels;
            m_GridsNorthSouth = gridsNorthSouth;
            m_GridsEastWest   = gridsEastWest;
            string[] array = (from l in m_Levels.Values
                              select l.get_Name()).ToArray();
            ComboBox[] array2 = new ComboBox[2]
            {
                comboBoxTopLevel,
                comboBoxBottomLevel
            };
            ComboBox[] array3 = array2;
            object[]   items2;
            foreach (ComboBox comboBox in array3)
            {
                ComboBox.ObjectCollection items = comboBox.Items;
                items2 = array;
                items.AddRange(items2);
            }
            ComboBox comboBox2 = comboBoxTopLevel;
            object   topLevel  = (object)zone.TopLevel;

            comboBox2.SelectedItem = (((topLevel != null) ? topLevel.get_Name() : null) ?? array.Last());
            ComboBox comboBox3 = comboBoxBottomLevel;
            object   baseLevel = (object)zone.BaseLevel;

            comboBox3.SelectedItem = (((baseLevel != null) ? baseLevel.get_Name() : null) ?? array.First());
            string[] array4 = (from g in m_GridsNorthSouth.Values
                               select g.get_Name()).ToArray();
            string[] array5 = (from g in m_GridsEastWest.Values
                               select g.get_Name()).ToArray();
            ComboBox.ObjectCollection items3 = comboBoxNorthGrid.Items;
            items2 = array5;
            items3.AddRange(items2);
            ComboBox.ObjectCollection items4 = comboBoxSouthGrid.Items;
            items2 = array5;
            items4.AddRange(items2);
            ComboBox.ObjectCollection items5 = comboBoxEastGrid.Items;
            items2 = array4;
            items5.AddRange(items2);
            ComboBox.ObjectCollection items6 = comboBoxWestGrid.Items;
            items2 = array4;
            items6.AddRange(items2);
            comboBoxNorthGrid.Items.Add("Origin");
            comboBoxSouthGrid.Items.Add("Origin");
            comboBoxEastGrid.Items.Add("Origin");
            comboBoxWestGrid.Items.Add("Origin");
            ComboBox comboBox4 = comboBoxNorthGrid;
            object   northGrid = (object)zone.NorthGrid;

            comboBox4.SelectedItem = (((northGrid != null) ? northGrid.get_Name() : null) ?? "Origin");
            ComboBox comboBox5 = comboBoxSouthGrid;
            object   southGrid = (object)zone.SouthGrid;

            comboBox5.SelectedItem = (((southGrid != null) ? southGrid.get_Name() : null) ?? "Origin");
            ComboBox comboBox6 = comboBoxEastGrid;
            object   eastGrid  = (object)zone.EastGrid;

            comboBox6.SelectedItem = (((eastGrid != null) ? eastGrid.get_Name() : null) ?? "Origin");
            ComboBox comboBox7 = comboBoxWestGrid;
            object   westGrid  = (object)zone.WestGrid;

            comboBox7.SelectedItem     = (((westGrid != null) ? westGrid.get_Name() : null) ?? "Origin");
            inputBoxTopOffset          = new FormattedInputBox(textBoxTopOffset, docUnits, 0);
            inputBoxBottomOffset       = new FormattedInputBox(textBoxBottomOffset, docUnits, 0);
            inputBoxNorthOffset        = new FormattedInputBox(textBoxNorthOffset, docUnits, 0);
            inputBoxSouthOffset        = new FormattedInputBox(textBoxSouthOffset, docUnits, 0);
            inputBoxEastOffset         = new FormattedInputBox(textBoxEastOffset, docUnits, 0);
            inputBoxWestOffset         = new FormattedInputBox(textBoxWestOffset, docUnits, 0);
            inputBoxTopOffset.Value    = zone.TopOffset;
            inputBoxBottomOffset.Value = zone.BaseOffset;
            inputBoxNorthOffset.Value  = zone.NorthOffset;
            inputBoxSouthOffset.Value  = zone.SouthOffset;
            inputBoxEastOffset.Value   = zone.EastOffset;
            inputBoxWestOffset.Value   = zone.WestOffset;
            textBoxName.SelectAll();
        }