|
//256个颜色命令
namespace JJBox命令 {
//获取变量
void GetVar(CString command, CString* sCmd)
{
struct resbuf var;
acedGetVar(command, &var);
//通过指针的方式存入内容
(*sCmd).Append(var.resval.rstring);
}
//颜色命令最后都会调用到这个组
void sk_ChColor()
{
CString sCmd;
GetVar(_T("CMDNAMES"), &sCmd);//获取是什么数字触发的.
if (sCmd == "")
{
return;
}
int nColor = _ttoi(sCmd);
if (nColor < 0 || nColor > 256)
{
return;
}
ads_name ss;
int nRet = acedSSGet(NULL, NULL, NULL, NULL, ss);
if (RTCAN == nRet)//取消
{
return;
}
if (RTNORM != nRet)//回车
{
//设置默认颜色
AcCmColor col;
col.setColorIndex(nColor);
acdbHostApplicationServices()->workingDatabase()->setCecolor(col);
}
Adesk::Int32 nSSLenght = 0;
acedSSLength(ss, &nSSLenght);
for (int i = 0; i < nSSLenght; i++)
{
ads_name ent;
AcDbObjectId objId;
acedSSName(ss, i, ent);
acdbGetObjectId(objId, ent);
AcDbEntityPointer pEnt(objId, AcDb::kForWrite);
if (Acad::eOk != pEnt.openStatus())
{
continue;
}
pEnt->setColorIndex(nColor);
}
}
//由于是顺序编译,所以这里的命令定义只能够放最下面
//定义颜色命令
void jjarx_AddCommands()
{
for (int i = 0; i <= 256; i++)
{
CString strCmdName;
strCmdName.Format(_T("%d"), i);
acedRegCmds->addCommand(_T("sk_ChColor"), strCmdName, strCmdName, ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, sk_ChColor);
}
}
} |
|