CAD ObjectArx开发之可停靠选项板
环境:VS2010 + CAD2014
创建思路
1、创建ObjectARX项目,支持MFC
2、使用ObjectARX向导创建基类为CAdUiPaletteSet和CAdUiPalette的窗体类
3、在acrxEntryPoint.cpp中编写代码
(1)、在cpp文件中定义全局窗体指针
(2)、在On_kInitAppMsg初始化函数中添加窗台构建代码
(3)、在On_kUnloadAppMsg卸载函数中添加窗体资源释放代码
编译时可能出现的问题:
(1)、编译时出现#import "msxml.dll" named_guids不存在的错误。解决办法:不同操作系统,这个库的名称不一样:向导默认是适配WIN7系统的,如果是WIN10系统,可以尝试改成msxml4.dll或者msxml6.dll,编程时可以一个个尝试
(2)、编译时出现error C2653: “MSXML”: 不是类或命名空间名称的错误。解决办法:在代码中自己在重新定义宏#define MSXML MSXML2
详细步骤
1、创建ObjectARX项目,支持MFC
2、使用ObjectARX向导创建基类为CAdUiPaletteSet和CAdUiPalette的窗体类
1、CAdUiPalette窗体
2、CAdUiPaletteSet窗体
3、在acrxEntryPoint.cpp中编写代码
完整代码段
// (C) Copyright 2002-2012 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.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "ArxAppMain.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//选项板
ArxAppPalette * pArxAppPalette = NULL;
ArxAppPaletteSet * pArxAppPaletteSet = NULL;
CAdUiPalette * pCAdUiPalette = NULL;
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CFW_ArxAppApp : public AcRxArxApp {
public:
CFW_ArxAppApp () : 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
acutPrintf(_T("初始化选项板"));
if(pArxAppPaletteSet == NULL){
//创建选项板集合
pArxAppPaletteSet = new ArxAppPaletteSet();
CRect rect(0,0,400,400);
pArxAppPaletteSet->Create(TEXT("工作空间"),WS_OVERLAPPED|WS_DLGFRAME,rect,acedGetAcadFrame(),PSS_EDIT_NAME|PSS_PROPERTIES_MENU|PSS_AUTO_ROLLUP|PSS_CLOSE_BUTTON);
//创建选项板
pArxAppPalette = new ArxAppPalette();
pCAdUiPalette = new CAdUiPalette();
pArxAppPalette->Create(WS_CHILD|WS_VISIBLE,TEXT("构件树"),pArxAppPaletteSet,PS_EDIT_NAME);
pArxAppPaletteSet->AddPalette(pArxAppPalette);
pCAdUiPalette->Create(WS_CHILD|WS_VISIBLE,TEXT("属性"),pArxAppPaletteSet,PS_EDIT_NAME);
pArxAppPaletteSet->AddPalette(pCAdUiPalette);
pArxAppPaletteSet->EnableDocking(CBRS_ALIGN_ANY);
pArxAppPaletteSet->RestoreControlBar();
acedGetAcadFrame()->ShowControlBar(pArxAppPaletteSet,TRUE,FALSE);
if(pArxAppPaletteSet->GetOpacity() != 100){
pArxAppPaletteSet->SetOpacity(100);
}
}
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
acutPrintf(_T("释放选项板"));
if(pArxAppPaletteSet != NULL){
pArxAppPaletteSet->DestroyWindow();
delete pArxAppPaletteSet;
pArxAppPaletteSet = NULL;
}
if(pArxAppPalette != NULL){
pArxAppPalette->DestroyWindow();
delete pArxAppPalette;
pArxAppPalette = NULL;
}
if(pCAdUiPalette != NULL){
pCAdUiPalette->DestroyWindow();
delete pCAdUiPalette;
pCAdUiPalette = NULL;
}
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
// The ACED_ARXCOMMAND_ENTRY_AUTO macro can be applied to any static member
// function of the CFW_ArxAppApp class.
// The function should take no arguments and return nothing.
//
// NOTE: ACED_ARXCOMMAND_ENTRY_AUTO has overloads where you can provide resourceid and
// have arguments to define context and command mechanism.
// ACED_ARXCOMMAND_ENTRY_AUTO(classname, group, globCmd, locCmd, cmdFlags, UIContext)
// ACED_ARXCOMMAND_ENTRYBYID_AUTO(classname, group, globCmd, locCmdId, cmdFlags, UIContext)
// only differs that it creates a localized name using a string in the resource file
// locCmdId - resource ID for localized command
// Modal Command with localized name
// ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL)
static void MyGroupMyCommand () {
// Put your command code here
acutPrintf(_T("Hello Arx"));
}
// Modal Command with pickfirst selection
// ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET)
static void MyGroupMyPickFirst () {
ads_name result ;
int iRet =acedSSGet (ACRX_T("_I"), NULL, NULL, NULL, result) ;
if ( iRet == RTNORM )
{
// There are selected entities
// Put your command using pickfirst set code here
}
else
{
// There are no selected entities
// Put your command code here
}
}
// Application Session Command with localized name
// ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION)
static void MyGroupMySessionCmd () {
// Put your command code here
acutPrintf(_T("Hello Arx"));
}
// The ACED_ADSFUNCTION_ENTRY_AUTO / ACED_ADSCOMMAND_ENTRY_AUTO macros can be applied to any static member
// function of the CFW_ArxAppApp class.
// The function may or may not take arguments and have to return RTNORM, RTERROR, RTCAN, RTFAIL, RTREJ to AutoCAD, but use
// acedRetNil, acedRetT, acedRetVoid, acedRetInt, acedRetReal, acedRetStr, acedRetPoint, acedRetName, acedRetList, acedRetVal to return
// a value to the Lisp interpreter.
//
// NOTE: ACED_ADSFUNCTION_ENTRY_AUTO / ACED_ADSCOMMAND_ENTRY_AUTO has overloads where you can provide resourceid.
//- ACED_ADSFUNCTION_ENTRY_AUTO(classname, name, regFunc) - this example
//- ACED_ADSSYMBOL_ENTRYBYID_AUTO(classname, name, nameId, regFunc) - only differs that it creates a localized name using a string in the resource file
//- ACED_ADSCOMMAND_ENTRY_AUTO(classname, name, regFunc) - a Lisp command (prefix C:)
//- ACED_ADSCOMMAND_ENTRYBYID_AUTO(classname, name, nameId, regFunc) - only differs that it creates a localized name using a string in the resource file
// Lisp Function is similar to ARX Command but it creates a lisp
// callable function. Many return types are supported not just string
// or integer.
// ACED_ADSFUNCTION_ENTRY_AUTO(CFW_ArxAppApp, MyLispFunction, false)
static int ads_MyLispFunction () {
//struct resbuf *args =acedGetArgs () ;
// Put your command code here
//acutRelRb (args) ;
// Return a value to the AutoCAD Lisp Interpreter
// acedRetNil, acedRetT, acedRetVoid, acedRetInt, acedRetReal, acedRetStr, acedRetPoint, acedRetName, acedRetList, acedRetVal
return (RTNORM) ;
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CFW_ArxAppApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CFW_ArxAppApp, MyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION, NULL)
ACED_ADSSYMBOL_ENTRY_AUTO(CFW_ArxAppApp, MyLispFunction, false)