Author Topic: Adding Hatch  (Read 2011 times)

0 Members and 1 Guest are viewing this topic.

Helios

  • Guest
Adding Hatch
« on: May 11, 2009, 11:01:12 AM »
Hello all,

Still busy on BRX for bricscad..
I have cooked up code below after a little internet search but that keeps failing on the appendLoop method.

Three questions?
1) what is wrong with this code?
2) MUST the Points array start/end with the same coordinate?
3) MUST the number of bulges equal the number of points? (I'd expect it to be one less)

Question 2 and 3 were mentioned at various forums, but I'm not sure they are correct.

Thanks in advance,
Helios.

Acad::ErrorStatus CadDrawing::AddHatch(const AcGePoint2dArray& Points, const AcGeDoubleArray& bulges)
 {
   Acad::ErrorStatus es = Acad::eNullHandle;
   
   if (NULL != m_pCurDb)
   {
     AcDbObjectPointer<AcDbHatch> hatch;
     
     if ((es = hatch.create()) != Acad::eOk)
     {
       LogString(L"Failed to create hatch\n");
       return es;
     }
     
     if ((es = hatch->setNormal(AcGeVector3d::kZAxis)) != Acad::eOk)
     {
       LogString(L"Failed to set hatch Normal vector\n");
       return es;
     }
     
     if ((es = hatch->setElevation(0.0)) != Acad::eOk)
     {
       LogString(L"Failed to set hatch Elevation vector\n");
       return es;
     }
     
     if ((es = hatch->setPattern(AcDbHatch::kPreDefined, _T("SOLID"))) != Acad::eOk)
     {
       LogString(L"Failed to set hatch Pattern to SOLID\n");
       return es;
     }
     
     if ((es = hatch->setHatchStyle(AcDbHatch::kNormal)) != Acad::eOk)
     {
       LogString(L"Failed to set hatch style\n");
       return es;
     }
     
     if ((es = hatch->setAssociative(false)) != Acad::eOk)
     {
       LogString(L"Failed to set hatch assiciative\n");
       return es;
     }
     
     if ((es = hatch->appendLoop(AcDbHatch::kExternal | AcDbHatch::kPolyline , Points, bulges)) != Acad::eOk);
     {
       LogString(L"Failed to appendloop to hatch\n");
       return es;
     }
     
     if ((es = setEntityCurProperties(hatch.object())) != Acad::eOk)
     {
       LogString(L"Failed to set hatch properties\n");
       return es;
     }
       
     if ((es = m_CurSpace->appendAcDbEntity(hatch)) != Acad::eOk)
     {
       LogString(L"Failed to append hatch to block (%s)\n", LPCTSTR(m_CurSpaceName));
       return es;
     }
     
     return es;
   }
   
   return es;
 }

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding Hatch
« Reply #1 on: May 12, 2009, 01:43:59 AM »
Its hard to saw what’s going on without seeing the code that calls this function.
Also you my have a look at using acadErrorStatusText(st),

Helios

  • Guest
Re: Adding Hatch
« Reply #2 on: May 12, 2009, 03:30:58 AM »
Hi Daniel,

I'm just passing an array of 5 points to this routine;
First and last coordinate are the same.
Can you commant on the questions:
2)first/last point must be same.
3)nr of bulges same as number of points?


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Adding Hatch
« Reply #3 on: May 12, 2009, 04:42:15 AM »
from the docs

Quote
A loop must be simple, closed, and continuous, intersecting itself only at its endpoints.
Furthermore, its start point and end point must coincide

and for number 3, from the samples I have seen, yes

Helios

  • Guest
Re: Adding Hatch
« Reply #4 on: May 12, 2009, 05:39:28 AM »
Mentioning docs:
What is a good source for background info on ARX? (Like those flags you need to pass to the appendLoop method)

B.T.W. I have forwarded above hatch questions to Bricscad Support. They're looking into it.
I will forward the results here as well.

Helios

Helios

  • Guest
Re: Adding Hatch
« Reply #5 on: May 12, 2009, 11:29:42 AM »
For those following this thread:

There were two problems in following line:

if ((es = hatch->appendLoop(AcDbHatch::kExternal | AcDbHatch::kPolyline , Points, bulges)) != Acad::eOk);
   
1) The semicolon at the end of the line should not be there. (I love C++  :realmad:)
2) Only the AcDbHatch::kExternal  flag has to be passed into the append Loop method. (In BRX)

This works:
if ((es = hatch->appendLoop(AcDbHatch::kExternal, Points, bulges)) != Acad::eOk)

Thanks to Bricsys Support for their swift replies.

Helios.