سؤال

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top