Esempio n. 1
0
 private void textBoxDataFile_TextChanged(object sender, TextChangedEventArgs e)
 {
     try
     {
         if (!string.IsNullOrEmpty(textBoxDataFile.Text))
         {
             if (File.Exists(textBoxDataFile.Text))
             {
                 XmlSerializer serializer = new XmlSerializer(typeof(AnalysisDataCollection));
                 FileStream    fs         = new FileStream(textBoxDataFile.Text, FileMode.Open);
                 XmlReader     reader     = XmlReader.Create(fs);
                 if (serializer.CanDeserialize(reader))
                 {
                     analysisDataCollection = (AnalysisDataCollection)serializer.Deserialize(reader);
                 }
                 reader.Close();
                 fs.Close();
             }
         }
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show("Failed to read point data from the xml file.\n" + ex.Message, "Read Result Data File", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        public ViewAnalysisManager(UIApplication uiapp, List <Room> rooms, AnalysisSettings settings, AnalysisDataCollection analysisDataCollection)
        {
            try
            {
                m_app            = uiapp;
                m_doc            = m_app.ActiveUIDocument.Document;
                selectedRooms    = rooms;
                analysisSettings = settings;
                overwriteData    = analysisSettings.OverwriteData;
                dataCollection   = analysisDataCollection;
                epsilon          = m_app.Application.ShortCurveTolerance;

                categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Walls));             //intercepting elements.
                categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Windows));           //passing elements
                categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_CurtainWallPanels)); //passing elements
                categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_Doors));             //passing elements
                categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns)); //intercepting elements
                if (includeLinkedModel)
                {
                    categoryFilters.Add(new ElementCategoryFilter(BuiltInCategory.OST_RvtLinks));
                }                                                                                                         //find elements in link

                m_view          = FindDefault3DView();
                linkedInstances = GetLinkedInstancesInfo();

                if (analysisSettings.ExteriorWallByParameter)
                {
                    exteriorElementIds = BuildingEnvelopUtil.FindExteriorWallsByParameter(m_doc, linkedInstances, includeLinkedModel);
                }
                else
                {
                    exteriorElementIds = BuildingEnvelopUtil.FindExteriorWallsByAnalyzer(m_doc, m_view, selectedRooms.First(), includeLinkedModel);
                    bool paramResult = BuildingEnvelopUtil.SetExteriorWallParameter(m_doc, exteriorElementIds);
                }

                if (exteriorElementIds.Count > 0)
                {
                    roomDictionary = GetRoomData(selectedRooms);
                    if (roomDictionary.Count > 0)
                    {
                        m_sfm = SetSpatialFieldManager(m_doc.ActiveView, out resultIndex);
                    }
                }
                else
                {
                    MessageBox.Show("Please select exterior walls and set LEED_IsExteriorWall parameter true.\n", "Exterior Walls Not Defined", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to run View Analysis.\n" + ex.Message, "View Analysis Manager", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 3
0
        private bool SaveResultData(Dictionary <int, RoomData> roomDictionary)
        {
            bool saved = false;

            try
            {
                if (!string.IsNullOrEmpty(settings.DataFileName))
                {
                    analysisDataCollection = new AnalysisDataCollection();

                    foreach (int roomId in roomDictionary.Keys)
                    {
                        RoomData roomData = roomDictionary[roomId];
                        int      index    = analysisDataCollection.AnalysisDataList.FindIndex(o => o.RoomId == roomId);
                        if (settings.OverwriteData)
                        {
                            if (index > -1)
                            {
                                analysisDataCollection.AnalysisDataList.RemoveAt(index);
                            }
                            AnalysisData aData = new AnalysisData();
                            aData.RoomId      = roomData.RoomId;
                            aData.RoomArea    = roomData.RoomArea;
                            aData.VisibleArea = roomData.AreaWithViews;
                            aData.RoomFace    = FMEDataUtil.ConvertRevitFaceToFMEArea(roomData.RoomFace);
                            aData.PointValues = FMEDataUtil.ConvertToFMEPointList(roomData.PointDataList);
                            analysisDataCollection.AnalysisDataList.Add(aData);
                        }
                        else if (index == -1)
                        {
                            //add new room data only if it doesn't exist
                            AnalysisData aData = new AnalysisData();
                            aData.RoomId      = roomData.RoomId;
                            aData.RoomArea    = roomData.RoomArea;
                            aData.VisibleArea = roomData.AreaWithViews;
                            aData.RoomFace    = FMEDataUtil.ConvertRevitFaceToFMEArea(roomData.RoomFace);
                            aData.PointValues = FMEDataUtil.ConvertToFMEPointList(roomData.PointDataList);
                            analysisDataCollection.AnalysisDataList.Add(aData);
                        }
                    }

                    if (analysisDataCollection.AnalysisDataList.Count > 0)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AnalysisDataCollection));
                        StreamWriter  writer     = new StreamWriter(settings.DataFileName);
                        serializer.Serialize(writer, analysisDataCollection);
                        writer.Close();
                        saved = true;
                    }
                }
                else
                {
                    saved = true;
                }
            }
            catch (Exception ex)
            {
                saved = false;
                System.Windows.MessageBox.Show("Failed to save analysis data.\n" + ex.Message, "Save Result Data", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(saved);
        }