Skip to content

gswifort/PyRx

 
 

Repository files navigation

PyRx

Visit us on PyPi

PyRx provides Python bindings for CAD software:

C++ bindings:

  • AutoCAD®: ObjectARX® 2021-2025
  • ZwCAD®: ZRX® 2024-2025
  • GstarCAD®: GRX® 2024-2025
  • BricsCAD®: BRX® v24-v25

ActiveX bindings:

  • AutoCAD®: 2021-2025
  • BricsCAD®: v24-v25
  • GstarCAD®: 2024-2025
  • ZwCAD®: 2024-2025

This project will not work for AutoCAD LT or BricsCAD Lite, check that your CAD can load ARX Modules first. Wherever in this project we talk about AutoCAD, we mean all supported applications (BricsCAD, GstarCAD, ZwCAD), and when we talk about ARX (Object ARX), we also mean BRX, GRX and ZRX.

Uses wxPython for the GUI, dialogs, and CAdUiPalette wrapper. Embeds Python (3.12) and wxPython (4.2.2) into a loadable ARX module.

Installation

Install python 3.12.X (64 bit) with the ❗PATH checkbox❗ set to true:

Python install,

Install PyRx from PyPI:

pip install cad-pyrx

Use APPLOAD command or the startup suite to load PyRx in CAD application, example:

_APPLOAD
%localappdata%\Programs\Python\Python312\Lib\site-packages\pyrx\RxLoaderZ25.0.zrx
or
RxLoader24.0.arx = 2021
RxLoader24.1.arx = 2022
RxLoader24.2.arx = 2023
RxLoader24.3.arx = 2024
RxLoader25.0.arx = 2025

Install PyRx from a tag , e.g. for git tag v2.1.7:

python -m pip install git+https://github.com/CEXT-Dan/[email protected]

Install PyRx from the latest commit:

python -m pip install git+https://github.com/CEXT-Dan/PyRx.git

Uninstall:

python -m pip uninstall cad-pyrx

AutoCAD user may optionally install a .bundle using the MSI installer attached to the release

Downloads

Get the latest build from GitHub Releases.

Commands

When loading the ARX/BRX/GRX/ZRX module, the following commands are added to CAD application:

  • PYLOAD: Use this command to load your Python modules
  • PYRELOAD: Use this command to reload your Python modules
  • PYCMDPROMPT: Provides simple access to the python interpreter
  • PYRXVER: Prints the ARX module version
  • PYRXLOADLOG: Prints the ARX module load logs

Autolisp commands:
(adspyload PATH) returns T or nil
(adspyreload PATH) returns T or nil
(adspyloaded) returns a list of loaded modules

ARX sample

from pyrx import Rx, Ge, Gi, Db, Ap, Ed, Sm
import traceback

 # these four (Optional) functions are called as they would be in ARX
def OnPyInitApp():
    print("\nOnPyInitApp")
    print("\ncommand = pydoit")

def OnPyUnloadApp():
    print("\nOnPyUnloadApp")

def OnPyLoadDwg():
    print("\nOnPyLoadDwg")

def OnPyUnloadDwg():
    print("\nOnPyUnloadDwg")

 # functions that are prefixed with PyRxCmd_ are registered as AutoCAD commands
def PyRxCmd_pydoit():
    try:
        db = Db.HostApplicationServices().workingDatabase()

        # create a line
        line = Db.Line()
        line.setDatabaseDefaults()

        # use Ge point
        line.setStartPoint(Ge.Point3d(0, 0, 0))
        line.setEndPoint(Ge.Point3d(100, 100, 0))

        # set a color
        color = Db.Color()
        color.setRGB(255, 255, 0)
        line.setColor(color)

        # open modelspace for write and add the entity
        model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.ForWrite)
        model.appendAcDbEntity(line)

    except Exception:
        traceback.print_exc()

ActiveX sample

under construction see task [#165]

and many more examples: https://github.com/CEXT-Dan/PyRx/tree/main/PySamples

Features

  • Create GUIs with wxPython, bindings for dialogs and palettes

    wxPython Gui

  • Generated stub files for built in help, autocomplete

    stubs

  • Debugging support with debugpy

    debug

See also

About

Python for AutoCAD

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 82.2%
  • C++ 17.7%
  • Other 0.1%