Retrieving BlockTableRecord id

Retrieving BlockTableRecord id

Anonymous
Not applicable
645 Views
1 Reply
Message 1 of 2

Retrieving BlockTableRecord id

Anonymous
Not applicable

Hey all - I'm trying to retrieve a BlockTableRecord using the transaction.GetObject() method, but the current implementation throws an exception. Here it is: 

BlockTableRecord destBTR = trans0.GetObject(destBT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

Does anyone have advice on a better way of getting this object? Thanks.

0 Likes
646 Views
1 Reply
Reply (1)
Message 2 of 2

arcticad
Advisor
Advisor
        internal List<ObjectId> GetModelSpace()
        {

            // return list of handles
            List<ObjectId> rtnValue = new List<ObjectId>();
            // Get the current document and database

            Document dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acDb = dwg.Database;

            // Start a transaction
            using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
            {
                using (DocumentLock @Anonymous = dwg.LockDocument())
                {
                    // Open the Block table for read
                    BlockTable acBlkTbl = (BlockTable)acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead);

                    // Open the Block table record Model space for read
                    BlockTableRecord acBlkTblRec = default(BlockTableRecord);
                    acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                    foreach (ObjectId objId in acBlkTblRec)
                    {
                        //check if this ObjectID is valid within the database
                        if ((objId.IsValid) && (!objId.IsErased))
                            rtnValue.Add(objId);
                    }
                    acTrans.Commit();
                }
            }
            return rtnValue;
        }
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes