[ObjectARX]-修改实体的图层 CH3_2

摘要:

  编写了ObjectARX程序,能够选择一组实体,并把这些实体的图层改为选中目标实体所在的图层。
实现代码:

入口函数acrxEntryPoint.cpp的实现:

static void aaaMyGroupMyCommand () {
		
		ads_name srcSS;  
		ads_name targEnt;
		int rc;
		ads_point pickPt;

		acedPrompt(_T("\\nSelect entities for layer change!"));
		rc = acedSSGet(NULL, NULL, NULL, NULL, srcSS);
		if (rc != RTNORM)
		{
			acutPrintf(_T("\\nNo entities selected!"));
			return;
		}

		rc = acedEntSel(_T("Select target layer entity."),targEnt,pickPt);
		switch (rc)
		{
		case RTERROR:
			acutPrintf(_T("\\nNothing selected!"));
			break;

		case RTCAN:
			acutPrintf(_T("\\nUser canceled."));

		case RTNORM:
			COtherUtil::chgEntsLyr(targEnt, srcSS);
			break;
		}

		acedSSFree(srcSS);

	}

chgEntsLyr函数的声明: 

	static void chgEntsLyr(ads_name ent, ads_name ss);

chgEntsLyr函数的实现:

void COtherUtil::chgEntsLyr(ads_name ent, ads_name ss)
{
	acutPrintf(_T("\\n进入chgEntsLyr()函数"));
	long idx;
	long lenSS;
    ACHAR lyrName[32];
	ads_name ssEntName;
	struct resbuf *rbTargEnt;
	struct resbuf *rbSSEnt;
	struct resbuf *rbTrav;
	int rc;

	acutPrintf(_T("\\n获取目标实体的图层名."));
	rbTargEnt = acdbEntGet(ent);
	if (!rbTargEnt)
	{
		acutPrintf(_T("\\nFailed to get target entities data."));
		return;
	}

	rbTrav = rbTargEnt;
	while (rbTrav)
	{
		switch (rbTrav->restype)
		{
		case 8:
			strcpy(reinterpret_cast<char *>(lyrName), 
                  reinterpret_cast<const char*>(rbTrav->resval.rstring));
			break;
		}
		rbTrav=rbTrav->rbnext;

	}

	acutPrintf(_T("\\n释放rbTargEnt."));
	if (rbTargEnt)
	{
		acutRelRb(rbTargEnt);
	}

	acutPrintf(_T("\\n遍历选择集."));
	rc = acedSSLength(ss, reinterpret_cast<Adesk::Int32*>(&lenSS));
	if (rc != RTNORM)
	{
		acutPrintf(_T("\\nInvalid or empty selection set."));
		return;
	   
	}

	acutPrintf(_T("\\n进入for循环."));
	for (idx = 0; idx < lenSS; idx++)
	{
		rc = acedSSName(ss, idx, ssEntName);
		if (rc != RTNORM)
		{
			break;
		}

		//Get ssEntName entity data
		rbSSEnt = acdbEntGet(ssEntName);
		if (!rbSSEnt)
		{
			break;
		}

		rbTrav = rbSSEnt;

		acutPrintf(_T("\\n进入while循环."));
		while (rbTrav)
		{
			switch (rbTrav->restype)
			{
			case 8:
				strcpy(reinterpret_cast<char *>(rbTrav->resval.rstring),
                           reinterpret_cast<const char*>(lyrName));
				break;
			}
			rbTrav = rbTrav->rbnext;
		}

		acutPrintf(_T("\\nacdbEntMod()函数."));
		rc = acdbEntMod(rbSSEnt);
		if (rc != RTNORM)
		{
			acutPrintf(_T("\\nFailded to modify the entity."));
		}

		//Release the resbuf
		if (rbSSEnt)
		{
			acutRelRb(rbSSEnt);
		}
	}
}

效果:

执行命令后:

 Ctrl + F2查看输出的文本:

参考资料:

  《AutoCAD 2000 ObjectARX 编程指南》

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片