finding self-intersecting polylines and polylines with double vertices

Hello, do any of you know a lisp tool for finding self-intersecting polylines and polylines with double vertices, similar to the "selfintersect.vlx" tool from this page?

https://www.cadforum.cz/en/self-intersecting-polylines-and-polylines-with-duplicate-vertice-tip10926

Or is there another way to accomplish this task in BricsCAD?
The problem is that BricsCAD apparently cannot process *.vlx files, and I have not yet found a corresponding *.lsp file online that does this job.

I myself work with BricsCAD version 23.1.08 (x64) and am more of a user than a programmer, which means I can't program LISP.

I need a tool like this to be able to create correct polylines for grading in BricsCAD-Civil. I often have to import these from "geometrically inaccurate sources" such as PDFs. Then I have to check the lines for errors, otherwise there will be problems when creating the grading. By the way, it would be good if there was a warning when creating the grading when you select a polyline with self-intersection, not just a cancellation or "not working" of the command.

Comments

  • Too bad you’re not using V24, Python’s shapely has a tool for checking polygons
    https://shapely.readthedocs.io/en/latest/manual.html#validation.make_valid

    I’m not sure if it will catch all your issues, but in this case, it detects self-intersection and fixes it by creating MultiPolygon
    Some sample code:

    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
    from pyrx_imp import Gs
    from pyrx_imp import Cv

    from shapely.validation import make_valid
    from shapely.validation import explain_validity
    from shapely.geometry.polygon import Polygon

    def PyRxCmd_doit() -> None:
    try:
    db = Db.curDb()
    filter = [(Db.DxfCode.kDxfStart, "LWPOLYLINE")]
    ssres: tuple[Ed.PromptStatus,Ed.SelectionSet] = Ed.Editor.select(filter)
    if ssres[0] != Ed.PromptStatus.eOk:
    print("Oops {}: ".format(ssres[0]))
    return

    for id in ssres[1].objectIds():
    pl = Db.Polyline(id)
    sp = Polygon(pl.toList())
    if not sp.is_valid:
    #why
    print(explain_validity(sp))
    #fix
    nsp = list(make_valid(sp).geoms)
    for spl in nsp:
    npl = Db.Polyline(list(spl.exterior.coords))
    npl.setColorIndex(3)
    npl.setClosed(True)#?
    db.addToCurrentspace(npl)

    except Exception as err:
    traceback.print_exception(err)