Revit 二次开发设定选择只能是某种类型

此处设置为只能选择体量

/// 
        /// 设定选择只能是体量
        /// 
        public class FormSelectionFilter : ISelectionFilter
        {
            public bool AllowElement(Element elem)
            {
                if (elem.Category.Name == "体量")
                    return true;
                else return false;
            }

            public bool AllowReference(Reference reference, XYZ position)
            {
                return false;
            }
        }

        private void button_ClickChoose(object sender, RoutedEventArgs e)
        {
            this.Hide();


            
            Element ele;
            try
            {

                Reference reference = uidoc.Selection.PickObject(ObjectType.Element, new FormSelectionFilter());
                ele = doc.GetElement(reference) as Element;
                
                this.Show();
 
                textBoxOne.Text = ele.Category.Name;
      
            }
            catch (Exception ex)
            {
                TaskDialog.Show("选择错误", ex.Message);
            }
            finally
            {
                this.Show();
            }

        }

你可能感兴趣的:(学习历程,c#)