[每日一码] ARX实例代码 -- 使用ARX转写VLISP同功能的VLA-函数
问题:我想把VLISP的VLA-开头的一些函数用ARX转写,我想获得INSERT实体的比例、旋转角,能否给我一个例子代码?下面是我的LISP代码。
普通浏览复制代码
(setq pntCenter (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint IAcadBlockRef)))
dAngle (vla-get-Rotation IAcadBlockRef)
dXScale (vla-get-XScaleFactor IAcadBlockRef)
解决方案:
下面的代码能够做你的要求,同时使用了“聪明”的指针,确保你打开对象操作后忘记关闭对象。
普通浏览复制代码
// extract some data from a Block Reference using ObjectARX, by Fenton Webb, DevTech, 20/12/2010
void GetBlockReferenceDetails()
{
ads采用name ename; ads采用point pt;
// select the block off the screen in AutoCAD
int res = acedEntSel(L"\nSelect INSERT: ", ename, pt);
// if ok
if (res == RTNORM)
{
// then convert the old ename to an ObjectARX ObjectId22
AcDbObjectId objId;
acdbGetObjectId(objId, ename);
// now open the object for read
AcDbObjectPointer<AcDbBlockReference> blockRef(AcDb::kForRead);
// if it opened ok
if (blockRef.openStatus() == Acad::eOk)
{
// extract the data from the block reference
AcGePoint3d insPnt = blockRef->position();
double rotation = blockRef->rotation();
AcGeScale3d xScale = blockRef->scaleFactors();
}
}
}
页:
[1]