Ejemplo n.º 1
0
        /// <summary>
        /// Sets document to the default family type pane.
        /// It will get all valid default types for the category and fill the data grid.
        /// </summary>
        public void SetDocument(Document document)
        {
            if (_document == document)
            {
                return;
            }

            _document = document;

            _dataGrid_DefaultFamilyTypes.Items.Clear();

            List <int> categories = GetAllFamilyCateogries(_document);

            if (categories.Count < 1)
            {
                return;
            }

            foreach (int cid in categories)
            {
                FamilyTypeRecord record = new FamilyTypeRecord();
                record.CategoryName = Enum.GetName(typeof(BuiltInCategory), cid);

                //RLog.WriteComment(String.Format("The valid default family type candidates of {0} are:", Enum.GetName(typeof(BuiltInCategory), cid)));
                FilteredElementCollector collector = new FilteredElementCollector(_document);
                collector = collector.OfClass(typeof(FamilySymbol));
                var query = from FamilySymbol et in collector
                            where et.IsValidDefaultFamilyType(new ElementId(cid))
                            select et; // Linq query

                ElementId defaultFamilyTypeId = _document.GetDefaultFamilyTypeId(new ElementId(cid));

                List <DefaultFamilyTypeCandidate> defaultFamilyTypeCandidates = new List <DefaultFamilyTypeCandidate>();
                foreach (FamilySymbol t in query)
                {
                    DefaultFamilyTypeCandidate item = new DefaultFamilyTypeCandidate()
                    {
                        Name       = t.FamilyName + " - " + t.Name,
                        Id         = t.Id,
                        CateogryId = new ElementId(cid)
                    };
                    defaultFamilyTypeCandidates.Add(item);
                    if (t.Id.IntegerValue == defaultFamilyTypeId.IntegerValue)
                    {
                        record.DefaultFamilyType = item;
                    }
                }
                record.DefaultFamilyTypeCandidates = defaultFamilyTypeCandidates;


                int index = _dataGrid_DefaultFamilyTypes.Items.Add(record);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Responses to the type selection changed.
        /// It will set the selected type as default type.
        /// </summary>
        private void DefaultFamilyTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 1 && e.RemovedItems.Count == 1)
            {
                System.Windows.Controls.ComboBox cb = sender as System.Windows.Controls.ComboBox;
                if (cb == null)
                {
                    return;
                }

                DefaultFamilyTypeCandidate item = e.AddedItems[0] as DefaultFamilyTypeCandidate;
                if (item == null)
                {
                    return;
                }

                _handler.SetData(item.CateogryId, item.Id);
                _event.Raise();
            }
        }