CAD ObjectARX二次开发之绘制第一条直线
作者:互联网
一、配置命令环境
参考此教程配置:https://www.cnblogs.com/chenshuangjian/p/16450346.html
二、代码编写
工程目录结构:
代码编写:
// (C) Copyright 2002-2007 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"
//-----------------------------------------------------------------------------
#define szRDS _RXST("Arx")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CDemo_DrawLineApp : public AcRxArxApp {
public:
CDemo_DrawLineApp () : 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 () {
}
// - ArxDemo_DrawLine._MyCommand1 command (do not rename)
static void ArxDemo_DrawLine_MyCommand1(void)
{
// Add your code for command ArxDemo_DrawLine._MyCommand1 here
AcGePoint3d P1(0,0,0);
AcGePoint3d P2(10,10,10);
//定义直线
AcDbLine *pLine = new AcDbLine(P1,P2);
AcDbBlockTable *pBlockTable =NULL;
//获取块表
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBockTableRecord = NULL;
//获取模型空间块表记录
pBlockTable->getAt(ACDB_MODEL_SPACE,pBockTableRecord,AcDb::kForWrite);
AcDbObjectId lineId;
//将直线添加到块表记录
pBockTableRecord->appendAcDbEntity(lineId,pLine);
//关闭释放资源
pBlockTable->close();
pBockTableRecord->close();
pLine->close();
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CDemo_DrawLineApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CDemo_DrawLineApp, ArxDemo_DrawLine, _MyCommand1, MyCommand1, ACRX_CMD_TRANSPARENT, NULL)
三、编译测试
标签:MyCommand1,code,pkt,void,here,ObjectARX,---------------------------------------- 来源: https://www.cnblogs.com/chenshuangjian/p/16450365.html