Results 1 to 7 of 7

Thread: puzzled! eWasOpenForWrite error

  1. #1
    Member
    Join Date
    2012-09
    Posts
    2
    Login to Give a bone
    0

    Default puzzled! eWasOpenForWrite error

    hello,everybody!
    I get a error 'eWasOpenForWrite' in the code below, can anyone tell me how to tackle this problem?
    thanks.

    Code:
            private static void CheckInference(List<Solid3d> solids) {
                Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
                using (Transaction tran = db.TransactionManager.StartTransaction()) {
                    BlockTable blockTable = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord blockRecord = tran.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
    
                    for (int i = 0; i < solids.Count - 1; i++) {
                        Solid3d solid1 = solids[i];
                        for (int j = i + 1; j < solids.Count; j++) {
                            Solid3d solid2 = solids[j];
                            if (solid1.Layer != solid2.Layer) {
                                if (solid1.CheckInterference(solid2)) {
                                    Solid3d copySolid1 = solid1.Clone() as Solid3d;
                                    copySolid1 .BooleanOperation(BooleanOperationType.BoolIntersect, solid2.Clone() as Solid3d);//------eWasOpenForWrite error occured here
                                    copySolid1 .ColorIndex = 1;
                                    blockRecord.AppendEntity(copySolid1 );
                                    tran.AddNewlyCreatedDBObject(copySolid1 , true);
                                    tran.Commit();
                                }
                            }
                        }
                    }
                }
            }
    Last edited by 289924688488291; 2012-09-11 at 07:39 AM.

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    Welcome to AUGI!

    First, I do not understand why you choose to iterate a valid selection set based in the layers supplied, only to check for solids, when you could simply include the solid as part of your filter.

    Second, if I am understanding your code correctly, you recursively call CheckInterference() on an ObjectId that you've already opened using the Transaction, hence the eWasOpenForWrite error. Just a guess.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2012-09
    Posts
    2
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    thanks , RenderMan.
    but if not call the function CheckInterference() recursively ,how can i get the Intersection of any two solids in the list?
    any idea?

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    Quote Originally Posted by 289924688488291 View Post
    but if not call the function CheckInterference() recursively ,how can i get the Intersection of any two solids in the list?
    any idea?
    Actually, I am mistaken... I accidentally misread your CheckInference() Method, and thought you were calling it recursively (when in fact you're calling the CheckInterference() Method... Presumably, the solid2 Object being open for write, should not in fact be an issue.

    I've never actually needed to code something like this, so I'm not exactly sure what would be best here... This article, and the comments posted below it, may be of use.

    Hopefully someone more knowledgeable will be along shortly.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    Per the Edit 3D Solid (.NET) Reference... Consider replacing this line:

    Code:
                        if (solid1.CheckInterference(solid2))
    ... With this, and see if that helps:

    Code:
                        if (solid1.CheckInterference(solid2) == true)
    Unless I am overlooking something, this is the only real difference I see between the example found in the documentation, and your code.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Woo! Hoo! my 1st post
    Join Date
    2011-07
    Posts
    1
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    If you clone an entity, you must AppendEntity to Block Table Record and AddNewlyCreatedDBOjbect to a Transaction and only then you can use them for other operations.

  7. #7
    Member
    Join Date
    2023-08
    Location
    London
    Posts
    3
    Login to Give a bone
    0

    Default Re: puzzled! eWasOpenForWrite error

    Hi,

    The error you mentioned, "eWasOpenForWrite," usually occurs in AutoCAD or similar CAD software environments when working with entities, cloning them, and manipulating them through their APIs.

    Here's a general solution outline for the error:

    Clone the Entity: Clone the entity you wish to work with.

    Append to Block Table Record: After cloning, append the entity to the appropriate block table record (such as the current space or a specific block definition).

    Add to Transaction: You must add the newly created object to the current transaction. This allows you to operate on it and have the changes committed or rolled back as part of the transaction.

    Perform Other Operations: Once you've done these things, you can use the cloned entity for other operations without encountering the "eWasOpenForWrite" error.

    Here's a code snippet that might demonstrate these concepts, typically used within AutoCAD development:

    CSharp

    using (Transaction transaction = database.TransactionManager.StartTransaction())
    {
    // Open the block table
    BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

    // Open the block table record for write
    BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

    // Clone the entity (assuming 'entityToClone' is already defined)
    Entity clonedEntity = entityToClone.Clone() as Entity;

    // Append the cloned entity to the block table record
    blockTableRecord.AppendEntity(clonedEntity);

    // Add the newly created object to the transaction
    transaction.AddNewlyCreatedDBObject(clonedEntity, true);

    // Commit the transaction
    transaction.Commit();
    }


    Note: Ensure you've appropriately handled and defined the variables within your specific context, like the entityToClone, which needs to be the entity you are trying to clone.

    This pattern ensures that the cloned entity is correctly associated with the database, and the changes will be part of the transaction, avoiding the "eWasOpenForWrite" error. Source
    Last edited by Ed Jobe; 2023-08-14 at 02:17 PM. Reason: removed hyperlink

Similar Threads

  1. eWasOpenForWrite
    By cadprog in forum Dot Net API
    Replies: 3
    Last Post: 2012-04-10, 08:51 AM
  2. Replies: 7
    Last Post: 2009-05-26, 04:51 PM
  3. eWasOpenForWrite
    By cristiandabu in forum Dot Net API
    Replies: 1
    Last Post: 2009-01-21, 08:11 PM
  4. Puzzled roof (warpped)
    By david_peterson in forum ACA General
    Replies: 10
    Last Post: 2008-02-29, 01:12 PM
  5. Puzzled by mpedit?
    By ddempsie in forum AutoCAD General
    Replies: 2
    Last Post: 2007-11-12, 01:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •