明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5080|回复: 5

[原创][ARX]生成图层和设置线型(类型、颜色、线宽)

[复制链接]
发表于 2006-5-29 11:45:00 | 显示全部楼层 |阅读模式
和大家一起分享生成图层和设置线型(类型、颜色、线宽)的简单东东。

AcDbLayerTable *pLayerTable;
acdbCurDwg()->getLayerTable(pLayerTable, AcDb::kForWrite);

AcDbLayerTableRecord *pLayerTableRecord1 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord2 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord3 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord4 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord5 = new AcDbLayerTableRecord;
AcDbLayerTableRecord *pLayerTableRecord6 = new AcDbLayerTableRecord;

pLayerTableRecord1->setName("A");
pLayerTableRecord2->setName("B");
pLayerTableRecord3->setName("C");
pLayerTableRecord4->setName("D");
pLayerTableRecord5->setName("E");
pLayerTableRecord6->setName("F");

AcCmColor color;
color.setColorIndex(1);
pLayerTableRecord1->setColor(color);
pLayerTableRecord1->setLineWeight(AcDb:ineWeight::kLnWt018);//

color.setColorIndex(5);
pLayerTableRecord2->setColor(color);
pLayerTableRecord2->setLineWeight(AcDb:ineWeight::kLnWt050);

color.setColorIndex(4);
pLayerTableRecord3->setColor(color);
pLayerTableRecord3->setLineWeight(AcDb:ineWeight::kLnWt018);

color.setColorIndex(6);
pLayerTableRecord4->setColor(color);
pLayerTableRecord4->setLineWeight(AcDb:ineWeight::kLnWt018);

color.setColorIndex(3);
pLayerTableRecord5->setColor(color);
pLayerTableRecord5->setLineWeight(AcDb:ineWeight::kLnWt018);

color.setColorIndex(2);
pLayerTableRecord6->setColor(color);
pLayerTableRecord6->setLineWeight(AcDb:ineWeight::kLnWt018);

AcDbLinetypeTable *pLinetypeTbl;
AcDbObjectId DashedLineId, CenterLineId,DivideLineId;

acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);

if ((pLinetypeTbl->getAt("DASHED",DashedLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("DASHED","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("DASHED",DashedLineId);
}
if ((pLinetypeTbl->getAt("CENTER",CenterLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("CENTER","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("CENTER",CenterLineId);
}
if ((pLinetypeTbl->getAt("DIVIDE",DivideLineId))!=Acad::eOk);
{
pLinetypeTbl->close();
acdbCurDwg()->loadLineTypeFile("DIVIDE","acadiso.lin");
acdbCurDwg()->getLinetypeTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl->getAt("DIVIDE",DivideLineId);
}

pLinetypeTbl->close();
pLayerTableRecord1->setLinetypeObjectId(CenterLineId);
pLayerTableRecord4->setLinetypeObjectId(DashedLineId);
pLayerTableRecord5->setLinetypeObjectId(DivideLineId);

pLayerTable->add(pLayerTableRecord1);
pLayerTable->add(pLayerTableRecord2);
pLayerTable->add(pLayerTableRecord3);
pLayerTable->add(pLayerTableRecord4);
pLayerTable->add(pLayerTableRecord5);
pLayerTable->add(pLayerTableRecord6);

pLayerTableRecord1->close();
pLayerTableRecord2->close();
pLayerTableRecord3->close();
pLayerTableRecord4->close();
pLayerTableRecord5->close();
pLayerTableRecord6->close();
pLayerTable->close();
发表于 2006-6-2 08:14:00 | 显示全部楼层

上述过程还可以用C语言格式书写.

生成新的图层.

ads_tblobjname("layer","0",ent);

rb=ads_entget(ent);

assoc_dxf_str(rb,1,new_layername);

assoc_dxf_int(rb,0,new_color);

ads_entmod(rb);

ads_relrb(rb);

其中assoc_dxf_int为链表替换程序!

 

发表于 2006-6-14 00:56:00 | 显示全部楼层

累死了,可不可以这么写?

//添加层
AcDbObjectId CLjDwg::AddLayer(const char* LayerName,
          const Adesk::Int16 LayerColor,
          const char* Linetype,
          AcDbDatabase* pDb)
{
 if(pDb==NULL)
  pDb=acdbCurDwg();
 //装载线型
 pDb->loadLineTypeFile(Linetype,LINETYPE_FILENAME);
 
 AcDbObjectId LineTypeId=AddLineType(pDb,Linetype);

 AcDbLayerTable* pLayerTable=NULL;
 AcDbLayerTableRecord* pLayerRecord=NULL;
 AcDbObjectId LayerId=AcDbObjectId::kNull;
 pDb->getLayerTable(pLayerTable,AcDb::kForWrite);
 if(!pLayerTable)
  return FALSE;
 if(pLayerTable->has(LayerName))
 {
  pLayerTable->getAt(LayerName,LayerId);
 }
 else
 {
  pLayerRecord=new AcDbLayerTableRecord;
  AcCmColor color;
  color.setColorIndex(LayerColor);
  pLayerRecord->setColor(color);
  pLayerRecord->setLinetypeObjectId(LineTypeId);
  pLayerRecord->setName(LayerName); 
  pLayerTable->add(LayerId,pLayerRecord);
  pLayerRecord->close();
 }
 pLayerTable->close();
 return LayerId;
}

 

发表于 2006-11-23 16:02:00 | 显示全部楼层

太好了,刚好在学这里,真是太感谢了!!

发表于 2007-3-8 14:48:00 | 显示全部楼层

相当谢谢

发表于 2012-8-4 13:59:51 | 显示全部楼层
很好,正需要这个呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-29 01:38 , Processed in 0.159771 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表