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

📄 acrxentrypoint.cpp

📁 vs2003+arxobject2006相信不用说
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				acutPrintf ("\nFailed to open the 'Employee' dictionary.") ;
				return ;
			}
			// Check if someone has else has created an entry with our name
			// that is not a dictionary.
			if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
				pO->close () ;
				pExtDict->close () ;
				acutPrintf ("\nThe entry is not a dictionary") ;
				return ;
			}
		}
		// We do not need the ext. dictionary object anymore
		pExtDict->close () ;
		// Check if a record with this key is already there
		if ( pEmployeeDict->getAt ("DETAILS", idO) == Acad::eOk ) {
			pEmployeeDict->close () ;
			acutPrintf ("\nDetails already assign to that 'Employee' object.") ;
			return ;
		}
		// Create an EmployeeDetails object and set its fields
		AsdkEmployeeDetails *pEmployeeDetails =new AsdkEmployeeDetails ;
		pEmployeeDetails->setID (id) ;
		pEmployeeDetails->setCube (cubeNumber) ;
		pEmployeeDetails->setFirstName (strFirstName) ;
		pEmployeeDetails->setLastName (strLastName) ;
		// Add it to the dictionary
		if ( pEmployeeDict->setAt ("DETAILS", pEmployeeDetails, idO) != Acad::eOk ) {
			delete pEmployeeDetails ;
			acutPrintf ("\nFailed to add details to that object.") ;
			pEmployeeDict->close () ;
			return ;

		}
		// Done
		acutPrintf ("\nDetails successfully added!") ;
		pEmployeeDict->close () ;
		pEmployeeDetails->close () ;
	}

	// - AsdkStep05._ListDetails command (do not rename)
	static void AsdkStep05_ListDetails(void)
	{
		// Add your code for command AsdkStep05._ListDetails here
		ads_name ename ;
		ads_point pt ;
		// Get the data from the user
		if ( acedEntSel ("Select employee: ", ename, pt) != RTNORM )
			return ;
		// Do a quick check
		// a more comprehensive check could include 
		// whether we already have the detail object on this candidate
		AcDbObjectId idO ;
		if ( acdbGetObjectId (idO, ename) != Acad::eOk )
			return ;
		AcDbObject *pO ;
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk )
			return ;
		if ( !pO->isKindOf (AcDbBlockReference::desc ()) ) {
			acutPrintf ("\nThis is not a block reference.") ;
			pO->close () ;
			return ;
		}
		// Get the Ext. Dictionary
		if ( (idO =pO->extensionDictionary ()) == AcDbObjectId::kNull ) {
			// Nothing to do
			pO->close () ;
			return ;
		}
		// We do not need the block reference object anymore.
		pO->close () ;
		// If erased, nothing to do
		AcDbDictionary *pExtDict ;
		if ( acdbOpenAcDbObject ((AcDbObject *&)pExtDict, idO, AcDb::kForRead, Adesk::kFalse) != Acad::eOk ) {
			acutPrintf ("\nFailed to open ext. dictionary.") ;
			return ;
		}
		// See if our dictionary is already there
		AcDbDictionary *pEmployeeDict ;
		if ( pExtDict->getAt ("ASDK_EMPLOYEE_DICTIONARY", idO) == Acad::eKeyNotFound ) {
			// Nothing to do if not
			pExtDict->close () ;
			return ;
		} else {
			// Open dictionary for write if it is already there
			if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk ) {
				pExtDict->close () ;
				acutPrintf ("\nFailed to open the 'Employee' dictionary.") ;
				return ;
			}
			// Check if someone has else has created an entry with our name
			// that is not a dictionary. 
			if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
				pO->close () ;
				pExtDict->close () ;
				acutPrintf ("\nThe entry is not a dictionary") ;
				return ;
			}
		}
		// Check if a record with this key is already there
		if ( pEmployeeDict->getAt ("DETAILS", idO) != Acad::eOk ) {
			// Nothing to do
			pEmployeeDict->close () ;
			pExtDict->close () ;
			return ;
		}
		// Open the object for write 
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk ) {
			pEmployeeDict->close () ;
			pExtDict->close () ;
			acutPrintf ("\nFailed to open the object detail.") ;
			return ;
		}
		// Check it is a AsdkEmployeeDetails object
		AsdkEmployeeDetails *pEmployeeDetails =AsdkEmployeeDetails::cast (pO) ;
		if ( pEmployeeDetails == NULL ) {
			acutPrintf ("\nNo details found!.") ;
			pO->close () ;
			pEmployeeDict->close () ;
			pExtDict->close () ;
			return ;
		}
		// And display details
		Adesk::Int32 i ;
		pEmployeeDetails->ID (i) ;
		acutPrintf ("*Employee's ID: %d\n", i) ;
		pEmployeeDetails->cube (i) ;
		acutPrintf ("*Employee's cube number: %d\n", i) ;
		char *st =NULL ;
		pEmployeeDetails->firstName (st) ;
		acutPrintf ("*Employee's first name: %s\n", st) ;
		delete [] st ;
		pEmployeeDetails->lastName (st) ;
		acutPrintf ("*Employee's last name: %s\n", st) ;
		delete [] st ;

		pO->close () ;
		pEmployeeDict->close () ;
		pExtDict->close () ;
	}

	// - AsdkStep05._RemoveDetail command (do not rename)
	static void AsdkStep05_RemoveDetail(void)
	{
		// Add your code for command AsdkStep05._RemoveDetail here
		ads_name ename ;
		ads_point pt ;
		// Get the data from the user
		if ( acedEntSel ("Select employee: ", ename, pt) != RTNORM )
			return ;
		// Do a quick check
		// a more comprehensive check could include 
		// whether we already have the detail object on this candidate
		AcDbObjectId idO ;
		if ( acdbGetObjectId (idO, ename) != Acad::eOk )
			return ;
		AcDbObject *pO ;
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk )
			return ;
		if ( !pO->isKindOf (AcDbBlockReference::desc ()) ) {
			acutPrintf ("\nThis is not a block reference.") ;
			pO->close () ;
			return ;
		}
		// Get the Ext. Dictionary
		if ( (idO =pO->extensionDictionary ()) == AcDbObjectId::kNull ) {
			// Nothing to do
			pO->close () ;
			return ;
		}
		// We do not need the block reference object anymore.
		pO->close () ;
		// If erased, nothing to do
		AcDbDictionary *pExtDict ;
		if ( acdbOpenAcDbObject ((AcDbObject *&)pExtDict, idO, AcDb::kForWrite, Adesk::kFalse) != Acad::eOk ) {
			acutPrintf ("\nFailed to open ext. dictionary.") ;
			return ;
		}
		// See if our dictionary is already there
		AcDbDictionary *pEmployeeDict ;
		if ( pExtDict->getAt ("ASDK_EMPLOYEE_DICTIONARY", idO) == Acad::eKeyNotFound ) {
			// Nothing to do if not
			pExtDict->close () ;
			return ;
		} else {
			// Open the dictionary for write if it is already there
			if ( acdbOpenAcDbObject (pO, idO, AcDb::kForWrite) != Acad::eOk ) {
				pExtDict->close () ;
				acutPrintf ("\nFailed to open the 'Employee' dictionary.") ;
				return ;
			}
			// Check if someone has else has created an entry with our name
			// that is not a dictionary.
			if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
				pO->close () ;
				pExtDict->close () ;
				acutPrintf ("\nThe entry is not a dictionary") ;
				return ;
			}
		}
		// Check if a record with this key is already there
		if ( pEmployeeDict->getAt ("DETAILS", idO) != Acad::eOk ) {
			pEmployeeDict->close () ;
			pExtDict->close () ;
			acutPrintf ("\nNo details assigned to that 'Employee' object.") ;
			return ;
		}
		// Open the object for write 
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForWrite) != Acad::eOk ) {
			pEmployeeDict->close () ;
			pExtDict->close () ;
			acutPrintf ("\nFailed to open the object detail.") ;
			return ;
		}
		// And erase it
		pO->erase () ;
		pO->close () ;
		// Erase dictionary if it has no more entries
		if ( pEmployeeDict->numEntries () == 0 )
			pEmployeeDict->erase () ;
		pEmployeeDict->close () ;
		// Erase ext. dictionary if it has no more entries
		if ( pExtDict->numEntries () == 0 )
			pExtDict->erase () ;
		pExtDict->close () ;
	}
} ;

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CStep05App)

ACED_ARXCOMMAND_ENTRY_AUTO(CStep05App, AsdkStep05, _Create, Create, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep05App, AsdkStep05, _SetLayer, SetLayer, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep05App, AsdkStep05, _AddDetail, AddDetail, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep05App, AsdkStep05, _ListDetails, ListDetails, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep05App, AsdkStep05, _RemoveDetail, RemoveDetail, ACRX_CMD_TRANSPARENT, NULL)

⌨️ 快捷键说明

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