eLockViolation exception when creating table from context command #97
-
Hi, I am receiving an exception when trying to add agenerated table to the model, but only when executed from a context menu. The command works as expected when it is run in the command line and the table is added. However, I am running the PyRxCmd_ function through a context menu command, and it does run the function and prints the expected table data in the console, but when it comes time to creating the table, it fails with the below exception
The offending code is: db = Db.curDb()
[...]
model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.ForWrite)
model.appendAcDbEntity(table) Why does the command line execution of the same function work but context menu execution does not? I have a feeling it has to do with the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Try this: lock = Ap.AutoDocLock() # !!!
table = ...
db.addToModelspace(table)
del(table)
del(lock) |
Beta Was this translation helpful? Give feedback.
-
It’s application (session) vs command context If you’re not running the code from a command, i.e. from a modeless dialog or a menu, its more than likely that you’re in an application context. See AcApDocManager::lockDocument As a side note, the default command (PyRxCmd_) is MODAL, however, you may create commands that work in a session context, see, testCmdFlags.py also lock = Ap.AutoDocLock() is short for doc = Ap.curDoc()
docman = Ap.DocManager()
docman.lockDocument(doc)
#work on the database
docman.unlockDocument(doc) |
Beta Was this translation helpful? Give feedback.
@CEXT-Dan will probably explain better why it works this way.