Skip to content
Discussion options

You must be logged in to vote

Hi, Ap.curDoc() or Db.workingDb() should be in context during that event.
Db.workingDb() should be slightly safer, I always just use curDoc

consider that document to be null after the OnPyUnloadDwg exits, and workingDb will be in a new context

import traceback
from pyrx import Ap, Db, Ed, Ge


def OnPyLoadDwg():
    Ap.curDoc().fileName()

    # or safer because workingDb is never null
    dm = Ap.DocManager()
    doc = dm.document(Db.workingDb())


def OnPyUnloadDwg():
    Ap.curDoc().fileName()

    # or safer because workingDb is never null
    dm = Ap.DocManager()
    doc = dm.document(Db.workingDb())


@Ap.Command(Ap.CmdFlags.SESSION)
def doit():
    try:
        # exec from Drawing1
…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gswifort
Comment options

gswifort Nov 6, 2026
Collaborator Author

Answer selected by gswifort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants