开发者

How to get label name in Autocad file using C#

开发者 https://www.devze.com 2023-03-28 09:07 出处:网络
I think it is simple 开发者_开发百科to do this but i dont know how to start? I want to get layer name or label name in the autocad file using c#. I search the forums but i really find anything valuabl

I think it is simple 开发者_开发百科to do this but i dont know how to start? I want to get layer name or label name in the autocad file using c#. I search the forums but i really find anything valuable. I found the ObjectARX and AutoLisp, but i dont find any tutorial about theese API's. So, i want to simple example about the reach autocad file.


If you downloaded the ObjectARX SDK from the official site it contains many sample projects to get you started. You will need to have some AutoCAD knowledge to understand the structure of the .dwg database as exposed by the API. Be prepared to invest significant time in the project.

If you just are looking for a simple one time dump of the data in a .dwg file ask your local drafter as there is a command in the AutoCAD UI for doing this known as the Data Extraction Wizard.

Another answer on stackoverflow recommend this book chapter as a way to understand the AutoCAD database connection features.


It's simple as follows:

[CommandMethod("LayerIterator")]
public static void LayerIterator_Method()
{
    Database database = HostApplicationServices.WorkingDatabase;
    using (Transaction transaction = database.TransactionManager.StartTransaction())
    {
        SymbolTable symTable = (SymbolTable)transaction.GetObject(database.LayerTableId, OpenMode.ForRead);
        foreach (ObjectId id in symTable)
        {
            LayerTableRecord symbol = (LayerTableRecord)transaction.GetObject(id, OpenMode.ForRead);

            //TODO: Access to the symbol
            MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
        }

        transaction.Commit();
    }
}

Details can be found from http://spiderinnet1.typepad.com/blog/2012/06/autocad-net-iterate-through-layer-table.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号