Talking about Explode - is this a bug?

Talking about Explode - is this a bug?

Anonymous
Not applicable
397 Views
4 Replies
Message 1 of 5

Talking about Explode - is this a bug?

Anonymous
Not applicable
or it is my code....

I use the code below to explode a custom object but the explode(); method
does not work as I was expecting, even if I ran the test on a closed
polyline (formed of lines) the selection I made on each of the segments
simple does not work, but if I use the AutoCAD built-in command EXPLODE,
then all work as expected.

If someone can check and run the code, will see what I'm talking about.

Thanks,
Luis.

// code start here
const double kPi = 3.14159265358979323846;
void segmentDivision (AcGePoint3d p1, AcGePoint3d p2, double ndiv,
AcGePoint3d &ptres)
{
ptres.x = p1.x + (p2.x - p1.x) / ndiv;
ptres.y = p1.y + (p2.y - p1.y) / ndiv;
ptres.z = p1.z + (p2.z - p1.z) / ndiv;
}
bool postToDatabase (AcDbObjectId blkName, AcDbEntity *pEntity, AcDbObjectId
&pOutputId)
{
AcDbBlockTableRecordPointer pBlk(blkName, AcDb::kForWrite);
if (pBlk.openStatus() != Acad::eOk) return (false);
return (pBlk->appendAcDbEntity(pOutputId, pEntity) == Acad::eOk);
}
bool ExplodeEntity (AcDbObjectId entId, AcDbObjectIdArray &ids)
{
ids.removeAll();
AcDbVoidPtrArray entitySet;
AcDbObjectId pOutputId;
AcDbObjectPointer pEnt(entId, AcDb::kForWrite);
if (pEnt.openStatus() != Acad::eOk) return false;
if (pEnt->explode(entitySet) == Acad::eOk)
{
pEnt->erase();
for (int i = 0; i < entitySet.length(); i++)
{
AcDbEntity *pNewEnt = AcDbEntity::cast((AcRxObject*)entitySet);
if (pNewEnt && postToDatabase(acdbCurDwg()->currentSpaceId(), pNewEnt,
pOutputId))
{
pNewEnt->setColorIndex(1);
pNewEnt->close();
ids.append(pOutputId);
}
}
}
if (ids.isEmpty()) return false;
else return true;
}
void MyExplode (void)
{
AcDbObjectId entId;
ads_name entres;
ads_point ptres;
if (acedEntSel(_T("\nSelect polyline to explode: "), entres, ptres) !=
RTNORM) return;
if (acdbGetObjectId(entId, entres) != Acad::eOk) return;
AcDbObjectIdArray sset;
ExplodeEntity(entId, sset); // does not work
// if the line above it is removed and these lines are used the code works
//struct resbuf *cmdlist = NULL;
//cmdlist = acutBuildList(RTSTR, _T("_.EXPLODE"), RTENAME, entres, 0); //
this one works
//acedCmd(cmdlist);
//acutRelRb(cmdlist);
//acedGetCurrentSelectionSet(sset);

AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); //
test
AcDbBlockTableRecordPointer pBTR(pDb->currentSpaceId(), AcDb::kForWrite); //
test
AcDbPoint *pPoint = NULL;
for (UINT i = 0; i < sset.length(); i++)
{
AcDbObjectPointer pEnt(sset, AcDb::kForRead);
if (pEnt.openStatus() == Acad::eOk)
{
AcGePoint3d p0, p1, m;
pEnt->getStartPoint(p0);
pEnt->getEndPoint(p1);
segmentDivision(p0, p1, 2.0, m);
double d = (sqrt(2.0) * (p0.distanceTo(p1) / 2.0));
ads_point ptres, a, b, p01, p11, p02, p12;
// extract two diagonal points a-b for crossing selection
acutPolar(asDblArray(m), ((3 * kPi) / 4), d, ptres);
acdbWcs2Ucs(ptres, a, false);
acutPolar(asDblArray(m), ((7 * kPi) / 4), d, ptres);
acdbWcs2Ucs(ptres, b, false);
// draw the points - test
pPoint = new AcDbPoint(asPnt3d(a));
if (pPoint && Acad::eOk == pBTR.openStatus())
{
pBTR->appendAcDbEntity(pPoint);
pPoint->close();
}
pPoint = new AcDbPoint(asPnt3d(b));
if (pPoint && Acad::eOk == pBTR.openStatus())
{
pBTR->appendAcDbEntity(pPoint);
pPoint->close();
}
ads_name ss;
resbuf *rbFilter = acutBuildList(RTDXF0, _T("LINE"), RTNONE);
if (acedSSGet(_T("_C"), a, b, rbFilter, ss) != RTNORM)
{
acutRelRb(rbFilter);
acutPrintf(_T("\nInvalid crossing selection. ")); // debug
return;
}
acutRelRb(rbFilter);
long len = 0;
if ((acedSSLength(ss, &len) != RTNORM) || (len == 0))
{
acedSSFree(ss);
return;
}
acutPrintf(_T("\nNumber of entities selected[%ld]"), len);
acedSSFree(ss);
}
}
}
// code end here
0 Likes
398 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Luis:

What exactly do you mean by "does not work as I was expecting"? Did you
perhaps forget to call transformBy() on the exploded entities?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


wrote in message news:6165037@discussion.autodesk.com...
or it is my code....

I use the code below to explode a custom object but the explode(); method
does not work as I was expecting, even if I ran the test on a closed
polyline (formed of lines) the selection I made on each of the segments
simple does not work, but if I use the AutoCAD built-in command EXPLODE,
then all work as expected.

If someone can check and run the code, will see what I'm talking about.

[...]
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Owen,

For some reason, I cannot make a selection on the recently exploded (via
code) entities.

I'm including a small visual studio project (A2007) and the arx file, with
two commands: ExplodeCode and ExplodeCmd.
Just use the command rectangle and test both commands.

Thanks!


/*

"Owen Wengerd"
Luis:

What exactly do you mean by "does not work as I was expecting"? Did you
perhaps forget to call transformBy() on the exploded entities?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


wrote in message news:6165037@discussion.autodesk.com...
or it is my code....

I use the code below to explode a custom object but the explode(); method
does not work as I was expecting, even if I ran the test on a closed
polyline (formed of lines) the selection I made on each of the segments
simple does not work, but if I use the AutoCAD built-in command EXPLODE,
then all work as expected.

If someone can check and run the code, will see what I'm talking about.

[...]
0 Likes
Message 4 of 5

Anonymous
Not applicable
Your ExplodeCode command creates a series of point entities.
Is this by design?

wrote in message news:6165206@discussion.autodesk.com...
Hi Owen,

For some reason, I cannot make a selection on the recently exploded (via
code) entities.

I'm including a small visual studio project (A2007) and the arx file, with
two commands: ExplodeCode and ExplodeCmd.
Just use the command rectangle and test both commands.

Thanks!


/*

"Owen Wengerd"
Luis:

What exactly do you mean by "does not work as I was expecting"? Did you
perhaps forget to call transformBy() on the exploded entities?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


wrote in message news:6165037@discussion.autodesk.com...
or it is my code....

I use the code below to explode a custom object but the explode(); method
does not work as I was expecting, even if I ran the test on a closed
polyline (formed of lines) the selection I made on each of the segments
simple does not work, but if I use the AutoCAD built-in command EXPLODE,
then all work as expected.

If someone can check and run the code, will see what I'm talking about.

[...]
0 Likes
Message 5 of 5

Anonymous
Not applicable
Those points are just for testing purposes, and to show where the crossing
selection it is made. 🙂

Thanks,
Luis.

"alexb" wrote in message
news:6165245@discussion.autodesk.com...
Your ExplodeCode command creates a series of point entities.
Is this by design?

wrote in message news:6165206@discussion.autodesk.com...
Hi Owen,

For some reason, I cannot make a selection on the recently exploded (via
code) entities.

I'm including a small visual studio project (A2007) and the arx file, with
two commands: ExplodeCode and ExplodeCmd.
Just use the command rectangle and test both commands.

Thanks!


/*

"Owen Wengerd"
Luis:

What exactly do you mean by "does not work as I was expecting"? Did you
perhaps forget to call transformBy() on the exploded entities?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


wrote in message news:6165037@discussion.autodesk.com...
or it is my code....

I use the code below to explode a custom object but the explode(); method
does not work as I was expecting, even if I ran the test on a closed
polyline (formed of lines) the selection I made on each of the segments
simple does not work, but if I use the AutoCAD built-in command EXPLODE,
then all work as expected.

If someone can check and run the code, will see what I'm talking about.

[...]
0 Likes