zyx137 发表于 2009-6-19 14:53:00

autocadmap短线检查源码

//-------------------------------------短线检查----------------------------------------------------------
void CleanupShortLine()
{
SetCurLayer(_T("checklayer"),250);
ade_id cleanupVarId = ADE_NULLID;          // variable ID
ade_id cleanupModelId = ADE_NULLID;      // clean ID
   ade_id cleanupactionVarId = ADE_NULLID;    //variable ID
ads_name ss;                               // selection set
long qty = 0;                              // quantity数量
long totalqty=0;                           //所有错误的总和
int type = 0;                              // clean error group type
int subtype = 0;                           // clean error group subtype
int done = 0;                              //是否完成清理工作
int resultCode = 0;
CString str;
//给cleanup变量分配内存,变量初始化为它们的缺省值,使用tpm_varalloc.
cleanupVarId = tpm_varalloc();
    cleanupactionVarId=tpm_varalloc();
//为cleanup模型分配内存,使用 tpm_cleanalloc.
cleanupModelId = tpm_cleanalloc();
if( ! cleanupVarId || ! cleanupModelId ||!cleanupactionVarId)
{
acutPrintf(_T("\n内存分配失败."));
tpm_varfree(cleanupVarId);
tpm_cleanfree(cleanupModelId);
return;
}
tpm_cleanactionlistins(cleanupVarId,1,1,cleanupactionVarId);//必须在tpm_cleaninit前调用
tpm_cleanactionlistins(cleanupVarId,2,256,cleanupactionVarId);//必须在tpm_cleaninit前调用
if(acedSSGet(_T("X"),NULL,NULL,NULL,ss)!= RTNORM)//第一个参数为NULL为自由选,“X”为全选
{
acutPrintf(_T("\n获取选择集失败!"));
tpm_varfree(cleanupVarId);
tpm_cleanfree(cleanupModelId);
tpm_varfree(cleanupactionVarId);
return;
}
// 初始化一个目标选择集命名为 ss进行清理工作
tpm_cleaninit(cleanupModelId, cleanupVarId, ss);//初始化清理模型
resultCode = tpm_cleanstart(cleanupModelId);//开始清理进程
if( resultCode != RTNORM )
{
acutPrintf(_T("\n清理工作启动失败."));
tpm_varfree(cleanupVarId);
tpm_varfree(cleanupactionVarId);
tpm_cleanfree(cleanupModelId);
return;
}
// Count errors by group type and subtype
while ( ! done)
{
resultCode = tpm_cleangroupnext(cleanupModelId);
if ( resultCode == RTNORM )
{
   if (tpm_cleancomplete(cleanupModelId) == TRUE )
   {
    done = 1;
   }
   else
   {
    type = tpm_cleangrouptype(cleanupModelId);
    subtype = tpm_cleangroupsubtype(cleanupModelId);
    tpm_cleangroupqty(cleanupModelId, &qty);
    tpm_cleangroupmark(cleanupModelId);
//         tpm_cleangroupfix(cleanupModelId);
    if(qty>0)
    {
   acutPrintf(_T("\n组类型:%d,子类型:%d,错误数目:%
d"),type,subtype,qty);
   totalqty+=qty;
    }
   } // else
} // if
else
{
   acutPrintf(_T("\n没有要清理的对象"));
}
} // while
resultCode = tpm_cleanend(cleanupModelId);//完成清理进程并更新图形,修复被tpm_cleanerrorfix指定的
要修复的错误
    resultCode = acedSSFree(ss);//最后释放选择集
tpm_cleanfree(cleanupModelId);//释放清理模型
tpm_varfree(cleanupVarId);//释放配置变量
tpm_varfree(cleanupactionVarId);//释放配置变量
if(totalqty==0)
str.Format(_T("\n恭喜!未找到任何错误。"));
else
   str.Format(_T("短线错误%d处"),totalqty);
acedAlert(str);
}
页: [1]
查看完整版本: autocadmap短线检查源码