/// <summary> /// Opens a DBObject for write. /// </summary> /// <param name="doc">Document where the object is being found.</param> /// <param name="dbObject">Object to open for write.</param> /// <exception cref="WriteEnablerException"/> /// <exception cref="Autodesk.AutoCAD.Runtime.Exception"/> public WriteEnabler(Document doc, DBObject dbObject) { if (doc != null) { _document = doc; if (dbObject != null) { _db_object = dbObject; // Make write enabled if it's not enabled yet. if (!dbObject.IsWriteEnabled) { try { DocumentLockMode lock_mode = doc.LockMode(); if (lock_mode == DocumentLockMode.Write || lock_mode == DocumentLockMode.ExclusiveWrite) { // is the object an entity? // if yes, unlock layer. if (dbObject is Entity entity) { UnlockLayer(entity.LayerId); } // make object writable _db_object.UpgradeOpen(); _is_upgraded = true; } else { string err_message = "\nDocument is not locked, object cannot be opened for write."; throw new WriteEnablerException(err_message); } } catch (Exception) { throw; } } } else { throw new Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.NullObjectPointer, "DBObject is Null"); } } else { throw new Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.NoDocument, "No active document."); } }
/// <summary> /// Stars the locked transaction. /// </summary> /// <param name="tm">The tm.</param> /// <param name="lockMode">The lock mode.</param> /// <param name="globalCommandName">Name of the global command.</param> /// <param name="localCommandName">Name of the local command.</param> /// <param name="promptIfFails">if set to <c>true</c> [prompt if fails].</param> /// <returns></returns> public static Runtime.LockedTransaction StartLockedTransaction(this TransactionManager tm, DocumentLockMode lockMode, string globalCommandName, string localCommandName, bool promptIfFails) { DocumentLock doclock = Application.DocumentManager.MdiActiveDocument.LockDocument(lockMode, globalCommandName, localCommandName, promptIfFails); return new Runtime.LockedTransaction(tm.StartTransaction(), doclock); }
/// <summary> /// Stars the locked transaction. /// </summary> /// <param name="tm">The tm.</param> /// <param name="lockMode">The lock mode.</param> /// <param name="globalCommandName">Name of the global command.</param> /// <param name="localCommandName">Name of the local command.</param> /// <param name="promptIfFails">if set to <c>true</c> [prompt if fails].</param> /// <returns></returns> public static Runtime.LockedTransaction StartLockedTransaction(this TransactionManager tm, DocumentLockMode lockMode, string globalCommandName, string localCommandName, bool promptIfFails) { DocumentLock doclock = Application.DocumentManager.MdiActiveDocument.LockDocument(lockMode, globalCommandName, localCommandName, promptIfFails); return(new Runtime.LockedTransaction(tm.StartTransaction(), doclock)); }