其他分享
首页 > 其他分享> > ObjectARX学习笔记(七)----RGB和CAD颜色索引之间的转换 ObjectARX学习笔记(六)----如何设置点的样式和大小 CAD二次

ObjectARX学习笔记(七)----RGB和CAD颜色索引之间的转换 ObjectARX学习笔记(六)----如何设置点的样式和大小 CAD二次

作者:互联网

如何获得程序路径
struct resbuf rb;

char sTemp[1024],*str;

ads_getvar("acadprefix",&rb);

strcpy(sTemp,rb.resval.string);

acad_free(rb.resval.rstring);

str=strchr(sTemp,';');

*str='\0';

str=strrchr(sTemp,'\\');

*str='\0';

上段程序中,sTemp中存储了安装CAD的目录
AUTOCAD的系统变量存储了一些与安装有关的信息,虽然不多,在正常情况是够用的.与目录有关的主要有:

dwgprefix 当前dwg图形存储的目录

acadprefix   acad环境变量存储的目录

dwgname   当前dwg文件名

savefile 当前自动存储文件名


///从RGB得到cad颜色索引值
int getNearestACI(COLORREF color)
{
long acirgb, r,g,b;
long mindst = 2147483647L;
long dst = 0;
int minndx = 0;
long red=GetRValue(color);
long green=GetGValue(color);
long blue=GetBValue(color);
for ( int i = 1; i < 255; i++ ) {
   acirgb = acdbGetRGB ( i );
   r =GetRValue(acirgb);
   g =GetGValue(acirgb);
   b =GetBValue(acirgb);
  
   dst = abs ( r-red) + abs ( g -green) + abs (b-blue);
   if ( dst < mindst ) {
    minndx = i;
    mindst = dst;
   }
}
return minndx;

}  


//功   能:从CAD的颜色得到RGB
COLORREF CGlobal::GetColorFromIndex(int colorIndex)
{
if(colorIndex < 0 || colorIndex > 255)
{
   ads_alert("传入的颜色号不在0~255之间!");
   return 0;
}

BYTE R, G, B;
#ifdef ARX_2002_dll
R = lpszRGBData[colorIndex*3+0];
G = lpszRGBData[colorIndex*3+1];
B = lpszRGBData[colorIndex*3+2];
#else
long zhi = acdbGetRGB(colorIndex);
WORD LOW = LOWORD(zhi);
WORD HIG = HIWORD(zhi);
R = LOBYTE(LOW);
G = HIBYTE(LOW);
B = LOBYTE(HIG);
#endif

return RGB(R,G,B);

//return acdbGetRGB(nColor);
}

获取AcDbDimension里的属性信息
AcDbEntity *pEnt;
AcDbObjectId id;
AcGePoint3d ptPick;
ads_name eName;
if (acedEntSel ("Select a dimension: " , eName, asDblArray (ptPick)) != RTNORM )
return;
acdbGetObjectId (id, eName);
acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead);
//----- Get the id of the block table record which owns the text entity
AcDbDimension *pDim =AcDbDimension::cast (pEnt);
if (pDim == NULL)
{
pEnt->close ();
return;
}

id =pDim->dimBlockId ();
pDim->close ();
AcDbBlockTableRecord *pr;
acdbOpenAcDbObject ((AcDbObject *&) pr, id, AcDb::kForRead);
//----- Iterating the block table record
AcDbBlockTableRecordIterator *pi;
pr->newIterator (pi);
while (!pi->done ())
{
pi->getEntity (pEnt, AcDb::kForRead);
if (pEnt->isKindOf (AcDbMText::desc ()))
{
AcDbMText *pt = (AcDbMText *) pEnt;
char *s = pt->contents ();
acutPrintf (s);
delete s;
}
pEnt->close();
pi->step();
}
pr->close();

 

 

 

 

 

 

 

 

 

 

 

 

 

ObjectARX学习笔记(六)----如何设置点的样式和大小 CAD二次开发

acdbCurDwg()->setPdmode(34); //设置点样式

acdbCurDwg()->setPdsize(6); //设置大小

标签:pEnt,return,colorIndex,long,acirgb,ObjectARX,笔记,id,CAD
来源: https://www.cnblogs.com/mjgw/p/12392774.html