bzxy08 发表于 2013-1-7 10:35:00

求函数AcAxGetBoundingBox的正确用法

最近做个计算文本实体的文字长度的功能,用到AcAxGetBoundingBox这个函数,
但是函数返回一直失败(S_FALSE),有哪位朋友知道这个函数的标准用法的,
希望不吝赐教,万分感谢.
下面是我的部分代码
bool CToolFunction::getTextLength(AcDbObjectId TextId, double& textlength)
{
      VARIANT                        X1_VarTmp;
      SAFEARRAY *                X1_ArrTmp;
      double *                X1_buf;
      X1_ArrTmp = ::SafeArrayCreateVectorEx(VT_R8, 1, 2, NULL);
      X1_VarTmp.vt = VT_ARRAY | VT_R8;
      X1_VarTmp.parray = X1_ArrTmp;
      ::SafeArrayAccessData(X1_ArrTmp, (void **)&X1_buf);
      VARIANT                        X2_VarTmp;
      SAFEARRAY *                X2_ArrTmp;
      double *                X2_buf;
      X2_ArrTmp = ::SafeArrayCreateVectorEx(VT_R8, 1, 2, NULL);
      X2_VarTmp.vt = VT_ARRAY | VT_R8;
      X2_VarTmp.parray = X2_ArrTmp;
      ::SafeArrayAccessData(X2_ArrTmp, (void **)&X2_buf);
      HRESULT slt;
      slt = AcAxGetBoundingBox(TextId, &X1_VarTmp, &X2_VarTmp);
      AcGePoint3d ptMin;
      AcGePoint3d ptMax;
      if (slt)
      {
                ptMin = AcGePoint3d(X1_buf, X1_buf, 0.0);
                ptMax = AcGePoint3d(X2_buf, X2_buf, 0.0);
                textlength = abs(ptMax.x - ptMin.x);
                ::SafeArrayDestroy(X1_ArrTmp);
                ::SafeArrayDestroy(X2_ArrTmp);
                return true;
      }
      else
      {
                textlength = 0.0;
                ::SafeArrayDestroy(X1_ArrTmp);
                ::SafeArrayDestroy(X2_ArrTmp);
                return false;
      }
}

luowy 发表于 2013-1-11 11:16:00

干嘛用com的?
acedTextBox就可以了,
传送门【http://objectarx.net/forum.php?mod=viewthread&tid=4044&extra=】
页: [1]
查看完整版本: 求函数AcAxGetBoundingBox的正确用法