PDA

View Full Version : Extracting Block Information



james.marchant
2008-12-02, 10:30 AM
Hi all,

I'm working on a .NET C# Windows app for automatically indexing drawings, I need to extract titles and drawing numbers from blocks on drawings. (our drawings have been built with templates which contain meaningful blocks).

Doesn't anyone have a headstart on this before I spend days getting my head round the API?

Much appreciated.

James.

T.Willey
2008-12-02, 05:47 PM
I have only worked with .Net within Acad, so I'm not sure how to connect and that stuff from windows, but once you get into the drawing you search the BlockTable to see if the blocks exists in the drawing, and once you know they do, the BlockTableRecord has a method to get all the inserted blocks ( BlockReference ), GetBlockReferenceIds. Once you get that, then you can get the AttributeCollection from the BlockReference, and get all the information you need.

joelkarr
2008-12-15, 11:36 PM
Kean Wamsley gives some good insight on working with blocks here

http://through-the-interface.typepad.com/through_the_interface/blocks/

I believe there is a way to use possibly RealDWG or a different way to access block information without opening the actual drawing.

Other than that....here is a way to start autocad and open a drawing from an outside program

Autodesk.AutoCAD.Interop.AcadApplication acadApplication = new Autodesk.AutoCAD.Interop.AcadApplication;
acadDrawing = acadApplication.Documents.Open(<pathname>, true, paramMissing);
acadApplication.ActiveDocument.SendCommand(<command>);

Make sure you also close your drawings and kill the application when you are done or you will get some dreaded HRResult error

if (acadDrawing != null)
{

acadDrawing.Close(false, paramMissing);
acadDrawing = null;
}


Process[] aCAD = Process.GetProcessesByName("acad");

foreach (Process aCADPro in aCAD)
{
aCADPro.CloseMainWindow();
}



make sure you reference acdbmgd.dll and acmgd.dll from your AutoCAD root folder

sinc
2008-12-16, 08:56 PM
To open a file and access the block table, use the Database.ReadDwgFile() method.

Kerry Brown
2008-12-17, 01:51 AM
AutoCAD 2007,2008,2009 folders contain a AcDx.dll
which contains the namespace Autodesk.AutoCAD.DataExtraction

.. that may be of use.