Author Topic: HELP! Hatch curve in custom objects  (Read 3992 times)

0 Members and 1 Guest are viewing this topic.

tuankm

  • Guest
HELP! Hatch curve in custom objects
« on: January 13, 2009, 05:06:34 AM »
Hi all,
I have a custom object, in this I have some curve. In my worlddraw How want to draw draw hatch inside this curve, so in my worldDraw I put the following code, but it is not work.
Can any one help? Thank in advance.

Adesk::Boolean MyObject::worldDraw (AcGiWorldDraw *mode)
{
//.............
AcDbMPolygon* mPoly = new AcDbMPolygon;
mPoly->copyFrom(m_pCurve); // my curve variable
mPoly->setNormal(m_normal); // my normal variable
mPoly->setPatternScale(1.0);
mPoly->setPatternAngle(0);
mPoly->setPattern(AcDbHatch::kPreDefined, _T("angle"));
mPoly->evaluateHatch();
mPoly->worldDraw(mode);
delete mPoly;
//....
return (Adesk::kTrue) ;
}

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #1 on: January 13, 2009, 11:15:51 PM »
Try with the added lines - compile your solution and try again.

Adesk::Boolean MyObject::worldDraw (AcGiWorldDraw *mode)
{
//.............
AcDbMPolygon* mPoly = new AcDbMPolygon;
mPoly->copyFrom(m_pCurve); // my curve variable
mPoly->setNormal(m_normal); // my normal variable
mPoly->setPatternScale(1.0);
mPoly->setPatternAngle(0);
mPoly->setPattern(AcDbHatch::kPreDefined, _T("angle"));

AcDbObjectIdArray dbObjIds; dbObjIds.append(m_pCurve->objectId());
mPoly->hatch()->appendLoop(AcDbHatch::kDefault, dbObjIds);


mPoly->evaluateHatch();
mPoly->worldDraw(mode);
delete mPoly;
//....
return (Adesk::kTrue) ;
}

Read more about the AcDbMPolygon and AcDbHatch classes.

tuankm

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #2 on: January 14, 2009, 05:35:01 AM »
Hi LE,
Thank you very much for your concern.
I added your suggest code but it is not work.
I think the problem is m_pCurve is only store in my custom object so it not have an objectid, so the appendloop doesnt works.
Do you have any solution for this case?

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #3 on: January 14, 2009, 09:48:27 AM »
Hi LE,
Thank you very much for your concern.
I added your suggest code but it is not work.
I think the problem is m_pCurve is only store in my custom object so it not have an objectid, so the appendloop doesnt works.
Do you have any solution for this case?


Have you tried the other two overloads of appendLoop(); ?

You can extract the vertices & bulges data and use those.

Draftek

  • Water Moccasin
  • Posts: 1501
Re: HELP! Hatch curve in custom objects
« Reply #4 on: January 14, 2009, 10:25:37 AM »
I'm no expert but I don't think your architecture is going to work - creating an object inside worlddraw that calls worlddraw doesn't seem right. Aren't you required to work with primitives at this point?

Maybe Tony will weigh in here.
Soli Deo Gloria

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #5 on: January 14, 2009, 10:52:20 AM »
I'm no expert but I don't think your architecture is going to work - creating an object inside worlddraw that calls worlddraw doesn't seem right. Aren't you required to work with primitives at this point?

Maybe Tony will weigh in here.

I do not know what other code tuankm it is using, but for what he posted, nothing it is appended to the drawing database.

The drawbacks or things you are not supposed to do, is to open for write an object inside of world/viewportDraw();.

Among some others, too.




Draftek

  • Water Moccasin
  • Posts: 1501
Re: HELP! Hatch curve in custom objects
« Reply #6 on: January 14, 2009, 12:11:40 PM »
If nothing gets streamed in and out of the database then worldraw will never work with anything scoped outside of it(worlddraw).
Soli Deo Gloria

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #7 on: January 14, 2009, 06:37:21 PM »
I have done some few commands using the AcDbMPolygon class and derived from AcDbEntity or from AcDbPolyline - two in particular, one for land use and other for landscape layout.

Here is a quick one (mickey mouse) I just did:

:)
« Last Edit: January 14, 2009, 06:42:14 PM by LE »

Draftek

  • Water Moccasin
  • Posts: 1501
Re: HELP! Hatch curve in custom objects
« Reply #8 on: January 15, 2009, 08:02:07 AM »
Nice work LE!
Soli Deo Gloria

tuankm

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #9 on: January 15, 2009, 09:06:24 AM »
Hi LE,
I think except the hatch part, my other code have no any error. You can see in my screen capture below. My object have 3 part, the yellow line is store in m_pCurve, the pink line is store in m_internalCurve, and a block.
I want to hatch the yellow line.

tuankm

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #10 on: January 15, 2009, 09:48:11 AM »
Hi LE,
I see in the help file that appendloop have an override of
Acad::ErrorStatus appendLoop( Adesk::Int32 loopType,const AcGePoint2dArray& vertices,const AcGeDoubleArray& bulges);
It may work for my case, but I don't know how to get vertices and bulges from curve. Can you help?

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #11 on: January 15, 2009, 10:03:13 AM »
Hi LE,
I see in the help file that appendloop have an override of
Acad::ErrorStatus appendLoop( Adesk::Int32 loopType,const AcGePoint2dArray& vertices,const AcGeDoubleArray& bulges);
It may work for my case, but I don't know how to get vertices and bulges from curve. Can you help?

That's what I mentioned on a previous post (to use one of the overloads).

You can use getPointAtParam(); or do a AcDbPolyline cast(); and traverse the object to extract all the vertices.

HTH.

tuankm

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #12 on: January 15, 2009, 10:49:22 PM »
Hi LE,
Thanks for your suggestion. Now I can make the hatch work on the polyline object, but not for the circle and ellipse.
I also want to remove hatch from the internal block. Please help. Thanks in advanced.

Code: [Select]
Adesk::Boolean KMTPARCEL::worldDraw (AcGiWorldDraw *mode) {
               
        //........................
  AcDbPolyline* pLine = AcDbPolyline::cast(m_pCurve);
      if (pLine) {
       AcGePoint2dArray vertices;
AcGeDoubleArray bulges;
int nVerts = pLine->numVerts();
AcGePoint2d pnt;
double bulge;
for (int i=0;i<nVerts;i++){
pLine->getPointAt(i,pnt);
pLine->getBulgeAt(i,bulge);
vertices.append(pnt);
bulges.append(bulge);
}
pLine->getPointAt(0,pnt);
pLine->getBulgeAt(0,bulge);
vertices.append(pnt);
bulges.append(bulge);

AcDbHatch* hatch = new AcDbHatch;
hatch->setNormal(m_normal);
hatch->setPatternScale(m_DimScale);
hatch->setPatternAngle(45);
hatch->setPattern(AcDbHatch::kPreDefined, _T("NET"));
hatch->appendLoop(AcDbHatch::kDefault|AcDbHatch::kExternal, vertices,bulges);
hatch->evaluateHatch();
hatch->worldDraw(mode);
delete hatch;
        }
       //........................
}

Daniel edit: added code tags
« Last Edit: January 15, 2009, 11:58:12 PM by Daniel »

Spike Wilbury

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #13 on: January 15, 2009, 11:28:59 PM »
Kieu,

Have a look at the code samples in the AcDbHatch class in the arxref.chm help, it shows step-by-step.


Luis.-

« Last Edit: January 15, 2009, 11:32:49 PM by LE »

tuankm

  • Guest
Re: HELP! Hatch curve in custom objects
« Reply #14 on: January 16, 2009, 01:05:34 AM »
Thanks LE.