TheSwamp

Code Red => .NET => Topic started by: dugk on February 05, 2010, 10:53:16 AM

Title: Hatch on Layer 0 prevents a layer from being purged???
Post by: dugk 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!
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: Slim© 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.
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: dugk 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.
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: Slim© 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.
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: T.Willey 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 . "")
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: dugk 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.
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: Glenn R 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();
            }
        }
Title: Re: Hatch on Layer 0 prevents a layer from being purged???
Post by: Glenn R 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();
    }
}