Author Topic: Hatch on Layer 0 prevents a layer from being purged???  (Read 2081 times)

0 Members and 1 Guest are viewing this topic.

dugk

  • Guest
Hatch on Layer 0 prevents a layer from being purged???
« on: February 05, 2010, 10:53:16 AM »
I've got a drawing (attached) that has one hatch and one polyline.  Both are on layer 0.  But there are two layers in the drawing, 0 and MHIDUCT.

There should only be one layer, 0 (zero), but the hatch somehow is associated to the MHIDUCT layer.  If I explode the hatch or erase it and replace it with a solid, the layer MHIDUCT can be purged.

So far I know this is not a .NET question but I'm trying to write C# code to find out how the layer MHIDUCT is associated with this hatch and change it.

Thanks for you ideas and suggestions!

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #1 on: February 05, 2010, 11:00:55 AM »
Your "hatch" is an anonymous block, with the "name" *XO. That's why when you explode it and purge the extra layer goes away. Just delete it and rehatch.
I drink beer and I know things....

dugk

  • Guest
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #2 on: February 05, 2010, 11:04:03 AM »
I'm trying to write C# code to find out how the layer MHIDUCT is associated with this hatch and change it.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #3 on: February 05, 2010, 11:07:18 AM »
As I said the "hatch" in your drawing is a block that is made up of lines as well as including the layer information you wish to be rid of.

You might want to check your block editing functions within your program.
I drink beer and I know things....

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #4 on: February 05, 2010, 12:05:24 PM »
It seems that the block was created while the current layer was ' MHIDUCT ', so it got associated with the block definition.  It seems like it is associated with the ' BlockBegin ' object ( which is what is is called in .Net ).  Here is the dxf code, printed from lisp to the command line, to show what I'm talking about.

Code: [Select]
(-1 . <Entity name: 7ddea048>)
(0 . "BLOCK")
(330 . <Entity name: 7ddea040>)
(5 . "89")
(100 . "AcDbEntity")
(67 . 0)
(8 . "MHIDUCT")
(100 . "AcDbBlockBegin")
(70 . 1)
(10 0.0 0.0 0.0)
(-2 . <Entity name: 7ddea058>)
(2 . "*X0")
(1 . "")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

dugk

  • Guest
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #5 on: February 05, 2010, 12:10:13 PM »
Great thinking!  I didn't think to go that Old-Skool on it.  Just what I was looking for as a reason.

Now to write some code to change it.

Glenn R

  • Guest
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #6 on: February 06, 2010, 01:53:05 PM »
I was waiting until I returned home to post about BLOCK_BEGIN but I see Tim beat me to it. This is a typical culprit when a layer will not purge.

Some code to ponder:
Code: [Select]
// Modal Command with localized name
        [CommandMethod("TCGS", "ListBlockHeaders", "ListBlockHeadersLocal", CommandFlags.Modal)]
        public void ListBlockHeadersCommand()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;

                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead, false) as BlockTableRecord;
                    BlockBegin btrBegin = tr.GetObject(btr.BlockBeginId, OpenMode.ForRead, false) as BlockBegin;
                    BlockEnd btrEnd = tr.GetObject(btr.BlockEndId, OpenMode.ForRead, false) as BlockEnd;

                    ed.WriteMessage("{0}Block name: {1}{0}\tBlockBegin Layer: {2}{0}\tBlockEnd Layer: {3}",
                                    Environment.NewLine, btr.Name, btrBegin.Layer, btrEnd.Layer);
                }

                tr.Commit();
            }
        }

Glenn R

  • Guest
Re: Hatch on Layer 0 prevents a layer from being purged???
« Reply #7 on: February 06, 2010, 02:08:32 PM »
If you want to change the layer:

Code: [Select]
// Modal Command with localized name
[CommandMethod("TCGS", "ListBlockHeaders", "ListBlockHeadersLocal", CommandFlags.Modal)]
public void ListBlockHeadersCommand()
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    using (Transaction tr = doc.TransactionManager.StartTransaction())
    {
        BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;

        foreach (ObjectId btrId in bt)
        {
            BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead, false) as BlockTableRecord;
            BlockBegin btrBegin = tr.GetObject(btr.BlockBeginId, OpenMode.ForRead, false) as BlockBegin;
            BlockEnd btrEnd = tr.GetObject(btr.BlockEndId, OpenMode.ForRead, false) as BlockEnd;

            ed.WriteMessage("{0}Block name: {1}{0}\tBlockBegin Layer: {2}{0}\tBlockEnd Layer: {3}",
                            Environment.NewLine, btr.Name, btrBegin.Layer, btrEnd.Layer);

            if (btrBegin.LayerId != db.LayerZero)
            {
                btrBegin.UpgradeOpen();
                btrBegin.LayerId = db.LayerZero;
            }

            if (btrEnd.LayerId != db.LayerZero)
            {
                btrEnd.UpgradeOpen();
                btrEnd.LayerId = db.LayerZero;
            }
        }

        tr.Commit();
    }
}