{"id":116,"date":"2015-08-03T00:09:37","date_gmt":"2015-08-02T23:09:37","guid":{"rendered":"http:\/\/pythoncvc.net\/?p=116"},"modified":"2015-08-03T01:46:34","modified_gmt":"2015-08-03T00:46:34","slug":"revit-iselectionfilter-example-using-python","status":"publish","type":"post","link":"https:\/\/pythoncvc.net\/?p=116","title":{"rendered":"[Revit] ISelectionFilter example using python"},"content":{"rendered":"<p>Someone asked an exemple of\u00a0ISelectionFilter <a href=\"https:\/\/groups.google.com\/forum\/#!topic\/RevitPythonShell\/4LWkBglkfE4\" target=\"_blank\">on RevitPythonShell group<\/a> almost a week ago. I don&rsquo;t know if he still needs it but anyway, it&rsquo;s interesting\u00a0 to show this other way to filter. In this exemple we allow user only to select a duct. Let see the code snippet :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">from Autodesk.Revit.UI.Selection import *\r\n\r\nclass CustomISelectionFilter(ISelectionFilter):\r\n\tdef __init__(self, nom_categorie):\r\n\t\tself.nom_categorie = nom_categorie\r\n\tdef AllowElement(self, e):\r\n\t\tif e.Category.Name == self.nom_categorie:\r\n\t\t\treturn True\r\n\t\telse:\r\n\t\t\treturn False\r\n\tdef AllowReference(self, ref, point):\r\n\t\treturn true\r\n\r\ntry:\r\n\tductsel = uidoc.Selection.PickObject(ObjectType.Element,\r\n\tCustomISelectionFilter(\"Ducts\"),\r\n\t\"Select a Duct\")\t\t\t\r\nexcept Exceptions.OperationCanceledException:\r\n\tTaskDialog.Show(\"Op\u00e9ration annul\u00e9e\",\"Annul\u00e9e par l'utilisateur\")\r\n\r\n__window__.Close()<\/pre>\n<p>Here in action :<\/p>\n<p><iframe loading=\"lazy\" title=\"ISelectionFilter example in python, Select a Duct\" width=\"620\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/U_iRYeNDpFg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Here is another exemple to select only objects inherited from MEPCurve (Cable Tray, Wire, InsulationLiningBase, Duct, FlexDuct, FlexPipe, Pipe) :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">from Autodesk.Revit.UI.Selection import *\r\nclass CustomISelectionFilter(ISelectionFilter):\r\n\u00a0\u00a0 \u00a0def __init__(self, element_class):\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0self.element_class = element_class\r\n\u00a0\u00a0 \u00a0def AllowElement(self, e):\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if isinstance(e, self.element_class):\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return True\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0else:\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return False\r\n\u00a0\u00a0 \u00a0def AllowReference(self, ref, point):\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return true\r\n\r\ntry:\r\n\u00a0\u00a0 \u00a0ductsel = uidoc.Selection.PickObject(ObjectType.Element,\r\n\u00a0\u00a0 \u00a0CustomISelectionFilter(MEPCurve),\r\n\u00a0\u00a0 \u00a0\"Select a Duct\")\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\nexcept Exceptions.OperationCanceledException:\r\n\u00a0\u00a0 \u00a0TaskDialog.Show(\"Op\u00e9ration annul\u00e9e\",\"Annul\u00e9e par l'utilisateur\")\r\n\r\n__window__.Close()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Someone asked an exemple of\u00a0ISelectionFilter on RevitPythonShell group almost a week ago. I don&rsquo;t know if he still needs it but anyway, it&rsquo;s interesting\u00a0 to show this other way to filter. In this exemple we allow user only to select a duct. Let see the code snippet : from Autodesk.Revit.UI.Selection import * class CustomISelectionFilter(ISelectionFilter): def [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[38,34],"tags":[52,48,50,54],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-revit-en","category-script-en","tag-mep-en","tag-revit-api-2015-en","tag-revitpythonshell-en","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=116"}],"version-history":[{"count":3,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/116\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}