Replies: 6 comments 31 replies
-
Absolutely not! This is the way .NET works and I don’t like it. |
Beta Was this translation helpful? Give feedback.
-
I don't understand this document I've created four functions that could represent the path to deleting an object from the database - none of them work. Please help. from pyrx import Db, Ge, command
from pyrx.ed.prompt import get_string
def create_line_db():
db = Db.curDb()
line = Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(10, 10, 0))
return db.addObject(line)
def create_line_msp():
db = Db.curDb()
line = Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(10, 10, 0))
return db.addToModelspace(line)
@command
def doit3():
db = Db.curDb()
line_id = create_line_db()
tmr = db.transactionManager()
tr = tmr.startTransaction()
line_tr_obj = tr.getObject(line_id)
line_tr_ent = Db.Entity.cast(line_tr_obj)
db.addToModelspace(line_tr_ent)
print(line_tr_ent.id().handle())
tmr.abortTransaction()
@command
def doit4():
db = Db.curDb()
line_id = create_line_msp()
tmr = db.transactionManager()
tr = tmr.startTransaction()
line_tr_obj = tr.getObject(line_id)
print(line_tr_obj.id().handle())
tmr.abortTransaction()
@command
def doit5():
db = Db.curDb()
line_id = create_line_db()
tmr = db.transactionManager()
tr = tmr.startTransaction()
line_tr_obj = tmr.getObject(line_id)
line_tr_ent = Db.Entity.cast(line_tr_obj)
db.addToModelspace(line_tr_ent)
print(line_tr_ent.id().handle())
tmr.abortTransaction()
@command
def doit6():
db = Db.curDb()
line_id = create_line_msp()
tmr = db.transactionManager()
tr = tmr.startTransaction()
line_tr_obj = tmr.getObject(line_id)
print(line_tr_obj.id().handle())
tmr.abortTransaction()
@command
def doit7():
db = Db.curDb()
obj_id = db.getObjectId(False, Db.Handle(get_string("Enter handle: ")))
obj = Db.DbObject(obj_id)
print(obj.isA().dxfName(), obj.isErased()) |
Beta Was this translation helpful? Give feedback.
-
PyRx does not have a |
Beta Was this translation helpful? Give feedback.
-
As a side note, I’ve seen ARX samples where people call AcDbObject::cancel if some previous operation fails. It’s probably not a good idea to mix transactions and cancel. it maybe that cancel is more lightweight for undoing single operations |
Beta Was this translation helpful? Give feedback.
-
For documentation purposes: @command
def doit9():
db = Db.curDb()
tmr = db.transactionManager()
tmr.startTransaction()
line = Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(10, 10, 0))
line_id = db.addToModelspace(line)
print(line_id.handle())
tmr.abortTransaction() # The line was NOT deleted from the database
# because it was created during the transaction but was NOT CLOSED before UNDO
@command
def doit10():
db = Db.curDb()
tmr = db.transactionManager()
tmr.startTransaction()
line = Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(10, 10, 0))
line_id = db.addToModelspace(line)
line.close() # ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ←
print(line_id.handle())
tmr.abortTransaction() # The line was deleted from the database
# because it was created during a transaction and was CLOSED before UNDO |
Beta Was this translation helpful? Give feedback.
-
Side note (applicable to transactions, but also to opening and closing operations): def line_generator():
db = Db.curDb()
i = 0
while True:
line = Db.Line(Ge.Point3d(i, 0, 0), Ge.Point3d(i + 1, 1, 0))
line_id = db.addToModelspace(line)
# line.close() # !!!
yield line_id
i += 1
@command
def doit11():
db = Db.curDb()
gen = line_generator()
l1 = next(gen)
l2 = next(gen)
Db.Line(l2, Db.OpenMode.kForWrite) # raises ``eWasOpenForWrite`` if it was not closed in the generator |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm wondering if the
@command
decorator should always create a new transaction and abort it if the command fails. This would ensure thatDb.TransactionManager.topTransaction()
returns a non-null object. Theget_block_reference
function needs to add the object to the database, so it would probably be a good idea to add it to the current transaction.Beta Was this translation helpful? Give feedback.
All reactions