- 积分
- 23668
- 明经币
- 个
- 注册时间
- 2011-2-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 zdqwy19 于 2014-8-18 16:51 编辑
acrxEntryPoint.cpp文件- // (C) Copyright 2002-2012 by Autodesk, Inc.
- //-----------------------------------------------------------------------------
- //----- acrxEntryPoint.cpp
- //-----------------------------------------------------------------------------
- #include "StdAfx.h"
- #include "resource.h"
- #include "CreateEnt.h"
- #include "ModifyEnt.h"
- #include <vector>
- #pragma once;
- using namespace std;
- //-----------------------------------------------------------------------------
- #define szRDS _RXST("")
- //-----------------------------------------------------------------------------
- //----- ObjectARX EntryPoint
- class CtxbhApp : public AcRxArxApp {
- public:
- CtxbhApp () : 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 () {}
- static void MyGroup_test () {
- // Put your command code here
- AcGePoint3d pt(0,0,0);
- vector<AcGePoint3d> pts;
- for(int i=0;i<12360;++i)
- {
- pts.push_back(pt);
- pt.x+=10;
- pt.y+=10;
- }
- int bstart=1;
- for(vector<AcGePoint3d>::iterator j=pts.begin();j!=pts.end();++j)
- {
- ACHAR str[10];
- AcDbObjectId textId;
- acdbRToS(bstart,-1,-1,str);
- textId = CCreateEnt::CreateText((*j),str,7);
- CModifyEnt::ChangeColor(textId, 3);
- CModifyEnt::ChangeWidthFactor(textId, 0.7);
- bstart=bstart+1;
- }
- }
-
-
- } ;
- //-----------------------------------------------------------------------------
- IMPLEMENT_ARX_ENTRYPOINT(CtxbhApp)
- ACED_ARXCOMMAND_ENTRY_AUTO(CtxbhApp, MyGroup, _test, test, ACRX_CMD_MODAL, NULL)
CreateEnt.h文件- #include "StdAfx.h"
- #pragma once
- // CCreateEnt
- class CCreateEnt
- {
- public:
- // 在模型空间添加实体;
- static AcDbObjectId PostToModelSpace(AcDbEntity* pEnt);
- //写入单行文字;
- static AcDbObjectId CreateText(const AcGePoint3d& ptInsert,const ACHAR* text,double height);
- CCreateEnt();
- virtual ~CCreateEnt();
- };
复制代码 CreateEnt.cpp文件- #include "StdAfx.h"
- // CreateEnt.cpp : 实现文件;
- //
- #include "stdafx.h"
- #include "CreateEnt.h"
- // CCreateEnt
- // 将实体添加到图形数据库的模型空间;
- AcDbObjectId CCreateEnt::PostToModelSpace(AcDbEntity* pEnt)
- {
- AcDbBlockTable *pBlockTable;
- acdbHostApplicationServices()->workingDatabase()
- ->getBlockTable(pBlockTable, AcDb::kForRead);
- AcDbBlockTableRecord *pBlockTableRecord;
- pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
- AcDb::kForWrite);
- AcDbObjectId entId;
- pBlockTableRecord->appendAcDbEntity(entId, pEnt);
- pBlockTable->close();
- pBlockTableRecord->close();
- pEnt->close();
- return entId;
- }
- // 写入单行文字;
- AcDbObjectId CCreateEnt::CreateText(const AcGePoint3d& ptInsert,const ACHAR* text,double height)
- {
- AcDbObjectId style = AcDbObjectId::kNull;
- double rotation = 0;
- AcDbText *pText =new AcDbText(ptInsert,text,style,height,rotation);
- return CCreateEnt::PostToModelSpace(pText);
- }
- CCreateEnt::CCreateEnt(){}
- CCreateEnt::~CCreateEnt(){}
- // CCreateEnt 消息处理程序;
复制代码 ModifyEnt.h文件- #include "StdAfx.h"
- #pragma once
- // CModifyEnt
- class CModifyEnt
- {
- public:
- static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex);//更改实体颜色;
- static Acad::ErrorStatus ChangeWidthFactor(AcDbObjectId entId, double WidthFactor);//更改文字宽高比;
- CModifyEnt();
- virtual ~CModifyEnt();
- };
复制代码 ModifyEnt.cpp文件- // ModifyEnt.cpp : 实现文件;
- //
- #include "stdafx.h"
- #include "ModifyEnt.h"
- // CModifyEnt
- //更改实体颜色;
- Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex)
- {
- AcDbEntity *pEntity;
- // 打开图形数据库中的对象;
- acdbOpenObject(pEntity, entId, AcDb::kForWrite);
- // 修改实体的颜色;
- pEntity->setColorIndex(colorIndex);
- // 用完之后,及时关闭;
- pEntity->close();
- return Acad::eOk;
- }
- //更改文字宽高比;
- Acad::ErrorStatus CModifyEnt::ChangeWidthFactor(AcDbObjectId entId, double WidthFactor)
- {
- AcDbEntity *pEntity;
- // 打开图形数据库中的对象;
- acdbOpenObject(pEntity, entId, AcDb::kForWrite);
- // 修改文字宽高比;
- if(pEntity->isKindOf(AcDbText::desc()))
- {
- AcDbText *pText = AcDbText::cast(pEntity);
- pText->setWidthFactor(WidthFactor);
- }
- // 用完之后,及时关闭;
- pEntity->close();
- return Acad::eOk;
- }
- CModifyEnt::CModifyEnt()
- {
- }
- CModifyEnt::~CModifyEnt()
- {
- }
- // CModifyEnt 消息处理程序;
复制代码 上面5段代码合在一起的压缩文件:
用于测试的图形
现在是这样情况,我手头三台电脑:
1、安装win7x64+cad2014;
2、安装win7x86+cad2007;
3、安装winXPx86+cad2008;
三台电脑在新建的空白文件上运行上述代码都没有问题;1#机在test.dwg中运行上述代码也没有问题;2#机和3#机在test.dwg中运行上述代码就引起cad崩溃,提示acad.exe缓冲区溢出。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|