Exemple #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);
        }
Exemple #2
0
        public static bool RemoveLinkedFamilyInfo(ElementType linkedType)
        {
            var removed = false;

            try
            {
                var entity = linkedType.GetEntity(familySchema);
                if (entity.IsValid())
                {
                    linkedType.DeleteEntity(familySchema);
                    removed = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to remove the linked family info from data storage.\n" + ex.Message, "Remove Linked Family Info", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(removed);
        }