Ejemplo n.º 1
0
        private void CheckNewTypes()
        {
            Dictionary <int, SyncProperties> newSyncDictionary = new Dictionary <int, SyncProperties>();
            List <int> deletedSync = new List <int>();

            foreach (int id in syncDictionary.Keys)
            {
                SyncProperties sp = syncDictionary[id];
                switch (sp.SyncType)
                {
                case SyncType.Category:
                    UpdateCategory(sp.CategoryID, newSyncDictionary, deletedSync);
                    break;

                case SyncType.Family:
                    UpdateFamily(sp.FamilyID, deletedSync);
                    break;
                }
            }
            //because dictionary collection cannot be modified during the foreach loop
            foreach (int id in newSyncDictionary.Keys)
            {
                SyncProperties sp = newSyncDictionary[id];
                syncDictionary.Add(sp.FamilyID, sp); //when adding new families
            }

            //when exisiting deleted families
            foreach (int id in deletedSync)
            {
                syncDictionary.Remove(id);
            }
        }
Ejemplo n.º 2
0
        private void UpdateCategory(int id, Dictionary <int, SyncProperties> newSync, List <int> deleted)
        {
            try
            {
                BuiltInCategory          enumCategory = (BuiltInCategory)id;
                FilteredElementCollector collector    = new FilteredElementCollector(doc);
                List <Element>           elementTypes = collector.OfCategory(enumCategory).OfClass(typeof(ElementType)).ToElements().ToList();

                if (elementTypes.Count > 0)
                {
                    foreach (Element element in elementTypes)
                    {
                        ElementType etype = (ElementType)element;
                        if (!symbolsToExclude.Contains(etype.Id))
                        {
                            symbolsToExclude.Add(etype.Id);

                            FamilySymbol symbol = etype as FamilySymbol;
                            if (null == symbol)
                            {
                                continue;
                            }
                            if (!syncDictionary.ContainsKey(symbol.Family.Id.IntegerValue) && !newSync.ContainsKey(symbol.Family.Id.IntegerValue))
                            {
                                SyncProperties sp = new SyncProperties();
                                sp.SyncType   = SyncType.Family;
                                sp.FamilyID   = symbol.Family.Id.IntegerValue;
                                sp.FamilyName = symbol.Family.Name;
                                newSync.Add(sp.FamilyID, sp);
                            }
                        }
                    }
                }
                else if (enumCategory == BuiltInCategory.OST_Views || enumCategory == BuiltInCategory.OST_Sheets)
                {
                    collector = new FilteredElementCollector(doc);
                    List <ViewFamilyType> viewTypeElements = collector.OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().ToList();
                    foreach (ViewFamilyType viewType in viewTypeElements)
                    {
                        string viewFamily = viewType.ViewFamily.ToString();
                        if (excludeViewFamily.Contains(viewFamily))
                        {
                            continue;
                        }
                        if (!symbolsToExclude.Contains(viewType.Id))
                        {
                            symbolsToExclude.Add(viewType.Id);
                        }
                    }
                }
                else
                {
                    deleted.Add(id);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to upadte categoires for auto-synchronization: \n" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void ReadSyncData()
        {
            try
            {
                Recordset recordset;
                recordset = daoDB.OpenTable("UI_AutoSyncOptions");

                if (recordset.RecordCount > 0)
                {
                    while (!recordset.EOF)
                    {
                        SyncProperties sp       = new SyncProperties();
                        string         syncType = recordset.Fields["SyncType"].Value;

                        switch (syncType)
                        {
                        case "Category":
                            sp.SyncType     = SyncType.Category;
                            sp.CategoryID   = int.Parse(recordset.Fields["CategoryID"].Value);
                            sp.CategoryName = recordset.Fields["CategoryName"].Value;
                            syncDictionary.Add(sp.CategoryID, sp);
                            break;

                        case "Family":
                            sp.SyncType   = SyncType.Family;
                            sp.FamilyID   = int.Parse(recordset.Fields["FamilyID"].Value);
                            sp.FamilyName = recordset.Fields["FamilyName"].Value;
                            syncDictionary.Add(sp.FamilyID, sp);
                            break;
                        }
                        recordset.MoveNext();
                    }
                }
                recordset.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Read Data from AutoSyncOptions table: \n" + ex.Message);
                CloseDatabase();
            }
        }