Issue :
I am working with an AutoLISP routine and I am running into a problem. The routine uses a hatch pattern to fill an object and then uses the individual line information that makes up the hatch to do some calculations on the object. Is there a way to get this information with LISP ?
To get the start and end points of hatch lines, the alternative to exploding the hatch is to use ObjectARX. The function AcDbHatch::getHatchLinesData() can be used to obtain the start and endpoints of the hatch lines. So a way to access this from Lisp is to create a Lisp callable function from ObjectARX.
The attached zip file contains a buildable project which demonstrates this technique. The arx file defines the lisp function (hatchlines) and needs an ename as parameter. The function returns a list with the start points of the hatch lines.
Here is the Lisp callable function implemented using ObjectARX. Please have a look at the attached source code for the complete project.
int hatchlines()
{
int res;
resbuf *argRb;
ads_name ename;
AcDbObjectId objId;
AcDbEntity *pEnt;
AcDbHatch *pHatch;
argRb = acedGetArgs();
if (!argRb) {
//
// Get parameters
//
ads_point pt;
if (RTNORM != (res = acedEntSel(
_T("nSelect hatch: "),
ename,
pt
)))
{
acedRetNil();
return res;
}
} else {
//
// Analyze parameters
//
if (argRb->restype != RTENAME) {
acutPrintf(_T("nFirst argument must be an ename."));
acedRetNil();
return RTERROR;
}
if (argRb->rbnext != NULL) {
acutPrintf(_T("nOnly one parameter accepted."));
acedRetNil();
return RTERROR;
}
acdbNameSet(argRb->resval.rlname, ename);
}
// Is the specified entity a hatch?
acdbGetObjectId(objId, ename);
if (Acad::eOk != acdbOpenAcDbEntity(
pEnt,
objId,
AcDb::kForRead
))
{
acedRetNil();
return RTERROR;
}
if (!pEnt->isKindOf(AcDbHatch::desc())) {
acutPrintf(_T("nNot a hatch specified."));
pEnt->close();
acedRetNil();
return RTERROR;
}
pHatch = (AcDbHatch*) pEnt;
//
// Get the hatch lines
//
AcGePoint2dArray startPoints,
endPoints;
if (Acad::eOk != pHatch->getHatchLinesData
(
startPoints,
endPoints
))
{
acutPrintf(_T("nError extracting hatch lines."));
pHatch->close();
acedRetNil();
return RTERROR;
}
pHatch->close();
//
// Build a resbuf containing the coordinates
//
resbuf *retList = NULL,
*retIter = NULL,
*onePoint;
int length = startPoints.length();
for (int i = 0; i < length; ++i) {
onePoint = acutNewRb(RTPOINT);
onePoint->resval.rpoint[X] = startPoints[i].x;
onePoint->resval.rpoint[Y] = startPoints[i].y;
if (!retList) {
retList = onePoint;
retIter = retList;
} else {
retIter->rbnext = onePoint;
retIter = retIter->rbnext;
}
}
acedRetList(retList);
// end of function
return RTNORM;
}

Leave a Reply