用ObjectARX开发AutoCAD 应用程序 配套源码 老虎工作室.docx
- 文档编号:6685686
- 上传时间:2023-01-08
- 格式:DOCX
- 页数:84
- 大小:36.08KB
用ObjectARX开发AutoCAD 应用程序 配套源码 老虎工作室.docx
《用ObjectARX开发AutoCAD 应用程序 配套源码 老虎工作室.docx》由会员分享,可在线阅读,更多相关《用ObjectARX开发AutoCAD 应用程序 配套源码 老虎工作室.docx(84页珍藏版)》请在冰豆网上搜索。
用ObjectARX开发AutoCAD应用程序配套源码老虎工作室
老虎工作室实例
exam03画直线
获取用户输入点
exam04a打开已存在文件
建立浏览器
对象ID数组
获取当前块表指针
常事务处理普通快(改变部分实体属性)
exam04b交互选择实体
扩展数据加入
调用扩展数据
exam05a创建新块表记录
创建一带属性快
创建一属性实体
遍历块中实体
exam06a获取用户选择集
建立组,并向其中加入选择集实体
遍历并改变组实体
exam06b向字典对象中加入扩展集
调用扩展集数据
exam07建立基于MFC的对话框
拾取点
exam08建一基于AcdbObject的派生类
应用类向字典加入数据并提取
exam09建一基于拖动的类
实现拖动创建椭圆
exam10a建一临时数据库反映器
exam10b建派生于AcdbObject的派生类
建一有名对象词典纪录
将反映器对象加入词典纪录中
用addPersistanReactor附着实体
exam13派生于AcdbEntity画一自定义网格
exam14判断实体类型
交互选择实体
转化为AcGe对象
求实体交点
exam032
exam04a2
exam04b4
exam05a7
exam06a11
exam06b13
exam0715
exam0820
exam0923
exam10a25
exam10b26
exam1329
exam1432
exam03
#include
#include
#include
#include
#include
#include
#include
Acad:
:
ErrorStatusnewLine();
voidaddLineCommand()
{
//{{BEGIN_LEVEL_ADVANCED
if(newLine()==Acad:
:
eOk)
acutPrintf("Success\n");
else
acutPrintf("Failed\n");
//{{END_LEVEL_ADVANCED
}
Acad:
:
ErrorStatus
postToDatabase(/*[in]*/AcDbEntity*pEnt,/*[out]*/AcDbObjectId&idObj)
{
Acad:
:
ErrorStatuses;
AcDbBlockTable*pBlockTable;
AcDbBlockTableRecord*pSpaceRecord;
//确定当前有正在工作的数据库
if(acdbHostApplicationServices()->workingDatabase()==NULL)
returnAcad:
:
eNoDatabase;
//获得当前图形的指针
//获得图形的块表,打开准备读取数据
if((es=acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb:
:
kForRead))==Acad:
:
eOk){
//获得建模空间的记录,打开准备写数据
if((es=pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb:
:
kForWrite))==Acad:
:
eOk){
//添加实体指针到建模空间后关闭指针和建模空间记录
if((es=pSpaceRecord->appendAcDbEntity(idObj,pEnt))==Acad:
:
eOk)
pEnt->close();
pSpaceRecord->close();
}
//关闭块表
pBlockTable->close();
}
//返回状态信息
returnes;
}
Acad:
:
ErrorStatusnewLine()
{
ads_pointpt1,pt2;//定义两个ads_point的点
intretval;
try
{
//从用户处获得第一点
if((retval=acedGetPoint(NULL,"\nSelectlowerleft:
",pt1))!
=RTNORM)
throwretval;
//以第一点为基点,从用户处获得第二点.
if((retval=acedGetPoint(pt1,"\nSelectupperright:
",pt2))!
=RTNORM)
throwretval;
}
catch(inte)
{
if(e==RTCAN)
//判断输入错误程序中断
returnAcad:
:
eUserBreak;
if(e==RTERROR)
//判断无效输入
returnAcad:
:
eInvalidInput;
}
//将ads_point类型的点转换为AcGePoint3d类型之后创建直线
AcDbLine*pLine=newAcDbLine(asPnt3d(pt1),asPnt3d(pt2));
//如果创建直线出错,返回错误信息
if(!
pLine)
{
acedAlert("NotenoughmemorytocreateaLine!
");
returnAcad:
:
eOutOfMemory;
}
AcDbObjectIdid;//定义对象ID
returnpostToDatabase(pLine,id);
}
extern"C"AcRx:
:
AppRetCode
acrxEntryPoint(AcRx:
:
AppMsgCodemsg,void*pkt)
{
switch(msg){
caseAcRx:
:
kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
//注册命令
acedRegCmds->addCommand("EXAM03","addline","addline",ACRX_CMD_MODAL,addLineCommand);
break;
caseAcRx:
:
kUnloadAppMsg:
//当应用程序卸载后,为防止AUOTCAD调用此命令,产生不必要的
//错误,移走命令组
acedRegCmds->removeGroup("EXAM03");
break;
}
returnAcRx:
:
kRetOK;
}
exam04a
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void
refEdit()
{
AcDbObjectIdtransId;
AcDbDatabase*pDb;
char*fname;
structresbuf*rb;
rb=acutNewRb(RTSTR);
intstat=acedGetFileD("Pickadrawing",NULL,"dwg",0,rb);
if((stat!
=RTNORM)||(rb==NULL))
{
acutPrintf("\nYoumustpickadrawingfile.");
return;
}
fname=(char*)acad_malloc(strlen(rb->resval.rstring)+1);
strcpy(fname,rb->resval.rstring);
acutRelRb(rb);
pDb=newAcDbDatabase(Adesk:
:
kFalse);
if(pDb->readDwgFile(fname)!
=Acad:
:
eOk)
{
acutPrintf("\nSorry,thatdraingisprobablyalreadyopen.");
return;
}
AcDbBlockTable*pBlockTable;
pDb->getSymbolTable(pBlockTable,AcDb:
:
kForRead);
AcDbBlockTableRecord*pOtherMsBtr;
pBlockTable->getAt(ACDB_MODEL_SPACE,pOtherMsBtr,AcDb:
:
kForRead);
pBlockTable->close();
AcDbBlockTableRecordIterator*pIter;
pOtherMsBtr->newIterator(pIter);
AcDbObjectIdArrayobjIdArray;
for(pIter->start();!
pIter->done();pIter->step()){
AcDbEntity*pEntity;
pIter->getEntity(pEntity,AcDb:
:
kForRead);
if(pEntity->isKindOf(AcDbCircle:
:
desc())){
objIdArray.append(pEntity->objectId());
}
pEntity->close();
}
deletepIter;
pOtherMsBtr->close();
if(objIdArray.isEmpty()){
acad_free(fname);
acutPrintf("\nYoumustpickadrawingfilethatcontainscircles.");
return;
}
AcDbBlockTable*pThisBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pThisBlockTable,AcDb:
:
kForRead);
AcDbBlockTableRecord*pThisMsBtr;
pThisBlockTable->getAt(ACDB_MODEL_SPACE,pThisMsBtr,AcDb:
:
kForWrite);
pThisBlockTable->close();
AcDbObjectIdid=pThisMsBtr->objectId();
pThisMsBtr->close();
AcDbIdMappingerrorMap;
acapLongTransactionManagerPtr()->checkOut(transId,objIdArray,id,errorMap);
intcolorIndex;
doubleradius;
acedGetInt("\nEntercolornumbertocirclescenterline:
",&colorIndex);
acedGetReal("\nEntercircleradius:
",&radius);
if(radius<=0)
{
acutPrintf("\nError:
Radiuscan'tlessthan0!
");
return;
}
AcDbObject*pObj;
if(acdbOpenObject(pObj,transId,AcDb:
:
kForRead)==Acad:
:
eOk)
{
AcDbLongTransaction*pLongTrans=AcDbLongTransaction:
:
cast(pObj);
if(pLongTrans!
=NULL)
{
AcDbLongTransWorkSetIterator*pWorkSetIter;
pLongTrans->newWorkSetIterator(pWorkSetIter);
for(pWorkSetIter->start();!
pWorkSetIter->done();pWorkSetIter->step())
{
AcDbEntity*pEntity;
acdbOpenAcDbEntity(pEntity,pWorkSetIter->objectId(),AcDb:
:
kForWrite);
pEntity->setColorIndex(colorIndex);
((AcDbCircle*)pEntity)->setRadius(radius);
pEntity->close();
}
deletepWorkSetIter;
}
pObj->close();
}
charstr[132];
acedGetString(0,"\nSeethenewcolorsandradius.Pressreturntoback",str);
acapLongTransactionManagerPtr()->checkIn(transId,errorMap);
pDb->saveAs(fname);
deletepDb;
pDb=NULL;
acad_free(fname);
}
void
initApp()
{
acedRegCmds->addCommand("EXAM04A",
"LONGTRANS",
"LONGTRANS",
ACRX_CMD_MODAL,
refEdit);
}
voidunloadApp()
{
acedRegCmds->removeGroup("EXAM04A");
}
extern"C"AcRx:
:
AppRetCode
acrxEntryPoint(AcRx:
:
AppMsgCodemsg,void*appId)
{
switch(msg){
caseAcRx:
:
kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
caseAcRx:
:
kUnloadAppMsg:
unloadApp();
break;
caseAcRx:
:
kLoadDwgMsg:
break;
caseAcRx:
:
kUnloadDwgMsg:
break;
caseAcRx:
:
kInvkSubrMsg:
break;
default:
;
}
returnAcRx:
:
kRetOK;
}
exam04b
#include
#include
#include
#include
#include
#include
#include
#include"acestext.h"
voidprintXdata();
voidaddXdata();
voidprintList(structresbuf*pRb);
AcDbObject*selectObject(AcDb:
:
OpenModeopenMode);
voidinitApp();
voidunloadApp();
extern"C"
AcRx:
:
AppRetCodeacrxEntryPoint(AcRx:
:
AppMsgCode,void*);
void
printXdata()
{
AcDbObject*pObj;
if((pObj=selectObject(AcDb:
:
kForRead))==NULL){
return;
}
charappname[133];
if(acedGetString(NULL,
"\nEnterthedesiredXdataapplicationname:
",
appname)!
=RTNORM)
{
return;
}
structresbuf*pRb;
pRb=pObj->xData(appname);
if(pRb!
=NULL){
printList(pRb);
acutRelRb(pRb);
}else{
acutPrintf("\nNoxdataforthisappname");
}
pObj->close();
}
void
addXdata()
{
AcDbObject*pObj=selectObject(AcDb:
:
kForRead);
if(!
pObj){
acutPrintf("Errorselectingobject\n");
return;
}
charappName[132],resString[200];
appName[0]=resString[0]='\0';
acedGetString(NULL,"Enterapplicationname:
",
appName);
acedGetString(NULL,"Enterstringtobeadded:
",
resString);
structresbuf*pRb,*pTemp;
pRb=pObj->xData(appName);
if(pRb!
=NULL){
for(pTemp=pRb;pTemp->rbnext!
=NULL;
pTemp=pTemp->rbnext)
{;}
}else{
acdbRegApp(appName);
pRb=acutNewRb(AcDb:
:
kDxfRegAppName);
pTemp=pRb;
pTemp->resval.rstring
=(char*)malloc(strlen(appName)+1);
strcpy(pTemp->resval.rstring,appName);
}
pTemp->rbnext=acutNewRb(AcDb:
:
kDxfXdAsciiString);
pTemp=pTemp->rbnext;
pTemp->resval.rstring
=(char*)malloc(strlen(resString)+1);
strcpy(pTemp->resval.rstring,resString);
pObj->upgradeOpen();
pObj->setXData(pRb);
pObj->close();
acutRelRb(pRb);
}
void
printList(structresbuf*pRb)
{
intrt,i;
charbuf[133];
for(i=0;pRb!
=NULL;i++,pRb=pRb->rbnext){
if(pRb->restype<1010){
rt=RTSTR;
}elseif(pRb->restype<1040){
rt=RT3DPOINT;
}elseif(pRb->restype<1060){
rt=RTREAL;
}elseif(pRb->restype<1071){
rt=RTSHORT;
}elseif(pRb->restype==1071){
rt=RTLONG;
}else{
rt=pRb->restype;
}
switch(rt){
caseRTSHORT:
if(pRb->restype==RTSHORT){
acutPrintf(
"RTSHORT:
%d\n",pRb->resval.rint);
}else{
acutPrintf("(%d.%d)\n",pRb->restype,
pRb->resval.rint);
};
break;
caseRTREAL:
if(pRb->restype==RTREAL){
acutPrintf("RTREAL:
%0.3f\n",
pRb->resval.rreal);
}else{
acutPrintf("(%d.%0.3f)\n",pRb->restype,
pRb->resval.rreal);
};
break;
caseRTSTR:
if(pRb->restype==RTSTR){
acutPrintf("RTSTR:
%s\n",
pRb->resval.rstring);
}else{
acutPrintf("(%d.\"%s\")\n",pRb->restype,
pRb->resval.rstring);
};
break;
caseRT3DPOINT:
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]
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 用ObjectARX开发AutoCAD 应用程序 配套源码 老虎工作室 ObjectARX 开发 AutoCAD 配套 源码 老虎 工作室