<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" width="40px" /> CPython engine is under active development and might be unstable. If you want to use python for development, it is preferred to use IronPython. CPython should only be used when accessing C-based python packages (e.g. numpy, scipy) is necessary.

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/01f9b8a6-3c36-442b-bed3-ec193007d66f/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/01f9b8a6-3c36-442b-bed3-ec193007d66f/ic_01_idea.png" width="40px" /> Start with the short introduction to scripts at Create Your First Command and Create Your First CPython Command

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/844cd1c9-d253-44c5-9200-dc026df980f5/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/844cd1c9-d253-44c5-9200-dc026df980f5/ic_01_idea.png" width="40px" /> See Python Script Facilities for information about the script support module

</aside>

Language Safe Code


CPython scripts are always read using UTF-8 encoding. There is no need to provide the # -*- coding: utf-8 -*- directive

Shipped Packages


Packages listed here are shipped with pyRevit by default for convenience

Implement Revit API's .NET Interfaces with CPython and pythonnet


RE https://github.com/pyrevitlabs/pyRevit/issues/686

If you want to use CPython and pythonnet to implement any Revit API's .NET interface (for example: Autodesk.Revit.DB.ISelectionFilter in order to use with Autodesk.Revit.UI.Selection.PickObject), you must specify __namespace__ attribute on the derived class

Additionally, your __namespace__ must be different each time you run your script, otherwise you will get an exception as shown below Source Implement a C# Interface in Python for .NET

CPython Traceback:
TypeError : Duplicate type name within an assembly.

You can use the pyRevit execution id for this purpose since it is unique for every execution.

from pyrevit import EXEC_PARAMS

class CategoriesFilter(Selection.ISelectionFilter):
    __namespace__ = EXEC_PARAMS.exec_id

    def __init__(self, names):
        self.names = names

    def AllowElement(self, element):
        return element.Category.Name in self.names

    def AllowReference(self, refer, point):
        return False