Repository navigation
|
When registering the |
Answered by
CEXT-Dan
Nov 6, 2026
Replies: 1 comment 1 reply
|
Hi, consider that document to be null after the 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
dm = Ap.DocManager()
# should be Drawing1, and can be different than curDoc
dm.mdiActiveDocument().fileName()
dm = Ap.DocManager()
for doc in dm.documents():
if "Drawing3" in doc.fileName():
print(doc.fileName())
dm.closeDocument(doc)
except Exception:
print(traceback.format_exc()) |
1 reply
Answer selected by
gswifort
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Ap.curDoc()orDb.workingDb()should be in context during that event.Db.workingDb()should be slightly safer, I always just usecurDocconsider that document to be null after the
OnPyUnloadDwgexits, andworkingDbwill be in a new context