Author Topic: Custom entity question!  (Read 6771 times)

0 Members and 1 Guest are viewing this topic.

gswang

  • Newt
  • Posts: 113
Custom entity question!
« on: August 08, 2010, 09:44:18 AM »
 :cry:
i have 3 files: MyDbxCust.dbx、MyArxCust.arx、MyComCust.dbx

question : run my ADS command
   Command:(custgcd)
   "选择点:"
   Pick one point, draw a point, My custom entity DXF_Name is "高程点", i want to display my DXF_NAME in Object property manager, how to do it?
« Last Edit: August 20, 2010, 07:25:47 AM by gswang »

nico

  • Guest
Re: Custom entity question!
« Reply #1 on: August 10, 2010, 02:31:37 AM »
Use function GetDisplayName in wrapper class.
For example:

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;
//...
  }
}

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
Re: Custom entity question!
« Reply #2 on: August 10, 2010, 07:31:00 PM »
There are a couple of samples in the SDK, see AsdkSquareWrapper in SDK \samples\com and
samples\entity\polysamp (samples\entity\polysamp\compoly)

The polysample has lots of goodies, as it shows how to build COM and .NET wrappers as well as the IOPMPropertyxxx stuff for the properties palette.

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #3 on: August 11, 2010, 07:03:47 AM »
Thank you, nico and Daniel, i'll try it. :roll:

LE3

  • Guest
Re: Custom entity question!
« Reply #4 on: August 11, 2010, 11:54:20 AM »
Quote
If your solution was made using the ARX wizard in example:
1. Your custom object normally will have one ARX and one DBX.
2. Make your ARX to depends on the DBX.
3. Override the method subGetClassID or getClassID depending your target versions (this is the one used to display your dxf).
4. Add your COM wrapper to your DBX project and then go to the recent created header and copy the CLSID and use that inside of subGetClassID().

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #5 on: August 12, 2010, 08:47:15 AM »
In accordance with your tips, I succeed. :-)

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #6 on: August 20, 2010, 07:33:30 AM »
my custom entity is CMyGCD, but when i run (entget ent), the returned list is:
((-1 . <图元名: 7ee595b8>) (0 . "高程点") (330 . <图元名: 7ee57cf8>) (5 . "22F")
(100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle")
(10 0.0 0.0 0.0) (40 . 30.0) (210 0.0 0.0 1.0) (90 . 1))

but it's actual coordinate isn't '(0.0 0.0 0.0) , please give me some advices. :-(

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
Re: Custom entity question!
« Reply #7 on: August 21, 2010, 08:49:27 AM »
You may need to override these functions

Code: [Select]
virtual Acad::ErrorStatus  dxfInFields(AcDbDxfFiler* filer);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* filer) const;

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #8 on: August 21, 2010, 10:14:43 PM »
 :cry:
thanks, i overried the dxfInFIelds and dxfOutFields,
Code: [Select]
//- 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);   //[b]mycode[/b]
return (pFiler->filerStatus ()) ;
}

but the entget data list is:
((-1 . <图元名: 7ee595b8>) (0 . "高程点") (330 . <图元名: 7ee57cf8>) (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) )
there are two 10 DXF code!



It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6940
  • AKA Daniel
Re: Custom entity question!
« Reply #9 on: August 22, 2010, 08:02:33 AM »
Just a thought,  since your are deriving from AcDbCircle, you probably don't need another variable to hold the center, rather use the AcDbCircle's center.

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #10 on: August 22, 2010, 08:53:39 AM »
Thanks for your advice, daniel! You're right!

when i create my custom entity:
Code: [Select]
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[133];
// 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[Z]);

TCHAR nameBuf[133];
_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[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0;
acdbUcs2Wcs(normal, normal, Adesk::kTrue);
acdbUcs2Ecs(center, center, normal, Adesk::kFalse);
AcGePoint3d cen = asPnt3d(center);
AcGePoint3d pt = AcGePoint3d(center[X]+2.0,center[Y],center[Z]);
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[X],center[Y],center[Z]))); //在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);
}
code line:
pGcd->transformBy(AcGeMatrix3d::translation(AcGeVector3d(center[X],center[Y],center[Z])));

will make the above "(10 0.0 0.0 0.0)" item into the correct value:
((-1 . <图元名: 7ee595b8>) (0 . "高程点") (330 . <图元名: 7ee57cf8>) (5 . "22F")
(100 . "AcDbEntity") (67 . 0) (410 . "Model") (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)
 )

i just want to know how to Achieve thus goals in my DBX project.
« Last Edit: August 22, 2010, 09:14:39 AM by gswang »

LE3

  • Guest
Re: Custom entity question!
« Reply #11 on: August 22, 2010, 10:36:04 AM »
Do you override subTransformBy() or transformBy() ?

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #12 on: August 23, 2010, 09:39:32 AM »
Refers to the polysamp example, I rewrote my procedure , deriving from the AcDbCurve, then the entget data list achieved the result which I want . thanks every one!!!

gswang

  • Newt
  • Posts: 113
Re: Custom entity question!
« Reply #13 on: September 12, 2010, 09:16:43 AM »
how to create AcDbWipeout in custom entity?

i search some code , but it doesn't work. :?
Code: [Select]
Adesk::Boolean CMyGcd::subWorldDraw (AcGiWorldDraw *mode) {
assertReadEnabled () ;
//return (AcDbCurve::subWorldDraw (mode)) ;
Acad::ErrorStatus es;
    //......

//wipeout
es = AcDbWipeout::createImageDefinition();
AcDbWipeout *pWipe = new AcDbWipeout();
if(pWipe == NULL) return (Adesk::kFalse);
pWipe->setDatabaseDefaults();

AcGePoint3d originPnt;
getTextPosition(originPnt);
AcGeVector3d Udirection(1,0,0);
AcGeVector3d Vdirection(0,-1,0);
pWipe->setOrientation(originPnt,Udirection,Vdirection);

// Set the clip boundary for the wipeout - this is very important
AcGePoint2dArray *ptArray = new AcGePoint2dArray(5,5);

AcGePoint3dArray vertexArray;
es = getExtentsBox(vertexArray);
AcGePoint2d p0,p1;
p0 = AcGePoint2d(vertexArray[0].x,vertexArray[0].y);
p1 = AcGePoint2d(vertexArray[1].x,vertexArray[1].y);

//AcGePoint2dArray ptArray;
ptArray->append(p0);
ptArray->append(AcGePoint2d(p1.x,p0.y));
ptArray->append(p1);
ptArray->append(AcGePoint2d(p0.x,p1.y));
ptArray->append(p0);
pWipe->setDisplayOpt(AcDbRasterImage::kTransparent,Adesk::kTrue);
pWipe->setDisplayOpt( AcDbRasterImage::kShow, true);
es = pWipe->setClipBoundaryToWholeImage();
es = pWipe->setClipBoundary(AcDbRasterImage::kPoly,*ptArray);


pWipe->worldDraw(mode);

//mode->geometry().draw(pWipe);
delete pWipe;
pWipe = NULL;

//...

return (Adesk::kTrue);
}

nico

  • Guest
Re: Custom entity question!
« Reply #14 on: September 13, 2010, 03:32:36 AM »
how to create AcDbWipeout in custom entity?

It's unpossible to do it in this way. There is a sample code is ADN site. Belive me. Try to use hatch or solid. It'll be much easie, than to create hard pointers and reactors to wipeout object within your custom entity. P.S.: Try to explain, what for do you plan to use a wipeout?