Author Topic: Dyn Block in selection set after vis change  (Read 2430 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4073
Dyn Block in selection set after vis change
« 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?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

gile

  • Gator
  • Posts: 2505
  • Marseille, France
Re: Dyn Block in selection set after vis change
« Reply #1 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);
            }
        }
Speaking English as a French Frog

Draftek

  • Guest
Re: Dyn Block in selection set after vis change
« Reply #2 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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4073
Re: Dyn Block in selection set after vis change
« Reply #3 on: February 06, 2012, 05:33:09 PM »
Thanks Gile, I will give this a try tomorrow
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)