找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 150|回复: 0

[每日一码] 如何通过程序创建一个多线样式(AcDbMlineStyle)

[复制链接]

0

主题

0

回帖

28

积分

管理员

积分
28
发表于 2024-3-14 19:38:45 | 显示全部楼层 |阅读模式
  1. // minimal error checking for code brevity
  2. void createMlineStyle()
  3. {
  4.     AcDbLinetypeTable* pTable = NULL;  
  5. AcDbObjectId id;   
  6. AcDbDatabase* pDb = curDoc()->database();
  7. // open ByLayer linetypetablerecord for use in MLineStyle later
  8. pDb->getLinetypeTable(pTable, AcDb::kForRead);
  9. if((pTable->getAt(L"ByLayer", id)) != Acad::eOk)
  10. {
  11.     acutPrintf(L"\nlinetype ByLayer not found.");   
  12.     return;   
  13. }
  14. pTable->close();
  15.     AcDbDictionary* pDict = NULL;
  16. // open MLStyleDictionary (its sored in the NOD)  
  17. Acad::ErrorStatus es = pDb->getMLStyleDictionary(pDict, AcDb::kForRead);
  18. if(es != Acad::eOk)   
  19. {     
  20.   acutPrintf(L"\nCan't open mline style dictionary for read.");  
  21.   return;   
  22. }  
  23. const ACHAR mlineStyleName[] = L"test";
  24. AcDbMlineStyle* ps = NULL;
  25. // does MLStyle "test" already exist?
  26. es = pDict->getAt(mlineStyleName, (AcDbObject*&)ps, AcDb::kForWrite);
  27. // If it doesn't exist, create it  
  28. if(es != Acad::eOk)  
  29. {      
  30.   ps = new AcDbMlineStyle;      
  31.   AcDbObjectId mId;  
  32.   ps->initMlineStyle();  
  33.   pDict->upgradeOpen();   
  34.   pDict->setAt(mlineStyleName, ps, mId);
  35. }   
  36. pDict->close();
  37.     // set MLStyle attributes and elements   
  38. es = ps->setName(mlineStyleName);
  39. AcCmColor cm;     cm.setColorIndex(256);
  40.     int a=0, b=0;   
  41. es = ps->addElement(a, -0.25, cm, id);  
  42. assert(es == Acad::eOk);  
  43. es = ps->addElement(b, 0.25, cm, id);
  44.     assert(es == Acad::eOk);  
  45. ps->close();
  46. acutPrintf(L"\nMline style: %s created.", mlineStyleName);
  47. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 05:33 , Processed in 0.136598 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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