Esempio n. 1
0
        public static bool UpdateLinkedFamilyInfo(LinkedFamilyInfo familyInfo, ElementType linkedType)
        {
            var updated = false;

            try
            {
                if (null == familySchema)
                {
                    familySchema = CreateFamilySchema();
                }

                if (null != familySchema)
                {
                    var entity = linkedType.GetEntity(familySchema);
                    if (entity.IsValid())
                    {
                        linkedType.DeleteEntity(familySchema);
                    }
                    entity = new Entity(familySchema);
                    entity.Set <ElementId>(familySchema.GetField(s_SourceLinkInstanceId), familyInfo.SourceLinkInstanceId);
                    entity.Set <ElementId>(familySchema.GetField(s_SourceSymbolId), familyInfo.SourceTypeId);
                    entity.Set <ElementId>(familySchema.GetField(s_LinkedSymbolId), familyInfo.TargetTypeId);

                    linkedType.SetEntity(entity);
                    updated = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update the information of the linked family.\n" + ex.Message, "Update Linked Family Info", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(updated);
        }
Esempio n. 2
0
        private void buttonApply_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != comboBoxCategory.SelectedItem && null != comboBoxSourceFamily.SelectedItem && null != comboBoxTargetFamily.SelectedItem &&
                    null != comboBoxSourceType.SelectedItem && null != comboBoxTargetType.SelectedItem)
                {
                    var sourceType = (ElementTypeInfo)comboBoxSourceType.SelectedItem;
                    var targetType = (ElementTypeInfo)comboBoxTargetType.SelectedItem;
                    if (null != sourceType && null != targetType)
                    {
                        familyInfo = new LinkedFamilyInfo(selectedLink.InstanceId, sourceType, targetType);
                        m_handler.SelectedFamilyInfo = familyInfo;
                        m_handler.MoverRequest.Make(RequestId.AddFamilyMapping);
                        m_event.Raise();
                        SetFocus();


                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Please make sure you select a category and source and target families", "Missing Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add/edit the selected family map.\n" + ex.Message, "Family Map", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 3
0
        public static LinkedFamilyInfo GetLinkedFamilyInfo(ElementType linkedType)
        {
            LinkedFamilyInfo familyInfo = null;

            try
            {
                if (null == familySchema)
                {
                    familySchema = CreateFamilySchema();
                }

                if (null != familySchema)
                {
                    var entity = linkedType.GetEntity(familySchema);
                    if (entity.IsValid())
                    {
                        familyInfo = new LinkedFamilyInfo();
                        familyInfo.SourceLinkInstanceId = entity.Get <ElementId>(familySchema.GetField(s_SourceLinkInstanceId));
                        familyInfo.SourceTypeId         = entity.Get <ElementId>(familySchema.GetField(s_SourceSymbolId));
                        familyInfo.TargetTypeId         = entity.Get <ElementId>(familySchema.GetField(s_LinkedSymbolId));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the information from the linked family type.\n" + ex.Message, "Get Linked Family Info", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(familyInfo);
        }
Esempio n. 4
0
        private void CollectFamilyMaps()
        {
            try
            {
                var hostDoc     = Instance.Document;
                var categoryIds = Categories.Keys.ToList();
                foreach (var catId in categoryIds)
                {
                    var collector = new FilteredElementCollector(hostDoc);
                    var elements  = collector.OfCategoryId(catId).WhereElementIsElementType().ToElements().ToList();
                    foreach (var element in elements)
                    {
                        var elementType = element as ElementType;
                        if (null != elementType)
                        {
                            var familyInfo = MoverDataStorageUtil.GetLinkedFamilyInfo(elementType);
                            if (null != familyInfo)
                            {
                                if (familyInfo.SourceLinkInstanceId != InstanceId)
                                {
                                    continue;
                                }
                                if (element.Id != familyInfo.TargetTypeId)
                                {
                                    continue;
                                }

                                var sourceType = LinkedDocument.GetElement(familyInfo.SourceTypeId) as ElementType;
                                if (null != sourceType)
                                {
                                    var sourceTypeInfo = new ElementTypeInfo(sourceType);
                                    var targetTypeInfo = new ElementTypeInfo(elementType);

                                    familyInfo = new LinkedFamilyInfo(familyInfo.SourceLinkInstanceId, sourceTypeInfo, targetTypeInfo);
                                    if (!LinkedFamilies.ContainsKey(familyInfo.TargetTypeId))
                                    {
                                        LinkedFamilies.Add(familyInfo.TargetTypeId, familyInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect family maps.\n" + ex.Message, "Collect Family Maps", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 5
0
        public FamilyWindow(ExternalEvent extEvent, MoverHandler handler)
        {
            m_event   = extEvent;
            m_handler = handler;
            m_handler.FamilyWindowInstance = this;

            selectedLink = m_handler.SelectedLink;
            familyInfo   = m_handler.SelectedFamilyInfo;

            linkedDoc = selectedLink.LinkedDocument;
            hostDoc   = m_handler.CurrentDocument;
            CollectElementTypes();

            InitializeComponent();

            var categories = selectedLink.Categories.Values.OrderBy(o => o.CategoryName).ToList();

            comboBoxCategory.ItemsSource   = null;
            comboBoxCategory.ItemsSource   = categories;
            comboBoxCategory.SelectedIndex = 0;
        }