<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Checking if a layer is empty in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612435#M67656</link>
    <description>I've been meaning to publish some sample code that&lt;BR /&gt;
shows how to use Linq in AutoCAD development, and&lt;BR /&gt;
found that your task was an good problem case for&lt;BR /&gt;
demonstrating how Linq can be used.&lt;BR /&gt;
&lt;BR /&gt;
So I've revised that code to be more 'Linq-oriented', and&lt;BR /&gt;
in the process made it less complicated and more generic.&lt;BR /&gt;
Most of the code is implemented as extension methods&lt;BR /&gt;
that are reusable in a range of similar problems as well.&lt;BR /&gt;
&lt;BR /&gt;
See the updated version just posted if you're interested&lt;BR /&gt;
in seeing how Linq can be leveraged to solve this and a&lt;BR /&gt;
variety of similar problems.&lt;BR /&gt;
&lt;BR /&gt;
Oh and BTW, that code can be used on any database,&lt;BR /&gt;
whether it's open in the editor, or not. With an outboard&lt;BR /&gt;
Database or a Database open in the editor, just call the&lt;BR /&gt;
BlockTableRecord.IsLayerUsed() extension method on the&lt;BR /&gt;
specific BlockTableRecord(s) you're interested in.&lt;BR /&gt;
&lt;BR /&gt;
If you want to be more helpful to users, then not only&lt;BR /&gt;
would you detect whether entities are not on the correct&lt;BR /&gt;
layer. You could also help them to locate those entities&lt;BR /&gt;
too. What you might do is store their ObjectIds in an&lt;BR /&gt;
extension dictionary within the drawing, and also provide&lt;BR /&gt;
another tool that can use that data to select the objects&lt;BR /&gt;
for the user when they later open the file to correct the&lt;BR /&gt;
issues you find.&lt;BR /&gt;
&lt;BR /&gt;
One last point, is that if you're interested in specific&lt;BR /&gt;
information about layer usage within a given block or&lt;BR /&gt;
several blocks, then you shouldn't bother with calling&lt;BR /&gt;
GenerateUsageData() or looking at the IsUsed property,&lt;BR /&gt;
because GenerateUsageData() has to look for references&lt;BR /&gt;
to every layer in the drawing, and may have to look at&lt;BR /&gt;
every single object in the drawing as well, not just the&lt;BR /&gt;
entities in the block you're interested in, and because&lt;BR /&gt;
of that, it could take much longer in very large files, or&lt;BR /&gt;
files with many blocks.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6314708@discussion.autodesk.com...&lt;BR /&gt;
Thanks Tony that helped alot. The entities of the blocks can be on layer 0 but&lt;BR /&gt;
nothing else.&lt;/TIMBLANCH&gt;</description>
    <pubDate>Fri, 08 Jan 2010 10:39:20 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-01-08T10:39:20Z</dc:date>
    <item>
      <title>Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612425#M67646</link>
      <description>What is the best way to check if a layer is empty? &lt;BR /&gt;
Can it be done using a side database?&lt;BR /&gt;
Using C# prefered but I can work with VB.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any and all input,&lt;BR /&gt;
&lt;BR /&gt;
Tim</description>
      <pubDate>Thu, 07 Jan 2010 03:01:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612425#M67646</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-07T03:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612426#M67647</link>
      <description>Try to delete the layer and if an exception is thrown, it means the layer is &lt;BR /&gt;
referenced by something in the drawing.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6313752@discussion.autodesk.com...&lt;BR /&gt;
What is the best way to check if a layer is empty?&lt;BR /&gt;
Can it be done using a side database?&lt;BR /&gt;
Using C# prefered but I can work with VB.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any and all input,&lt;BR /&gt;
&lt;BR /&gt;
Tim&lt;/TIMBLANCH&gt;</description>
      <pubDate>Thu, 07 Jan 2010 12:38:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612426#M67647</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-07T12:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612427#M67648</link>
      <description>Well that one is easy enough! Don't know why I didn't think of that one.&lt;BR /&gt;
Guess I was just thinking that the layer has to stay in the drawing (not sure why) but I can just recreate it if it deletes.&lt;BR /&gt;
Layer "0" has to be in the drawing but nothing can be on it... go figure.&lt;BR /&gt;
&lt;BR /&gt;
Thanks Tony&lt;BR /&gt;
&lt;BR /&gt;
Tim</description>
      <pubDate>Thu, 07 Jan 2010 14:41:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612427#M67648</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-07T14:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612428#M67649</link>
      <description>Things can be on layer '0'.&lt;BR /&gt;
&lt;BR /&gt;
The point is it has a special purpose for block creation.  Nothing else should be on layer 0, because that's just bad drawing organization.&lt;BR /&gt;
&lt;BR /&gt;
Any entity placed on layer 0 in a block definition will assume the layer properties of whatever layer the block reference is placed on. That is, any properties that were not explicitly set to the entity.&lt;BR /&gt;
&lt;BR /&gt;
So, I can create some widget.  Place it on layer 0, color bylayer, linetype bylayer...&lt;BR /&gt;
draw a centerline on it. on Layer 0, color red, linetype centerline...&lt;BR /&gt;
attach some gadget to it (I don't know... a J-Box for wiring maybe)  layer 0, color ByBlock, linetype ByBlock.&lt;BR /&gt;
&lt;BR /&gt;
Now make all that into a block and place several instances on different layers with different color and linetype settings.&lt;BR /&gt;
Then take a couple of the blocks and change the color or linetype of the block itself.&lt;BR /&gt;
&lt;BR /&gt;
The result is:&lt;BR /&gt;
 the centerline will always be color red, linetype centerline in all instances.&lt;BR /&gt;
the widget will always follow the layer settings in all instances&lt;BR /&gt;
the gadget will follow the settings given to the block reference (which can be bylayer making it the same as the widget, or specific color/Ltype, making the widget and the gadget appear differently.</description>
      <pubDate>Thu, 07 Jan 2010 18:39:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612428#M67649</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-01-07T18:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612429#M67650</link>
      <description>No, it will not work for Layer 0.&lt;BR /&gt;
&lt;BR /&gt;
You don't have to recreate the layer if it gets deleted, you just unerase it.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6313984@discussion.autodesk.com...&lt;BR /&gt;
Well that one is easy enough! Don't know why I didn't think of that one.&lt;BR /&gt;
Guess I was just thinking that the layer has to stay in the drawing (not sure &lt;BR /&gt;
why) but I can just recreate it if it deletes.&lt;BR /&gt;
Layer "0" has to be in the drawing but nothing can be on it... go figure.&lt;BR /&gt;
&lt;BR /&gt;
Thanks Tony&lt;BR /&gt;
&lt;BR /&gt;
Tim&lt;/TIMBLANCH&gt;</description>
      <pubDate>Thu, 07 Jan 2010 20:50:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612429#M67650</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-07T20:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612430#M67651</link>
      <description>Thanks for the insight chiefbraincloud, and point well taken.&lt;BR /&gt;
You can't delete layer 0 so I guess I am back to square one again. What I need/want to do is check a bunch of drawings (&amp;gt;5000) to see if there is anything on layer 0 that should not be there. I was spot checking them and I have found 2 that had objects on them, lines and blocks. 2 out of the 30 or so I checked warrants me to check them all. I also need to delete layers that don't belong. There is a layer standard we follow and all layers have to be there and the ones that don't belong should be deleted.&lt;BR /&gt;
I have taken it upon myself to learn how to do this and have most of it written but its an uphill battle with limited documentation on .NET. Maybe if I get good enough or prove the value they will let me sign up for ADN.&lt;BR /&gt;
So could somebody show me how to do this tidbit of code? I would be forever grateful.&lt;BR /&gt;
&lt;BR /&gt;
Tim</description>
      <pubDate>Thu, 07 Jan 2010 20:50:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612430#M67651</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-07T20:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612431#M67652</link>
      <description>neeeevermind, didn't see "won't" in that sentence.

Edited by: ViktorCad on Jan 8, 2010 1:11 AM</description>
      <pubDate>Fri, 08 Jan 2010 01:11:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612431#M67652</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T01:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612432#M67653</link>
      <description>Your problem may actually a bit more complicated than you assume.&lt;BR /&gt;
&lt;BR /&gt;
The first question you need to answer is in your case, whether you want&lt;BR /&gt;
to know if any entity is on a given layer, regardless of where the entity is.&lt;BR /&gt;
&lt;BR /&gt;
IOW, is it acceptable for entities in block definitions to be on layer 0?&lt;BR /&gt;
&lt;BR /&gt;
If the answer is no, you can use the following method to test if a layer&lt;BR /&gt;
is referenced by *any* entity, including entities in any block definition:&lt;BR /&gt;
&lt;BR /&gt;
    1.  Call the LayerTable's GenerateUsageData() method.&lt;BR /&gt;
&lt;BR /&gt;
    2.  Check the IsUsed property of one or more LayerTableRecords.&lt;BR /&gt;
&lt;BR /&gt;
IsUsed is only valid after GenerateUsageData() was called, up to the&lt;BR /&gt;
point where the database is modified.&lt;BR /&gt;
&lt;BR /&gt;
OTOH, if you're only interested in knowing if entities in model and/or&lt;BR /&gt;
paper space reside on a given layer, it becomes more complicated&lt;BR /&gt;
because the IsUsed property cannot tell you that.&lt;BR /&gt;
&lt;BR /&gt;
In that case, have a look at the code here:&lt;BR /&gt;
&lt;BR /&gt;
     http://www.caddzone.com/LayerUtils.cs&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6313984@discussion.autodesk.com...&lt;BR /&gt;
Well that one is easy enough! Don't know why I didn't think of that one.&lt;BR /&gt;
Guess I was just thinking that the layer has to stay in the drawing (not sure &lt;BR /&gt;
why) but I can just recreate it if it deletes.&lt;BR /&gt;
Layer "0" has to be in the drawing but nothing can be on it... go figure.&lt;BR /&gt;
&lt;BR /&gt;
Thanks Tony&lt;BR /&gt;
&lt;BR /&gt;
Tim&lt;/TIMBLANCH&gt;</description>
      <pubDate>Fri, 08 Jan 2010 02:01:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612432#M67653</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T02:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612433#M67654</link>
      <description>Thanks Tony that helped alot. The entities of the blocks can be on layer 0 but nothing else.</description>
      <pubDate>Fri, 08 Jan 2010 03:26:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612433#M67654</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T03:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612434#M67655</link>
      <description>Based on your question in the beginning about the ability to do this as a side database, combined with the fact that you indicated a very large number of drawings needing searched, I worked up an example of how to do it, as a side database.&lt;BR /&gt;
&lt;BR /&gt;
It would be much simpler if you opened the drawings into the editor, because you could use a selection filter to get all entities on layer 0, however, if you tried to do it that way on 5000 drawings it might take about a week.  (depending somewhat on the drawing content)&lt;BR /&gt;
&lt;BR /&gt;
Since you can't use the editor methods on a side database, you have to loop through both the ModelSpace and the PaperSpace opening every entity you find to check it's layer property.  &lt;BR /&gt;
&lt;BR /&gt;
I had a routine for copying block definitions from a side database to the current database, so I hacked up a copy of it (attached) to make a simple text report (In your MyDocuments Folder) of all entities found to be on layer 0 (with one exception, next paragraph).  You pass it a string collection of filenames to process.&lt;BR /&gt;
&lt;BR /&gt;
Tony, If you have any interest, you may note that my code here does not use the IsUsed property of the layer to short circuit the process.  I did try to do that, thinking that at least that way if a drawing is clean, you don't have to loop the whole MS and PS to find out, but I found that it always returned true.  (At first, I was not aware of the need for calling GenerateUsageData first, but even after it still always returned true)  I believe through my limited efforts to test this routine, I determined that the root PaperSpace Viewport (the one that exists even of there are no mview created viewports) is reporting itself on layer 0, therefore IsUsed may work fine for other layers but could never be false for layer 0.&lt;BR /&gt;
&lt;BR /&gt;
Of course this simple text report does you little good, but you would just insert whatever code you desire at the points where I am writing to the report, and there is one more detail which may need some work.  I think if the drawing has multiple layouts there is more work to be done to catch all the paperspaces.  &lt;BR /&gt;
&lt;BR /&gt;
Anyone got any input on that?  I used the SymbolUtilityServices.GetBlockPaperSpaceID(db) method to get the paperspace entities.  Is that a 'Parent' PaperSpace to the multiple 'child' layout PaperSpaces, or will it represent the most recently activated Layout?</description>
      <pubDate>Fri, 08 Jan 2010 04:00:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612434#M67655</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-01-08T04:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612435#M67656</link>
      <description>I've been meaning to publish some sample code that&lt;BR /&gt;
shows how to use Linq in AutoCAD development, and&lt;BR /&gt;
found that your task was an good problem case for&lt;BR /&gt;
demonstrating how Linq can be used.&lt;BR /&gt;
&lt;BR /&gt;
So I've revised that code to be more 'Linq-oriented', and&lt;BR /&gt;
in the process made it less complicated and more generic.&lt;BR /&gt;
Most of the code is implemented as extension methods&lt;BR /&gt;
that are reusable in a range of similar problems as well.&lt;BR /&gt;
&lt;BR /&gt;
See the updated version just posted if you're interested&lt;BR /&gt;
in seeing how Linq can be leveraged to solve this and a&lt;BR /&gt;
variety of similar problems.&lt;BR /&gt;
&lt;BR /&gt;
Oh and BTW, that code can be used on any database,&lt;BR /&gt;
whether it's open in the editor, or not. With an outboard&lt;BR /&gt;
Database or a Database open in the editor, just call the&lt;BR /&gt;
BlockTableRecord.IsLayerUsed() extension method on the&lt;BR /&gt;
specific BlockTableRecord(s) you're interested in.&lt;BR /&gt;
&lt;BR /&gt;
If you want to be more helpful to users, then not only&lt;BR /&gt;
would you detect whether entities are not on the correct&lt;BR /&gt;
layer. You could also help them to locate those entities&lt;BR /&gt;
too. What you might do is store their ObjectIds in an&lt;BR /&gt;
extension dictionary within the drawing, and also provide&lt;BR /&gt;
another tool that can use that data to select the objects&lt;BR /&gt;
for the user when they later open the file to correct the&lt;BR /&gt;
issues you find.&lt;BR /&gt;
&lt;BR /&gt;
One last point, is that if you're interested in specific&lt;BR /&gt;
information about layer usage within a given block or&lt;BR /&gt;
several blocks, then you shouldn't bother with calling&lt;BR /&gt;
GenerateUsageData() or looking at the IsUsed property,&lt;BR /&gt;
because GenerateUsageData() has to look for references&lt;BR /&gt;
to every layer in the drawing, and may have to look at&lt;BR /&gt;
every single object in the drawing as well, not just the&lt;BR /&gt;
entities in the block you're interested in, and because&lt;BR /&gt;
of that, it could take much longer in very large files, or&lt;BR /&gt;
files with many blocks.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6314708@discussion.autodesk.com...&lt;BR /&gt;
Thanks Tony that helped alot. The entities of the blocks can be on layer 0 but&lt;BR /&gt;
nothing else.&lt;/TIMBLANCH&gt;</description>
      <pubDate>Fri, 08 Jan 2010 10:39:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612435#M67656</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T10:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612436#M67657</link>
      <description>I'm not going to get into what's wrong with the chief's endeavor&lt;BR /&gt;
other than to just advise you that it doesn't do what he seems to&lt;BR /&gt;
think it does. It will not find all layer references that can exist,&lt;BR /&gt;
and will leave the outboard database open should an error cause&lt;BR /&gt;
the code to terminate prematurely, which is mainly because the&lt;BR /&gt;
code is badly written (e.g, doesn't use 'Using' where appropriate,&lt;BR /&gt;
nor uses exception/termination handling correctly to ensure the&lt;BR /&gt;
database is disposed if an error stops the code).&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6314708@discussion.autodesk.com...&lt;BR /&gt;
Thanks Tony that helped alot. The entities of the blocks can be on layer 0 but &lt;BR /&gt;
nothing else.&lt;/TIMBLANCH&gt;</description>
      <pubDate>Fri, 08 Jan 2010 11:02:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612436#M67657</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T11:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612437#M67658</link>
      <description>Wow, thanks! It's going to take me a little to digest all this, but great example.&lt;BR /&gt;
One more question, where or what do you use for reference? I mean do you get all this information from the SDK documentation? Is there some other source of documentation available outside of joining ADN (company won't go for that yet)? I read Kean Walmsley's blogs and I have learned quite a bit there but there has to be some sort of reference that lists what all of the classes and methods of the API do.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again,&lt;BR /&gt;
&lt;BR /&gt;
Tim</description>
      <pubDate>Fri, 08 Jan 2010 15:08:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612437#M67658</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T15:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612438#M67659</link>
      <description>That's crap.  It does exactly what I said it does.&lt;BR /&gt;
&lt;BR /&gt;
It will find all &lt;U&gt;Graphical&lt;/U&gt; references to Layer 0 (the specific problem presented) other than my question about multiple layouts.&lt;BR /&gt;
&lt;BR /&gt;
It does use Using as much as is neccessary, and has plenty of exception handling.&lt;BR /&gt;
&lt;BR /&gt;
I missed putting the DB.closeinput and dispose into a finally... sue me.  If it had actually failed once I would have caught that.&lt;BR /&gt;
&lt;BR /&gt;
And for Tim's benefit I'll mention that in the process of trying to figure out what was up with the viewports I accidentally made it only report the viewports from paperspace, so needs an Else in the If.</description>
      <pubDate>Fri, 08 Jan 2010 18:45:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612438#M67659</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2010-01-08T18:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612439#M67660</link>
      <description>No it doesn't do what you think, and you're not&lt;BR /&gt;
worthy of a debate about it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
over and out&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;CHIEFBRAINCLOUD&gt; wrote in message news:6315127@discussion.autodesk.com...&lt;BR /&gt;
That's crap.  It does exactly what I said it does.&lt;BR /&gt;
&lt;BR /&gt;
It will find all &lt;U&gt;Graphical&lt;/U&gt; references to Layer 0 (the specific problem &lt;BR /&gt;
presented) other than my question about multiple layouts.&lt;BR /&gt;
&lt;BR /&gt;
It does use Using as much as is neccessary, and has plenty of exception &lt;BR /&gt;
handling.&lt;BR /&gt;
&lt;BR /&gt;
I missed putting the DB.closeinput and dispose into a finally... sue me.  If it &lt;BR /&gt;
had actually failed once I would have caught that.&lt;BR /&gt;
&lt;BR /&gt;
And for Tim's benefit I'll mention that in the process of trying to figure out &lt;BR /&gt;
what was up with the viewports I accidentally made it only report the viewports &lt;BR /&gt;
from paperspace, so needs an Else in the If.&lt;/CHIEFBRAINCLOUD&gt;</description>
      <pubDate>Fri, 08 Jan 2010 21:32:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612439#M67660</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-08T21:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612440#M67661</link>
      <description>Aside from the docs that come with the SDK, there are some online docs that &lt;BR /&gt;
include basic code samples for common tasks.  The links to them can be found on &lt;BR /&gt;
the same page where you download the SDK.&lt;BR /&gt;
&lt;BR /&gt;
My own experience is rooted in native ObjectARX, and has been very helpful in &lt;BR /&gt;
unraveling the managed API.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;TIMBLANCH&gt; wrote in message news:6314899@discussion.autodesk.com...&lt;BR /&gt;
Wow, thanks! It's going to take me a little to digest all this, but great &lt;BR /&gt;
example.&lt;BR /&gt;
One more question, where or what do you use for reference? I mean do you get all &lt;BR /&gt;
this information from the SDK documentation? Is there some other source of &lt;BR /&gt;
documentation available outside of joining ADN (company won't go for that yet)? &lt;BR /&gt;
I read Kean Walmsley's blogs and I have learned quite a bit there but there has &lt;BR /&gt;
to be some sort of reference that lists what all of the classes and methods of &lt;BR /&gt;
the API do.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again,&lt;BR /&gt;
&lt;BR /&gt;
Tim&lt;/TIMBLANCH&gt;</description>
      <pubDate>Mon, 11 Jan 2010 09:27:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612440#M67661</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-11T09:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a layer is empty</title>
      <link>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612441#M67662</link>
      <description>Maybe this?&lt;BR /&gt;
&lt;BR /&gt;
Public Shared Function LayerIsEmpty(ByVal layerName As String) As Boolean&lt;BR /&gt;
   Dim db As acaDb.Database = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database&lt;BR /&gt;
   Using tr As acaDb.Transaction = db.TransactionManager.StartTransaction&lt;BR /&gt;
      Dim tbl As acaDb.LayerTable = tr.GetObject(db.LayerTableId, &lt;BR /&gt;
acaDb.OpenMode.ForRead)&lt;BR /&gt;
      If tbl.Has(layerName) Then&lt;BR /&gt;
         Dim ltr As acaDb.LayerTableRecord = &lt;BR /&gt;
tr.GetObject(tbl.Item(layerName), acaDb.OpenMode.ForRead)&lt;BR /&gt;
         Dim ids As New acaDb.ObjectIdCollection&lt;BR /&gt;
         ids.Add(ltr.ObjectId)&lt;BR /&gt;
         db.Purge(ids)&lt;BR /&gt;
         If ids.Count &amp;gt; 0 Then&lt;BR /&gt;
            Return True&lt;BR /&gt;
         End If&lt;BR /&gt;
      End If&lt;BR /&gt;
   End Using&lt;BR /&gt;
   Return False&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
tp&lt;BR /&gt;
&lt;BR /&gt;
"TimBlanch" escreveu na mensagem news:6313752@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt; What is the best way to check if a layer is empty?&lt;BR /&gt;
&amp;gt; Can it be done using a side database?&lt;BR /&gt;
&amp;gt; Using C# prefered but I can work with VB.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Thanks for any and all input,&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Tim</description>
      <pubDate>Thu, 25 Feb 2010 13:17:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/checking-if-a-layer-is-empty/m-p/2612441#M67662</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-25T13:17:55Z</dc:date>
    </item>
  </channel>
</rss>

