AcGePoint3d PtO;
if (AcDbObjectId id = Ctest0lib::SelectEnt(_T("/n选择曲线"),PtO))
{
ExtendCurve( id , 1000);
}
AcDbObjectId SelectEnt(const TCHAR* prompt,AcGePoint3d &PtO)
{
ads_name ent;
ads_point pt;
AcDbObjectId entId = AcDbObjectId::kNull;
int ret = RTNORM;
ret = acedEntSel(prompt, ent, pt);
if (RTNORM != ret) return entId;
acdbGetObjectId(entId, ent);
PtO = asPnt3d(pt);
return entId;
}
static bool ExtendCurve(AcDbObjectId id , double extensionLength)
{
bool TF = false;
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt, id, AcDb::kForWrite);
if (es != Acad::eOk) return TF;
if (pEnt->isKindOf(AcDbCurve::desc()))
{
AcDbCurve *pCurve = AcDbCurve::cast(pEnt);
pCurve->extend(extensionLength);
pCurve->close();
TF = true;
}
pEnt->close();
return TF;
}
Is the length of the curve extension incorrect?
Can it be extended in both directions?
Solved! Go to Solution.
Solved by tbrammer. Go to Solution.
maybe take into consideration the param WRONG Doh!
import traceback
from pyrx_imp import Rx
from pyrx_imp import Ge
from pyrx_imp import Gi
from pyrx_imp import Db
from pyrx_imp import Ap
from pyrx_imp import Ed
def PyRxCmd_doit() -> None:
try:
# create a curve with a length of 100
db = Db.curDb()
curve = Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(0, 100, 0))
lineid = db.addToModelspace(curve)
#check length
print(curve.getDistAtParam(curve.getEndParam()))
# extend do start first, does it matter?
curve.extend(curve.getStartParam() - 1000)
curve.extend(curve.getEndParam() + 1000)
#should be 100 + 1000 + 1000
print(curve.getDistAtParam(curve.getEndParam()))
except Exception as err:
traceback.print_exception(err)
output:
Command: DOIT
100.0
2100.0
The parameter value of a point on an AcDbCurve is in general not the same as its distance from the starpoint!
In case of a polyline the first vertex point has the parameter 0 the second 1 the third 2 and so on.
Unfortunately neither AcDbCurve nor AcGeCurve3d have methods to evaluate the start-/endparameter or the start-/endpoint itself of a curve that is extended by a given length. I tried AcDbCurve::getParamAtDist(dist,..) and AcGeCurve3d::paramAtLength(dist,...). Both work only if 0<=dist<=curve length.
I think it is best practice to calculate the new start/endpoint yourself based on your requirements and knowledge of the curve. Do you want to extent the curve with a tangential line or shall the extension follow the existing curve?
In the latter case a different approach is to estimate the required parameter value by calculating the "parameter-velocity" at the start- or endpoint:
curve->getFirstDeriv(parStart, vDeriv);
velocity = vDeriv.length(); // dLength / dParam
dParam = addedLength / velocity;
parStartNew = parStart-dParam;
curve->getFirstDeriv(parEnd, vDeriv);
velocity = vDeriv.length(); // dLength / dParam
dParam = addedLength / velocity;
parEndNew = parStart + dParam;
It seems to work fine if the curve is linear at the start/endpoint. But the velocity may vary in non linear curves.
You could extend the curve multiple times until its total length is >= old length + additionalLength. Than you can evaluate the "extension point" and cut the curve there.
Thanks for that, I tested on a polyline and it went wonky : |
Can't find what you're looking for? Ask the community or share your knowledge.