
(2) 在“Project Settings”对话框中选择“Setting For:”下拉列表的“All Configurations”项。
(3) 在“Project Settings”对话框中选择“C/C++”选项卡。
(4) 在“Category:”下拉列表中选择“Code Generation”项。然后选中“Use run-time library”下拉列表中的“Multithreaded DLL”选项(如图38-6所示)。再在“Category:”下拉列表框中选择“Preprocessor”项,然后在“Preprocessor definitions:”编辑框中内容的后面添加“ACRXAPP,RADPACK”,表示需要预链接的库(如图38-7所示)。
(5) 在“Project Settings”对话框中选择“Link”选项卡。
(6) 在“Category:”下拉列表中选择“General”项,然后在“Output file name:”编辑框中键入应用程序名“.\HelloARX.arx”(图38-8);在“Object/library modules:”编辑框中添加“acutil15.lib acrx15.lib acdb15.lib acedapi.lib rxapi.lib acad.lib acge15.lib”;在“Category:”下拉列表框中选择“Output”项,然后在“Base address:”编辑框中键入“0x1c000000”(图38-9)。
(7) 完成上述步骤后,单击OK按钮确定设置。
Step 6 编译和建立ARX程序
选择菜单命令【Build】→【Build HelloARX】,编译和建立Hello.arx程序。
Step 7 加载并运行首汪ARX程序
(1) 在AutoCAD 2002环境中,选择菜单命令【Tools(工具)】→【Load Application…(加载应用程序带乱)】,d出“Load/Unload Applications(加载/卸载应用程序)”对话框。
(2) 选中“Hello.arx”文件,单击Load...按钮。
(3) 单击Close按钮返回AutoCAD主窗口。
(4) 在命令行中输入命令“Hello”,将在命令行中出现“Hello, Object ARX!”。蠢芹档
(5) 如果需要卸载程序,则再d出“Load/Unload Applications(加载/卸载应用程序)”对话框,如图38-10所示。在“Loaded Applications(已加载应用程序)”选项卡内选择“Hello.ARX”程序,单击Unload按钮,则该程序被卸载。
使用ARX的向导创建一个ARX项目,增悄岁加一个命令,在命令函数中实现如下代码即可启蔽睁。void ShowARCInfo()
{
ads_point adsPt
ads_name entName
AcDbObjectId entId
AcDbEntity* pEnt
if(acedEntSel(_T("\n请选择圆或圆弧或<退出>:"), entName, adsPt) != RTNORM)
return FALSE
acdbGetObjectId(entId, entName)
if (acdbOpenObject(pEnt, entId, AcDb::kForRead) != Acad::eOk)
return FALSE
if(pEnt->isKindOf(AcDbArc::desc()) || pEnt->isKindOf(AcDbCircle::desc()))
{
AcDbArc* pArc = (AcDbArc*)pEnt
double dR = pArc->radius()
AcGePoint3d ptCen = pArc->center()
double dStartAngle = pArc->startAngle()
double dEndAngle = pArc->endAngle()
// 下面将上面的参数传递到对话框中显示即可。
...
}
else
{
ads_printf(_T("\n所选实体并非是圆并局或圆弧!"))
}
pEnt->close()
}
你自己已经解决了这样就可以了,
void CAddBlock::OnOK()
{
CDialog::OnOK()
//获得要插入的块名
CString blockname
m_listctrl.GetLBText(m_listctrl.GetCurSel(),blockname)
//blockname = "CHART-20"
//寻找是否已经定义
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase()
AcDbBlockTable *pBlkTable
AcDbObjectId blockId
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)
if(!pBlkTable->has(blockname))
{
pBlkTable->close()
AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse)
char dir[MAX_PATH]
GetModuleFileName(NULL,dir,MAX_PATH)
dir[CString(dir).ReverseFind('\')]='\0'
//AfxMessageBox(CString(dir)+"\\survingpack\\"+blockname+".dwg")
pDwg->readDwgFile (CString(dir)+"段隐毁\\survingpack\\"+blockname+".dwg")
Acad::ErrorStatus es = pCurDb->insert (blockId, blockname, pDwg)//, Adesk::kFalse) //
delete pDwg
if ( es != Acad::eOk )
{
acutPrintf ("\n插入块错误携厅.")
return
}
}
else
pBlkTable->getAt(blockname, blockId)
BeginEditorCommand()
//ShowWindow(SW_HIDE)
ads_point pt={0,0,0}
int rc=acedGetPoint(NULL,"\n选择插入点:",pt)
if (rc==RTCAN||rc==RTNONE)
{
acutPrintf("\n*取消了插入 *** 作*")
CancelEditorCommand()
return
}
CompleteEditorCommand()
//---- 设置插入点,旋转角度,比例等等
AcDbBlockReference *pBlkRef =new AcDbBlockReference(AcGePoint3d(pt[0],pt[1],pt[2]),blockId)
//pBlkRef->setBlockTableRecord (blockId)
pBlkRef->握备setScaleFactors(AcGeScale3d(m_scale,m_scale,1))
//pBlkRef->setPosition(AcGePoint3d(pt[0],pt[1],pt[2]))
pBlkRef->setRotation (m_angle)
pBlkRef->setLayer(NULL)//设置图层
//获得模型空间块表记录
AcDbBlockTable *pBlockTable
acdbHostApplicationServices()->workingDatabase()->getBlockTable (pBlockTable, AcDb::kForRead)
AcDbBlockTableRecord *pBlockTableRecord
pBlockTable->getAt (ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite)
pBlockTable->close ()
pBlockTableRecord->appendAcDbEntity(pBlkRef)
//获得属性
AcDbBlockTableRecord *pBlkDefRecord
acdbOpenObject(pBlkDefRecord, blockId, AcDb::kForRead)
if(pBlkDefRecord->hasAttributeDefinitions())
{
//AcDbObjectIterator* pBlkIterator = pBlkRef->attributeIterator()//修改
AcDbBlockTableRecordIterator *pIterator
pBlkDefRecord->newIterator(pIterator)
for(pIterator->start()!pIterator->done()pIterator->step())
{
AcDbEntity *pEnt
pIterator->getEntity(pEnt, AcDb::kForRead)
AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt)
if(pAttDef != NULL &&!pAttDef->isConstant())
{
AcDbAttribute* pAtt = new AcDbAttribute()
pAtt->setPropertiesFrom(pAttDef)
pAtt->setInvisible( pAttDef->isInvisible() )
pAtt->setHorizontalMode(pAttDef->horizontalMode())
pAtt->setVerticalMode(pAttDef->verticalMode())
/* AcGePoint3d basePt = pAttDef->position()
basePt[0]+=pt[0]
basePt[1]+=pt[1]
basePt[2]+=pt[2]
pAtt->setPosition(basePt)
*/
AcGePoint3d basePt = pAttDef->alignmentPoint()
basePt[0]+=pt[0]
basePt[1]+=pt[1]
basePt[2]+=pt[2]
pAtt->setAlignmentPoint(basePt)
pAtt->setHeight(pAttDef->height())
pAtt->setTextStyle(pAttDef->textStyle())
pAtt->setTag(pAttDef->tag())
pAtt->setTextString(m_attrib)
pAtt->setFieldLength(25)
pBlkRef->appendAttribute(pAtt)
pAtt->close()
pEnt->close()
}
}
delete pIterator
}//end if pBlkDefRecord->hasAttributeDefinitions
pBlkDefRecord->close()
pBlockTableRecord->close()
pBlkRef->close()
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)