我正在尝试在已运行的 AutoCAD 实例中绘制一个圆,并将其附加到现有图形中。
这可能吗?最简单的方法是什么?
四
最佳答案
正如您提到的“已运行的 AutoCAD 实例”,我假设您想要自动化 AutoCAD,通常是通过 ActiveX COM 自动化。您应该使用 AcadApplication 接口(interface)(并且不能使用 AcDb 或 .NET Mgd 引用)。
这是来自 this blog post 的 ActiveX C++ 通用代码示例。请注意 acac19enu.tlb 引用,其中 19 代表 AutoCAD 版本。当前版本是 AutoCAD 2017(库版本:21)。
#import "acax19ENU.tlb" no_namespace
#include <rxmfcapi.h>
#include <axpnt3d.h>
void fAddAttribute()
{
try
{
// get the ActiveX application object from AutoCAD, inc ref count
IAcadApplicationPtr pAcadApp = acedGetAcadWinApp()->GetIDispatch(TRUE);
// now get the active doc
IAcadDocumentPtr pActiveDoc = pAcadApp->ActiveDocument;
IAcadBlockPtr pBlock = NULL;
TCHAR *pBlkName = _T("some_block_name");
// create an activex compatible insertion point3d
AcAxPoint3d axInsPnt(0,0,0);
// now add the block name
pBlock = pActiveDoc->Blocks->Add(axInsPnt.asVariantPtr(),_bstr_t(pBlkName));
// now add an Attribute to the block
IAcadAttributePtr pAttDef;
pAttDef = pBlock->AddAttribute(1.0, (AcAttributeMode)0 ,
_bstr_t("Type the employee name"), axInsPnt.asVariantPtr(),
_bstr_t("empname"),_bstr_t(""));
//attribute added
}
catch(_com_error &es)
{
acutPrintf(L"\nError : %s", es.ErrorMessage());
}
}
关于c - 从 C 语言在 AutoCAD 中画一个圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793618/