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

📄 acrxentrypoint.cpp

📁 vs2003+arxobject2006相信不用说
💻 CPP
字号:
// (C) Copyright 2002-2005 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"

//-----------------------------------------------------------------------------
#define szRDS _RXST("Asdk")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CStep04App : public AcRxArxApp {

public:
	CStep04App () : AcRxArxApp () {}

	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
		// TODO: Load dependencies here

		// You *must* call On_kInitAppMsg here
		AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
		
		// TODO: Add your initialization code here

		return (retCode) ;
	}

	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
		// TODO: Add your code here

		// You *must* call On_kUnloadAppMsg here
		AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;

		// TODO: Unload dependencies here

		return (retCode) ;
	}

	virtual void RegisterServerComponents () {
	}


	// - AsdkStep04._MyADDENTRY command (do not rename)
	static void AsdkStep04_MyADDENTRY(void)
	{
		// Add your code for command AsdkStep04._MyADDENTRY here
		char strID [133] ;
		if ( acedGetString (0, "Enter employee name: ", strID) != RTNORM )
			return ;

		// Get the named object dictionary
		AcDbDictionary *pNOD ;
		if ( acdbHostApplicationServices()->workingDatabase ()->getNamedObjectsDictionary (pNOD, AcDb::kForRead) != Acad::eOk ) {
			acutPrintf ("\nUnable to open the NOD! Aborting...") ;
			return ;
		}

		// See if our dictionary is already there
		AcDbObjectId idO ;
		AcDbDictionary *pEmployeeDict =NULL ;
		if ( pNOD->getAt ("ASDK_EMPLOYEE_DICTIONARY", idO) == Acad::eKeyNotFound ) {
			// Create it if not
			if ( pNOD->upgradeOpen () != Acad::eOk ) {
				acutPrintf ("\nCannot open NOD for Write!") ;
				pNOD->close () ;
				return ;
			}
			pEmployeeDict =new AcDbDictionary ;
			// Add it to the NOD
			if ( pNOD->setAt ("ASDK_EMPLOYEE_DICTIONARY", pEmployeeDict, idO) != Acad::eOk ) {
				// We are really unlucky
				acutPrintf ("\nCannot add our dictionary in the AutoCAD NOD!") ;
				// Clean-up memory and abort
				delete pEmployeeDict ;
				pNOD->close () ;
				return ;
			}
		}
		else {
			// Get it for write if it is already there
			AcDbObject *pO ;
			if ( acdbOpenAcDbObject (pO, idO, AcDb::kForWrite) != Acad::eOk ) {
				acutPrintf ("\nCannot open the object for write.") ;
				pNOD->close () ;
				return ;
			}
			// Check if someone has else has created an entry with our name
			// that is not a dictionary. This should never happen as long as
			// I use the registered developer RDS prefix.
			if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
				acutPrintf ("\nEntry found in the NOD, but it is not a dictionary.") ;
				pO->close () ;
				pNOD->close () ;
				return ;
			}
		}
		pNOD->close () ;
		// Check if a record with this key is already there
		if ( pEmployeeDict->getAt (strID, idO) == Acad::eOk ) {
			acutPrintf ("\nThis employee is already registered.") ;
			pEmployeeDict->close () ;
			return ;
		}
		// Let's add the new record. Append an empty xrecord.
		AcDbXrecord *pEmployeeEntry =new AcDbXrecord ;
		if ( pEmployeeDict->setAt (strID, pEmployeeEntry, idO) != Acad::eOk ) {
			acutPrintf ("\nFailed to add the new employee in the dictionary.") ;
			delete pEmployeeEntry ;
			pEmployeeDict->close () ;
			return ;
		}
		pEmployeeEntry->close () ;
		pEmployeeDict->close () ;
	}

	// - AsdkStep04._MyLISTENTRIES command (do not rename)
	static void AsdkStep04_MyLISTENTRIES(void)
	{
		// Add your code for command AsdkStep04._MyLISTENTRIES here
		AcDbDictionary *pNOD ;
		if ( acdbHostApplicationServices()->workingDatabase ()->getNamedObjectsDictionary (pNOD, AcDb::kForRead) != Acad::eOk ) {
			acutPrintf ("\nUnable to open the NOD! Aborting...") ;
			return ;
		}
		// See if our dictionary is already there
		AcDbObjectId idO ;
		AcDbObject* pO;
		if ( pNOD->getAt ("ASDK_EMPLOYEE_DICTIONARY", idO) != Acad::eOk ) {
			acutPrintf ("\nNo dictionary, no entry to remove...") ;
			pNOD->close () ;
			return ;
		}
		// Get employee dictionary for read
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk ) {
			acutPrintf ("\nCannot open the object for write.") ;
			pNOD->close () ;
			return ;
		}
		// Check if someone has else has created an entry with our name
		// that is not a dictionary. This should never happen as long as
		// I use the registered developer RDS prefix.
		AcDbDictionary *pEmployeeDict ;
		if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
			acutPrintf ("\nEntry found in the NOD, but it is not a dictionary.") ;
			pO->close () ;
			pNOD->close () ;
			return ;
		}
		pNOD->close () ;

		AcDbDictionaryIterator *pIter ;
		if ( (pIter =pEmployeeDict->newIterator (AcRx::kDictCollated)) != NULL ) {
			for ( ; !pIter->done () ;pIter->next () ) {
				// Print name
				acutPrintf ("*Employee: %s\n", pIter->name ()) ;
			}
			delete pIter ;
		}

		pEmployeeDict->close () ;
	}

	// - AsdkStep04._MyREMOVEENTRY command (do not rename)
	static void AsdkStep04_MyREMOVEENTRY(void)
	{
		// Add your code for command AsdkStep04._MyREMOVEENTRY here
		char strID [133] ;
		if ( acedGetString (0, "Enter employee name: ", strID) != RTNORM )
			return ;
		// Get the named object dictionary
		AcDbDictionary *pNOD ;
		if ( acdbHostApplicationServices()->workingDatabase ()->getNamedObjectsDictionary (pNOD, AcDb::kForRead) != Acad::eOk ) {
			acutPrintf ("\nUnable to open the NOD! Aborting...") ;
			return ;
		}
		// See if our dictionary is already there
		AcDbObjectId idO ;
		AcDbObject* pO;
		if ( pNOD->getAt ("ASDK_EMPLOYEE_DICTIONARY", idO) != Acad::eOk ) {
			acutPrintf ("\nNo dictionary, no entry to remove...") ;
			pNOD->close () ;
			return ;
		}
		// Get employee dictionary for read
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForRead) != Acad::eOk ) {
			acutPrintf ("\nCannot open the object for write.") ;
			pNOD->close () ;
			return ;
		}
		// Check if someone has else has created an entry with our name
		// that is not a dictionary. This should never happen as long as
		// I use the registered developer RDS prefix.
		AcDbDictionary *pEmployeeDict ;
		if ( (pEmployeeDict =AcDbDictionary::cast (pO)) == NULL ) {
			acutPrintf ("\nEntry found in the NOD, but it is not a dictionary.") ;
			pO->close () ;
			pNOD->close () ;
			return ;
		}
		pNOD->close () ;
		// Check if a record with this key is there
		if ( pEmployeeDict->getAt (strID, idO) != Acad::eOk ) {
			acutPrintf ("\nEntry not found.") ;
			pEmployeeDict->close () ;
			return ;
		}
		pEmployeeDict->close () ;
		// Get it for write 
		if ( acdbOpenAcDbObject (pO, idO, AcDb::kForWrite) != Acad::eOk ) {
			acutPrintf ("\nEntry cannot be opened for write.") ;
			return ;
		}
		// And erase it
		pO->erase () ;
		pO->close () ;
	}
} ;

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CStep04App)

ACED_ARXCOMMAND_ENTRY_AUTO(CStep04App, AsdkStep04, _MyADDENTRY, MyADDENTRY, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep04App, AsdkStep04, _MyLISTENTRIES, MyLISTENTRIES, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CStep04App, AsdkStep04, _MyREMOVEENTRY, MyREMOVEENTRY, ACRX_CMD_TRANSPARENT, NULL)

⌨️ 快捷键说明

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