objectarx .net 获取图层名称

主要是通过遍历  layerTable 表的方式获取,方法很基础,只是本人菜鸟,才发现,代码如下:

[CommandMethod("getLayername")]
        public void GetLayerName()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

                foreach (ObjectId layerId in lt)
                {
                    LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(layerId, OpenMode.ForRead);
                    ed.WriteMessage(ltr.Name);
                }
                trans.Commit();
            }
        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在C++ ObjectARX中创建图层,可以按照以下步骤进行: 1. 获取当前文档的数据库。 ```cpp AcDbDatabase* pDatabase = acdbHostApplicationServices()->workingDatabase(); ``` 2. 获取当前文档的图层表。 ```cpp AcDbLayerTable* pLayerTable; pDatabase->getLayerTable(pLayerTable, AcDb::kForWrite); ``` 3. 创建一个新的图层。 ```cpp AcDbLayerTableRecord* pLayerTableRecord = new AcDbLayerTableRecord; pLayerTableRecord->setName("MyLayer"); ``` 4. 将新图层添加到图层表中。 ```cpp pLayerTable->add(pLayerTableRecord); ``` 5. 关闭图层表和图层表记录。 ```cpp pLayerTableRecord->close(); pLayerTable->close(); ``` 下面是一个完整的示例代码,演示如何在C++ ObjectARX中创建图层: ```cpp void createLayer() { // 获取当前文档的数据库 AcDbDatabase* pDatabase = acdbHostApplicationServices()->workingDatabase(); // 获取当前文档的图层表 AcDbLayerTable* pLayerTable; pDatabase->getLayerTable(pLayerTable, AcDb::kForWrite); // 创建一个新的图层 AcDbLayerTableRecord* pLayerTableRecord = new AcDbLayerTableRecord; pLayerTableRecord->setName("MyLayer"); // 将新图层添加到图层表中 pLayerTable->add(pLayerTableRecord); // 关闭图层表和图层表记录 pLayerTableRecord->close(); pLayerTable->close(); acutPrintf("New layer created: MyLayer"); } ``` 在上面的代码中,我们首先获取当前文档的数据库和图层表。然后,我们创建一个名为“MyLayer”的新图层,并将其添加到图层表中。最后,我们关闭图层表和图层表记录,并在命令行上显示新图层名称

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值