⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printxdata.cpp

📁 autocad 二次开发的xdata开发函数的实例
💻 CPP
字号:
// printXdata.cpp

// date : 03st.Dec.2003

#include <aced.h>
#include <rxregsvc.h>
#include <adscodes.h>

void initApp();
void unloadApp();

void printList(struct resbuf* pRb);
AcDbObject* selectObject(AcDb::OpenMode openMode);
void printXdata();

void initApp()
{
	// register a command with AutoCAD command mechanism.
	acedRegCmds->addCommand("ASDK_AEXP_COMMANDS",
		"PRINTXDATA",
		"PRINTXDATA",
		ACRX_CMD_TRANSPARENT,
		printXdata);
}

void unloadApp()
{
	acedRegCmds->removeGroup("ASDK_AEXP_COMMANDS");
}

// This function calls the selectObject() function to allow the user to pick
// an object; then it accesses the xdata of the object and sends the list to 
// the printList() function that lists the restype and resval values.
//
void printXdata()
{
	// Select and open an object.
	// 
	AcDbObject *pObj;
	if ((pObj = selectObject(AcDb::kForRead)) == NULL)
	{
		return;
	}

	// Get the application name for the xdata.
	//
	char appname[133];
	if (acedGetString(NULL,"\nEnter the desired Xdata application name: ", appname) != RTNORM)
	{
		return;
	}

	// Get the xdata for the application name.
	//
	struct resbuf *pRb;
	pRb = pObj->xData(appname);
	if (pRb != NULL)
	{
		// Print the existing xdata if any is present.
		// Notice that there is no -3 group, as there is in LISP.
		// This is ONLY the xdata, so the -3 xdata-start marker isn't needed.
		//
		printList(pRb);
		acutRelRb(pRb);
	}
	else
	{
		acutPrintf("\nNo xdata for this appname");
	}
	pObj->close();
}

// This function accepts a linked list of resbufs as it's
// argument and runs through the list printing out the 
// restype and resval values one set per line.
//
void printList(struct resbuf* pRb)
{
	int rt, i;
	char buf[133];

	for (i = 0; pRb != NULL; i++,pRb = pRb->rbnext){
		if (pRb->restype < 1010) {
			rt = RTSTR;
		} else if (pRb->restype < 1040) {
			rt = RT3DPOINT;
		} else if (pRb->restype < 1060) {
			rt = RTREAL;
		} else if (pRb->restype < 1071) {     
			rt = RTSHORT;
		} else if (pRb->restype == 1071) {
			rt = RTLONG;
		} else {// restype is already RTSHORT, RTSTR,...
			rt = pRb->restype; // or else it is unknown.
		}

		switch (rt) 
		{
		case RTSHORT:
			if (pRb->restype == RTSHORT) {
				acutPrintf("RTSHORT : %d\n", pRb->resval.rint);
			} else {
				acutPrintf("(%d . %d)\n", pRb->restype, pRb->resval.rint);
			};
			break;
		case RTREAL:
			if (pRb->restype == RTSTR) {
				acutPrintf("RTSTR : %s\n", pRb->resval.rstring);
			} else {
				acutPrintf("(%d . \"%s\")\n", pRb->restype, pRb->resval.rstring);
			};
			break;
		case RTSTR:
			if (pRb->restype == RTSTR) {
				acutPrintf("RTSTR : %s\n",
					pRb->resval.rstring);
			} else {
				acutPrintf("(%d . \"%s\")\n", pRb->restype, pRb->resval.rstring);
			};
			break;
		case RT3DPOINT:
			if (pRb->restype == RT3DPOINT) {
				acutPrintf("RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
					pRb->resval.rpoint[X],
					pRb->resval.rpoint[Y],
					pRb->resval.rpoint[Z]);
			} else {
				acutPrintf("(%d %0.3f %0.3f %0.3f)\n",
					pRb->restype,
					pRb->resval.rpoint[X],
					pRb->resval.rpoint[Y],
					pRb->resval.rpoint[Z]);
			}
			break;
		case RTLONG:
			acutPrintf("RTLONG : %dl\n", pRb->resval.rlong);
			break;
		}
		
		if ((i == 23) && (pRb->rbnext != NULL)) {
			i = 0;
			acedGetString(0, "Press <ENTER> to continue...", buf);
		}
	}// for
}

// This function prompts the user to select an entity or 
// enter an object's handle. It then proceeds to open the
// object/entity and return a pointer to it.
//
AcDbObject* selectObject(AcDb::OpenMode openMode)
{
	// Allow user to either pick an entity, or type in the
	// object handle.
	//
	int ss;
	ads_name en;
	ads_point pt;
	acedInitGet(RSG_OTHER, "Handle _Handle");
	ss = acedEntSel("\nSelect an Entity or either" 
		" 'H' to enter its handle:  ", en, pt);

	char handleStr[132];
	AcDbObjectId eId;
	switch (ss)
	{
	case RTNORM:	// got it!
		break;
	case RTKWORD:
		if ((acedGetString(Adesk::kFalse, "Enter Valid Object Handle: ", handleStr) == RTNORM)
			&& (acdbHandEnt(handleStr, en) == RTNORM))
		{
			break;
		}
	// Fall-through intentional
	//
	default:
		acutPrintf("Nothing Selected, Return Code == %d\n", ss);
		return NULL;
	}
	// Now, exchange the ads_name for the object Id...
	//
	Acad::ErrorStatus retStat;
	retStat = acdbGetObjectId(eId, en);
	if (retStat != Acad::eOk) {
		acutPrintf("\nacdbGetObjectId failed");
		acutPrintf("\nen==(%lx,%lx), retStat==%d\n",
			en[0], en[1], eId);
		return NULL;
	}

	AcDbObject* obj;

	if ((retStat = acdbOpenObject(obj, eId, openMode)) != Acad::eOk)
	{
		acutPrintf("acdbOpenEntity failed: ename:(%lx,%lx),"
			" mode:%d retStat:%d", en[0], en[1], openMode, retStat);
		return NULL;
	}
	return obj;
}

// Dll Entry Point.
extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void *pkt)
{
	switch (msg)
	{
	case AcRx::kInitAppMsg:
		acrxDynamicLinker->unlockApplication(pkt);
		acrxDynamicLinker->registerAppMDIAware(pkt);
		initApp();
		break;
	case AcRx::kUnloadAppMsg:
		unloadApp();
		break;
	default:
		break;
	}
	return AcRx::kRetOK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -