找回密码
 立即注册

QQ登录

只需一步,快速开始

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

RGB和CAD颜色索引之间的转换

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-9-25 13:21:06 | 显示全部楼层 |阅读模式
  1. 如何获得程序路径
  2. struct resbuf rb;
  3. char sTemp[1024],*str;
  4. ads_getvar("acadprefix",&rb);
  5. strcpy(sTemp,rb.resval.string);
  6. acad_free(rb.resval.rstring);
  7. str=strchr(sTemp,';');
  8. *str='\0';
  9. str=strrchr(sTemp,'\\');
  10. *str='\0';
  11. 上段程序中,sTemp中存储了安装CAD的目录
  12. AUTOCAD的系统变量存储了一些与安装有关的信息,虽然不多,在正常情况是够用的.与目录有关的主要有:
  13. dwgprefix 当前dwg图形存储的目录
  14. acadprefix   acad环境变量存储的目录
  15. dwgname   当前dwg文件名
  16. savefile 当前自动存储文件名
  17. ///从RGB得到cad颜色索引值
  18. int getNearestACI(COLORREF color)
  19. {
  20. long acirgb, r,g,b;
  21. long mindst = 2147483647L;
  22. long dst = 0;
  23. int minndx = 0;
  24. long red=GetRValue(color);
  25. long green=GetGValue(color);
  26. long blue=GetBValue(color);
  27. for ( int i = 1; i < 255; i++ ) {
  28.    acirgb = acdbGetRGB ( i );
  29.    r =GetRValue(acirgb);
  30.    g =GetGValue(acirgb);
  31.    b =GetBValue(acirgb);
  32.   
  33.    dst = abs ( r-red) + abs ( g -green) + abs (b-blue);
  34.    if ( dst < mindst ) {
  35.     minndx = i;
  36.     mindst = dst;
  37.    }
  38. }
  39. return minndx;
  40. }  
  41. //功   能:从CAD的颜色得到RGB
  42. COLORREF CGlobal::GetColorFromIndex(int colorIndex)
  43. {
  44. if(colorIndex < 0 || colorIndex > 255)
  45. {
  46.    ads_alert("传入的颜色号不在0~255之间!");
  47.    return 0;
  48. }
  49. BYTE R, G, B;
  50. #ifdef ARX_2002_dll
  51. R = lpszRGBData[colorIndex*3+0];
  52. G = lpszRGBData[colorIndex*3+1];
  53. B = lpszRGBData[colorIndex*3+2];
  54. #else
  55. long zhi = acdbGetRGB(colorIndex);
  56. WORD LOW = LOWORD(zhi);
  57. WORD HIG = HIWORD(zhi);
  58. R = LOBYTE(LOW);
  59. G = HIBYTE(LOW);
  60. B = LOBYTE(HIG);
  61. #endif
  62. return RGB(R,G,B);
  63. //return acdbGetRGB(nColor);
  64. }
  65. 获取AcDbDimension里的属性信息
  66. AcDbEntity *pEnt;
  67. AcDbObjectId id;
  68. AcGePoint3d ptPick;
  69. ads_name eName;
  70. if (acedEntSel ("Select a dimension: " , eName, asDblArray (ptPick)) != RTNORM )
  71. return;
  72. acdbGetObjectId (id, eName);
  73. acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead);
  74. //----- Get the id of the block table record which owns the text entity
  75. AcDbDimension *pDim =AcDbDimension::cast (pEnt);
  76. if (pDim == NULL)
  77. {
  78. pEnt->close ();
  79. return;
  80. }
  81. id =pDim->dimBlockId ();
  82. pDim->close ();
  83. AcDbBlockTableRecord *pr;
  84. acdbOpenAcDbObject ((AcDbObject *&) pr, id, AcDb::kForRead);
  85. //----- Iterating the block table record
  86. AcDbBlockTableRecordIterator *pi;
  87. pr->newIterator (pi);
  88. while (!pi->done ())
  89. {
  90. pi->getEntity (pEnt, AcDb::kForRead);
  91. if (pEnt->isKindOf (AcDbMText::desc ()))
  92. {
  93. AcDbMText *pt = (AcDbMText *) pEnt;
  94. char *s = pt->contents ();
  95. acutPrintf (s);
  96. delete s;
  97. }
  98. pEnt->close();
  99. pi->step();
  100. }
  101. pr->close();
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-27 21:47 , Processed in 0.145622 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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