gswang 发表于 2010-8-8 09:44:18

自定义实体问题

我有 3 个文件:MyDbxCust.dbx、MyArxCust.arx、MyComCust.dbx
问题:运行我的 ADS 命令
   命令:(custgcd)
   “选择点:”
   选择一个点,画一个点,我的自定义实体 DXF_Name 是“高程点”,我想在对象属性管理器中显示我的 DXF_NAME,怎么做?

Nico 发表于 2010-8-10 02:31:37

在包装类中 使用函数GetDisplayName 。
例如:
h-file
STDMETHOD(GetDisplayName) (DISPID dispId, BSTR *propName);
cpp-file:
STDMETHODIMP CAcDbRopeWraper::GetDisplayName (DISPID dispId, BSTR *propName)
{
switch (dispId)
{
    case (0x401): // this is the object name identifier
      *propName= ::SysAllocString(_T("高程点"));
      break;
//...
}
}

gswang 发表于 2010-8-10 19:31:00

SDK中有几个示例,请参见SDK\samples\com中的AsdkSquareWrapper和

samples\entity\polysamp(samples\ entity\polysamp\compoly)

polysample有很多优点,因为它展示了如何构建COM和.NET包装器,以及属性调色板的IOPMPropertyxxx内容。

LE3 发表于 2010-8-11 07:03:47

谢谢你,我试试。

gswang 发表于 2010-8-12 08:47:15

按照你的提示,我成功了。

gswang 发表于 2010-8-20 07:33:30

我的自定义实体是 CMyGCD,但是当我运行 (entget ent) 时,返回的列表是:
((-1 . ) (0 . "高程点") (330 . ) (5 . "22F")
(100 . "AcDbEntity ") (67 . 0) (410 . "模型") (8 . "0") (100 . "AcDbCircle")
(10 0.0 0.0 0.0) (40 . 30.0) (210 0.0 0.0 1.0) (90 . 1) )
但它的实际坐标不是 '(0.0 0.0 0.0) ,请给我一些建议。

gswang 发表于 2010-8-21 08:49:27

您可能需要覆盖这些函数

virtual Acad::ErrorStatusdxfInFields(AcDbDxfFiler* filer);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* filer) const;

LE3 发表于 2010-8-21 22:14:43

谢谢,我覆盖了 dxfInFIelds 和 dxfOutFields,

//- Dxf Filing protocol
Acad::ErrorStatus CMyGcd::dxfOutFields (AcDbDxfFiler *pFiler) const {
      assertReadEnabled () ;
      //----- Save parent class information first.
      Acad::ErrorStatus es =AcDbCircle::dxfOutFields (pFiler) ;
      if ( es != Acad::eOk )
                return (es) ;
      es =pFiler->writeItem (AcDb::kDxfSubclass, _RXST("CMyGcd")) ;
      if ( es != Acad::eOk )
                return (es) ;
      //----- Object version number needs to be saved first
      if ( (es =pFiler->writeUInt32 (kDxfInt32, CMyGcd::kCurrentVersionNumber)) != Acad::eOk )
                return (es) ;
      //----- Output params
      //.....
      pFiler->writePoint3d(AcDb::kDxfXCoord, mCenter);   //mycode
      return (pFiler->filerStatus ()) ;
}
但是entget数据列表是:
((-1 . ) (0 . "高程点") (330 . ) (5 . "22F")
(100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle")
(10 0.0 0.0 0.0)(40 . 0.0) (210 0.0 0.0 1.0) (100 . "CMyGcd") (90 . 1)
(10 2228.71 1228.61 0.0) )
有两个 10 DXF 码!

gswang 发表于 2010-8-22 08:02:33

只是一个想法,因为你是从 AcDbCircle 派生的,你可能不需要另一个变量来保持中心,而是使用 AcDbCircle 的中心。

gswang 发表于 2010-8-22 08:53:39

谢谢你的建议,你是对的!
当我创建我的自定义实体时:
      static int ads_mygcd()
      {
                Acad::ErrorStatus es;
                ads_point center, normal;
                if (acedGetPoint(NULL, _T("\n选择点:"), center) != RTNORM)
                        return RSERR;
                AcDbObjectId tsId = 0;
                TCHAR styleBuf;
                // Get default text style
                struct resbuf result;
                if ( acedGetVar(_T("TEXTSTYLE"), &result) != RTNORM ) {
                        acutPrintf(_T("\nError while reading default AutoCAD text style setting"));
                        return RSERR;
                }
                _tcscpy(styleBuf, result.resval.rstring);
                acdbFree(result.resval.rstring);
                if ( rx_getTextStyleId(styleBuf,acdbHostApplicationServices()->workingDatabase(),tsId) != Acad::eOk)
                {
                        acutPrintf(_T("\nInvalid text style name"));
                        return RSERR;
                }
                CString txt = _T("");
                txt.Format(_T("%.2f"), center);
                TCHAR nameBuf;
                _tcscpy(nameBuf, txt);
                // Set the normal to the plane of the GCD to be the same as the
                // z direction of the current ucs, i.e. (0, 0, 1) since we also got the
                // center and start point in the current UCS.
                normal = 0.0; normal = 0.0; normal = 1.0;
                acdbUcs2Wcs(normal, normal, Adesk::kTrue);
                acdbUcs2Ecs(center, center, normal, Adesk::kFalse);
                AcGePoint3d cen = asPnt3d(center);
                AcGePoint3d pt = AcGePoint3d(center+2.0,center,center);
                AcGeVector3d norm = asVec3d(normal);
                CMyGcd *pGcd = new CMyGcd();
                if (pGcd->set(cen, pt, nameBuf, tsId, norm, 0.5, 4.0) != Acad::eOk) {
                        delete pGcd;
                        acutPrintf(_T("\nCannot create CMyGcd with given parameters."));
                        return RSERR;
                }
                pGcd->setDatabaseDefaults(curDoc()->database());
                pGcd->transformBy(AcGeMatrix3d::translation(AcGeVector3d(center,center,center)));                //在Dbx中怎么写才能代替这行代码?
                AcDbBlockTable* pBT = NULL;
                AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();
                pDB->getSymbolTable(pBT, AcDb::kForRead);
                AcDbBlockTableRecord* pBTR = NULL;
                pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite);
                pBT->close();
                AcDbObjectId Id;
                pBTR->appendAcDbEntity(Id, pGcd);
                pBTR->close();
                pGcd->close();
                return (RSRSLT);
      }代码行:
pGcd->transformBy(AcGeMatrix3d::translation(AcGeVector3d(center,center,center)));
将使上述“(10 0.0 0.0 0.0)”项变为正确的值:
((-1 . ) (0 . "高程点") (330 . ) (5 . "22F")
(100 . "AcDbEntity") (67 . 0) (410 . "模型") (8 . "0") (100 . "AcDbCircle")
(10 2228.71 1228.61 0.0) (40 . 0.0) (210 0.0 0.0 1.0) (100 . "CMyGcd") (90 . 1)
)
我只想知道如何在我的 DBX 项目中实现这些目标。
页: [1] 2
查看完整版本: 自定义实体问题