I've been meaning to publish some sample code that
shows how to use Linq in AutoCAD development, and
found that your task was an good problem case for
demonstrating how Linq can be used.
So I've revised that code to be more 'Linq-oriented', and
in the process made it less complicated and more generic.
Most of the code is implemented as extension methods
that are reusable in a range of similar problems as well.
See the updated version just posted if you're interested
in seeing how Linq can be leveraged to solve this and a
variety of similar problems.
Oh and BTW, that code can be used on any database,
whether it's open in the editor, or not. With an outboard
Database or a Database open in the editor, just call the
BlockTableRecord.IsLayerUsed() extension method on the
specific BlockTableRecord(s) you're interested in.
If you want to be more helpful to users, then not only
would you detect whether entities are not on the correct
layer. You could also help them to locate those entities
too. What you might do is store their ObjectIds in an
extension dictionary within the drawing, and also provide
another tool that can use that data to select the objects
for the user when they later open the file to correct the
issues you find.
One last point, is that if you're interested in specific
information about layer usage within a given block or
several blocks, then you shouldn't bother with calling
GenerateUsageData() or looking at the IsUsed property,
because GenerateUsageData() has to look for references
to every layer in the drawing, and may have to look at
every single object in the drawing as well, not just the
entities in the block you're interested in, and because
of that, it could take much longer in very large files, or
files with many blocks.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:[email protected]...
Thanks Tony that helped alot. The entities of the blocks can be on layer 0 but
nothing else.