# Select Elements by Category (error can not get IselectionFilter)

**URL:** <https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953>\
**Category:** Developers\
**Tags:** revit, python\
**Created:** [March 4, 2023, 6:26am UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953 "2023-03-04T06:26:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![manhgt214](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/manhgt214/32/153251_2.png) [@manhgt214](https://forum.dynamobim.com/u/manhgt214)\
**Post date:** [March 4, 2023, 6:26am UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/1 "2023-03-04T06:26:07Z")

</div>

Hi!  
How to select elements by category.  
I tried but allway return except:

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/7/77b04b8e8b3af0ac2f92cac13716e8e824f84c0c.png)

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/a/6a99ea488c1dcb390d536bd633fa61ff5ab87859.png)

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/b/2bf3906a2d6ec76b2042686252cc5212f63d85ee.png)

```auto
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.UI.Selection import ISelectionFilter

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

class Single_Category(Selection.ISelectionFilter):
	def __init__ (self, cat):
		self.cat = cat
	def AllowElement(self, e):
		if e.Category.Name == self.cat:
			return True
		else:
			return False
	def AllowReference(self, ref, point):
		return true

def selects():
    try:
        picked = uidoc.Selection.PickObjects(Selection.ObjectType.Element, Single_Category('Walls'),"Let Select Model")
        element = [doc.GetElement(i) for i in picked]
    except:
        TaskDialog.Show("Operation canceled","Canceled by the user")
    #return element

clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
	def __init__ (self):
		self.InitializeComponent()
	def InitializeComponent(self):
		self.label1 = System.Windows.Forms.Label()
		self._button1 = System.Windows.Forms.Button()
		self._textBox1 = System.Windows.Forms.TextBox()
		self.SuspendLayout()
		# 
		# label1
		#
		self.label1.AutoSize = True
		self.label1.Location = System.Drawing.Point(15, 30)
		self.label1.Name = "label1"
		self.label1.Size = System.Drawing.Size(65, 25)
		self.label1.TabIndex = 1
		self.label1.Text = "１．A"
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(260, 230)
		self._button1.Name = "button2"
		self._button1.Size = System.Drawing.Size(75, 25)
		self._button1.TabIndex = 0
		self._button1.Text = "Select"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		# 
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(160, 30)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(175, 25)
		self._textBox1.TabIndex = 1
		self._textBox1.Text = "50"
		# 
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(360, 270)
		self.Controls.Add(self.label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._button1)
		self.MaximizeBox = False
		self.MinimizeBox = False
		self.ShowIcon = False
		self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		self.Name = "MainForm"
		self.Text = "SelectByCatagory"
		self.ResumeLayout(False)
		self.PerformLayout()

	def Button1Click(self, sender, e):
		self.selected = selects()
		pass

form = MainForm()
Application.Run(form)
OUT = form.selected

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [March 7, 2023, 10:59am UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/2 "2023-03-07T10:59:20Z")

</div>

Hello,  
Which version of Revit / Python Engine are you using ?

---

<div class="post-metadata">

**Author:** ![manhgt214](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/manhgt214/32/153251_2.png) [@manhgt214](https://forum.dynamobim.com/u/manhgt214)\
**Post date:** [March 7, 2023, 11:37am UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/3 "2023-03-07T11:37:32Z")

</div>

Hi!  
I tested for Revit2022 and Revit2023-IronPython, but not work.

---

<div class="post-metadata">

**Author:** ![Lazy\_BIM](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/lazy_bim/32/156170_2.png) [@Lazy\_BIM](https://forum.dynamobim.com/u/Lazy_BIM)\
**Post date:** [March 7, 2023, 12:08pm UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/4 "2023-03-07T12:08:31Z")

</div>

Hi,

Why don’t you use the node from the Data-Shapes package? Additionally, Data-Shapes has nodes for creating Window Forms in Revit. Check: [Blog – data|shapes](https://data-shapes.io/blog/)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/c/6c1d0c435cd69050253d7e039c22b6bfe09bab41.png)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [March 7, 2023, 3:22pm UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/5 "2023-03-07T15:22:43Z")

</div>

Here the code fixed

```auto
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.UI.Selection import ISelectionFilter

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

class Single_Category(ISelectionFilter):
	def __init__ (self, cat):
		self.cat = cat
	def AllowElement(self, e):
		if e.Category.Name == self.cat:
			return True
		else:
			return False
	def AllowReference(self, ref, point):
		return true

def selects():
	elements = []
	try:
		pickeds = uidoc.Selection.PickObjects(Selection.ObjectType.Element, Single_Category('Murs'),"Let Select Model")
		elements = [doc.GetElement(i) for i in pickeds]
	except:
		TaskDialog.Show("Operation canceled","Canceled by the user")
	return elements

clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
	def __init__ (self):
		self.InitializeComponent()
	def InitializeComponent(self):
		self.label1 = System.Windows.Forms.Label()
		self._button1 = System.Windows.Forms.Button()
		self._textBox1 = System.Windows.Forms.TextBox()
		self.SuspendLayout()
		# 
		# label1
		#
		self.label1.AutoSize = True
		self.label1.Location = System.Drawing.Point(15, 30)
		self.label1.Name = "label1"
		self.label1.Size = System.Drawing.Size(65, 25)
		self.label1.TabIndex = 1
		self.label1.Text = "１．A"
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(260, 230)
		self._button1.Name = "button2"
		self._button1.Size = System.Drawing.Size(75, 25)
		self._button1.TabIndex = 0
		self._button1.Text = "Select"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		# 
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(160, 30)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(175, 25)
		self._textBox1.TabIndex = 1
		self._textBox1.Text = "50"
		# 
		# MainForm
		# 
		self.ClientSize = System.Drawing.Size(360, 270)
		self.Controls.Add(self.label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._button1)
		self.MaximizeBox = False
		self.MinimizeBox = False
		self.ShowIcon = False
		self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		self.Name = "MainForm"
		self.Text = "SelectByCatagory"
		self.ResumeLayout(False)
		self.PerformLayout()

	def Button1Click(self, sender, e):
		self.selected = selects()
		self.Close()

form = MainForm()
Application.Run(form)
OUT = form.selected

```

---

<div class="post-metadata">

**Author:** ![manhgt214](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/manhgt214/32/153251_2.png) [@manhgt214](https://forum.dynamobim.com/u/manhgt214)\
**Post date:** [March 7, 2023, 10:48pm UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/6 "2023-03-07T22:48:07Z")

</div>

Yes, I know it. But I want control my form.

---

<div class="post-metadata">

**Author:** ![manhgt214](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/manhgt214/32/153251_2.png) [@manhgt214](https://forum.dynamobim.com/u/manhgt214)\
**Post date:** [March 8, 2023, 10:39am UTC](https://forum.dynamobim.com/t/select-elements-by-category-error-can-not-get-iselectionfilter/86953/7 "2023-03-08T10:39:03Z")

</div>

Thank you !!!
