TheSwamp

Code Red => .NET => Topic started by: David Hall on February 06, 2012, 01:02:37 PM

Title: Dyn Block in selection set after vis change
Post by: David Hall on February 06, 2012, 01:02:37 PM
I have a very weird problem that maybe someone can shed some light on.  If I insert a dynamic block, and leave the visability alone on insert, I can use .Net to grab the block by name.  If I change the visability, the program will not grab the block anymore.  The block still has the same same.  If i change the vis back, the program will grab it again.  Any ideas?
Title: Re: Dyn Block in selection set after vis change
Post by: gile on February 06, 2012, 01:16:31 PM
Hi,

Try this:
Code: [Select]
        public ObjectIdCollection GetBlockReferenceByName(string blkName, Database db)
        {
            ObjectIdCollection result = new ObjectIdCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (!bt.Has(blkName))
                    return null;
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[blkName], OpenMode.ForRead);
                GetRefs(btr, ref result);
                foreach (ObjectId anonId in btr.GetAnonymousBlockIds())
                {
                    BlockTableRecord anonBtr = (BlockTableRecord)tr.GetObject(anonId, OpenMode.ForRead);
                    GetRefs(anonBtr, ref result);
                }
            }
            return result;
        }

        private void GetRefs(BlockTableRecord btr, ref ObjectIdCollection ids)
        {
            foreach (ObjectId id in btr.GetBlockReferenceIds(true, false))
            {
                BlockReference br = (BlockReference)id.GetObject(OpenMode.ForRead);
                BlockTableRecord owner = (BlockTableRecord)br.OwnerId.GetObject(OpenMode.ForRead);
                if (owner.IsLayout)
                    ids.Add(br.Id);
            }
        }
Title: Re: Dyn Block in selection set after vis change
Post by: Draftek on February 06, 2012, 03:38:06 PM
I just had a similar problem where I'm inserting a dynamic block, making some modifications to the custom properties and then trying to explode to just get the linework.

Apparently once any modifications are made there is an anonymous block definition created that is used via some dictionaries in addition to the original dynamic block table record. In my case, once the changes were made to my block the objectId was pointing to the original definition on explode and none of the parameters were drawn modified with the new dimensions. If I left the block unexploded it was fine.

I finally figured the ObjectId was not correct.
So, I wound up silently selecting the block again at the insertion point so I could get the updated ObjectId and then exploding it.

Maybe not the best solution but it works.
Title: Re: Dyn Block in selection set after vis change
Post by: David Hall on February 06, 2012, 05:33:09 PM
Thanks Gile, I will give this a try tomorrow