-
I use the following code to get the parameters of the arc. from pyrx import Rx, Ge, Gi, Db, Ap, Ed, Ax, command
@command
def doit():
"""
return:
curves = [
{"type": "Line", "start": (0, 0), "end": (100, 0)},
{"type": "Arc", "center": (100, 10), "radius": 10, "start_angle": 270, "end_angle": 360},
{"type": "Line", "start": (110, 10), "end": (0, 10)},
{"type": "Arc", "center": (0, 10), "radius": 10, "start_angle": 0, "end_angle": 90},
]
"""
ent_line, id, _ = Ed.Editor.entSel("\nSelect road center line: ")
if ent_line != Ed.PromptStatus.eOk:
return
ent = Db.Entity(id)
pe = Db.AssocPersSubentIdPE(ent.queryX(Db.AssocPersSubentIdPE.desc()))
curves = []
for edge in pe.getAllSubentities(ent, Db.SubentType.kEdgeSubentType):
curve = pe.getEdgeSubentityGeometry(ent, edge)
if curve.type() in [Ge.EntityId.kCircArc3d, Ge.EntityId.kCircArc2d]:
curve = Ge.CircArc3d.cast(curve) if curve.type() == Ge.EntityId.kCircArc3d else Ge.CircArc2d.cast(curve)
curves.append({
"type": "Arc",
"center": curve.center().toTuple(),
"radius": curve.radius(),
"start_radian": curve.startAng(),
"end_radian": curve.endAng()
})
print(f"Circle center: {curve.center()}, radius: {curve.radius()}, start_angle: {curve.startAng()}, end_angle: {curve.endAng()}")
print(f"Circle start: {curve.startPoint()}, end: {curve.endPoint()}") When I select a single arc, the parameters are correct; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
That’s strange! I’ll have to investigate that. Note, I only make the wrappers, I don’t do any of the implementation so the best I can do is file a bug report with Autodesk. If you are always working with curves, you might try something like this import traceback
from pyrx import Ap, Db, Ed, Ge, Gi, command
def appendCurveData(curve, curves):
curves.append(
{
"type": "Arc",
"center": curve.center().toTuple(),
"radius": curve.radius(),
"start_radian": curve.startAng(),
"end_radian": curve.endAng(),
}
)
@command()
def doit():
try:
ent_line, id, _ = Ed.Editor.entSel("\nSelect road center line: ", Db.Curve.desc())
if ent_line != Ed.PromptStatus.eOk:
return
curves = []
dbc = Db.Curve(id)
gec = dbc.getAcGeCurve()
if gec.type() == Ge.EntityId.kCircArc3d:
appendCurveData(Ge.CircArc3d.cast(gec), curves)
elif gec.type() == Ge.EntityId.kCompositeCrv3d:
cc = Ge.CompositeCurve3d.cast(gec)
for c in cc.getCurveList():
if c.type() == Ge.EntityId.kCircArc3d:
appendCurveData(Ge.CircArc3d.cast(c), curves)
print(curves)
except Exception as err:
traceback.print_exc(err) |
Beta Was this translation helpful? Give feedback.
-
I recommend using AcGeCurve sample, but if you really need to use AssocPersSubentIdPE, I found a workaround by doing a conversion. I hope this sample will illustrate it import traceback
from pyrx import Ap, Db, Ed, Ge, Gi, command
def appendCurveData(curve, curves):
curves.append(
{
"type": "kCircArc3d",
"center": curve.center().toTuple(),
"radius": curve.radius(),
"start_radian": curve.startAng(),
"end_radian": curve.endAng(),
}
)
@command
def doit():
db = Db.curDb()
ent_line, id, _ = Ed.Editor.entSel("\nSelect road center line: \n")
if ent_line != Ed.PromptStatus.eOk:
return
ent = Db.Entity(id)
pe = Db.AssocPersSubentIdPE(ent.queryX(Db.AssocPersSubentIdPE.desc()))
curves = []
for edge in pe.getAllSubentities(ent, Db.SubentType.kEdgeSubentType):
curve = pe.getEdgeSubentityGeometry(ent, edge)
print(curve.type())
if curve.type() == Ge.EntityId.kCircArc3d:
#convert to a AcDbCurve
dbc = Db.Core.convertGelibCurveToAcDbCurve(curve)
#this makes a proper arc
#db.addToModelspace(Db.Core.convertGelibCurveToAcDbCurve(curve))
#convert back to a AcGeCurve3d
gec = Db.Core.convertAcDbCurveToGelibCurve(dbc)
appendCurveData(Ge.CircArc3d.cast(gec), curves)
print(curves)
@command()
def doit2():
try:
ent_line, id, _ = Ed.Editor.entSel("\nSelect road center line: \n", Db.Curve.desc())
if ent_line != Ed.PromptStatus.eOk:
return
curves = []
dbc = Db.Curve(id)
gec = dbc.getAcGeCurve()
if gec.type() == Ge.EntityId.kCircArc3d:
appendCurveData(Ge.CircArc3d.cast(gec), curves)
elif gec.type() == Ge.EntityId.kCompositeCrv3d:
cc = Ge.CompositeCurve3d.cast(gec)
for c in cc.getCurveList():
if c.type() == Ge.EntityId.kCircArc3d:
appendCurveData(Ge.CircArc3d.cast(c), curves)
print(curves)
except Exception as err:
traceback.print_exc(err) |
Beta Was this translation helpful? Give feedback.
I recommend using AcGeCurve sample, but if you really need to use AssocPersSubentIdPE, I found a workaround by doing a conversion. I hope this sample will illustrate it