<?xml encoding=”UTF-8″>By Balaji Ramamoorthy
In this blog post, we will look at modifying an associative path array. A path array can either be using the item spacing or the item count depending on how the path array is configured in its properties. The below code snippet decrements the item count or increases the item spacing to reduce the number of items along the path.
Here is a recording and a code snippet :
<span>#include</span><span> <span>"AcDbAssocManager.h"</span><span> </span></span>
<span>#include</span><span> <span>"AcDbAssocArrayActionBody.h"</span><span> </span></span>
<span>#include</span><span> <span>"AcDbAssocArrayPathParameters.h"</span><span> </span></span>
Acad::ErrorStatus es;
ads_name ename;
ads_point pickPt;
<span>int</span><span> rc = acedEntSel(_T(<span>"\nSelect Entity"</span><span> ), ename, pickPt);</span></span>
<span>if</span><span> (rc != RTNORM)</span>
<span>return</span><span> ;</span>
AcDbObjectId entId;
acdbGetObjectId(entId, ename);
AcDbObjectPointer <AcDbEntity> pEntity(entId, AcDb::kForRead);
<span>if</span><span> ((es = pEntity.openStatus()) != Acad::eOk)</span>
<span>return</span><span> ;</span>
<span>if</span><span> (! AcDbAssocArrayActionBody::isAssociativeArray(pEntity))</span>
<span>{</span>
acutPrintf(ACRX_T(<span>"\nNot an associative array !"</span><span> ));</span>
<span>return</span><span> ;</span>
<span>}</span>
AcDbObjectId actionBodyId
= AcDbAssocArrayActionBody::getControllingActionBody(
pEntity, NULL);
pEntity->close();
AcDbAssocArrayActionBody* pArrayActionBody = NULL;
<span>if</span><span> ( (es = acdbOpenAcDbObject(</span>
(AcDbObject*&)pArrayActionBody,
actionBodyId,
AcDb::kForWrite)) != Acad::eOk)
<span>return</span><span> ;</span>
AcDbAssocArrayParameters *pAssocArrayParams
= pArrayActionBody->parameters();
AcDbAssocArrayPathParameters *pAssocArrayPathParams
= AcDbAssocArrayPathParameters::cast(pAssocArrayParams);
AcDbAssocArrayPathParameters::Method pathArrMethod
= pAssocArrayPathParams->method();
<span>if</span><span> (pathArrMethod </span>
== AcDbAssocArrayPathParameters::Method::kDivide)
<span>{</span>
<span>//The Divide method arranges the given number of items on the </span><span> </span>
<span>// entire path equidistantly. </span><span> </span>
<span>// So we will decrement the number of items along the path</span><span> </span>
pAssocArrayPathParams->setItemCount
(pAssocArrayPathParams->itemCount() - 1);
<span>}</span>
<span>else</span><span> <span>if</span><span> (pathArrMethod </span></span>
== AcDbAssocArrayPathParameters::Method::kMeasure)
<span>{</span>
<span>double</span><span> itemSpacingBefore </span>
= pAssocArrayPathParams->itemSpacing();
<span>//The Measure method arranges the given number of items </span><span> </span>
<span>// using the specified item spacing along the path.</span><span> </span>
pAssocArrayPathParams->setItemSpacing
(pAssocArrayPathParams->itemSpacing() * 1.1);
<span>double</span><span> itemSpacingAfter </span>
= pAssocArrayPathParams->itemSpacing();
<span>if</span><span> (fabs(itemSpacingBefore-itemSpacingAfter) < 0.0001)</span>
<span>{</span><span>// Reduce the number of items</span><span> </span>
pAssocArrayPathParams->setItemCount
(pAssocArrayPathParams->itemCount() - 1);
pAssocArrayPathParams->setItemSpacing
(pAssocArrayPathParams->itemSpacing() * 1.1);
<span>}</span>
<span>}</span>
pArrayActionBody->close();
AcDbAssocManager::evaluateTopLevelNetwork(entId.database());
acedUpdateDisplay();

Leave a Reply