1. xdrx-pointmonitor
Through the point monitor callback function _callback, draw dynamic memory MTEXT, POLYLINE screen vector, and dynamic drag
2. xd::geom:getoverlaps
Get Entitiy List of overlapping segments
;|
Functions: Obtain the memory geometric entities of the overlapping segments of two polylines (determine whether the two polylines will overlap in the future)
parameter:
1. e1,e2 ---- polyline entity name, or geometric entity name, or point table
2. mode --- t: returns the geometric entity table, nil: returns t or nil
|;
(defun xd::geom:getoverlaps (e1 e2 mode / g1 g2 gint curveint ret _getparam ranges ranges1)
(defun _getparam (e1 / g1)
(cond
((= (type e1) 'list)
(setq g1 (xdge::constructor "kCompositeCrv3d" e1))
)
((and (= (type e1) 'ename)
(xdrx-object-iskindof e1 "AcDbCurve")
)
(setq g1 (xdge::constructor e1))
)
((xdge::type e1)
t
)
(t
(setq g1 nil)
)
)
g1
)
(setq g1 (_getparam e1)
g2 (_getparam e2)
)
(if (and g1 g2)
(progn
(setq curveint (xdge::constructor "kCurveCurveInt3d"))
(setq gint (xdge::setpropertyvalue curveint "set" g1 g2))
(setq ret (> (xdge::getpropertyvalue gint "numOverlaps") 0))
(if (and mode ret)
(progn
(setq ranges (xdge::getpropertyvalue gint "overlapranges" t)
ranges1 (mapcar 'car ranges)
)
(setq ret
(mapcar '(lambda (x)
(setq tmp (xdge::copy g1))
(xdge::setpropertyvalue tmp "setinterval" x)
)
ranges1
)
)
)
)
)
)
(xdge::free g1 g2 curveint gint ranges)
ret
)
(defun c:tt ()
(defun *error* (msg)
(xdrx-entity-delete ents)
(xdrx-pointmonitor)
(xdrx-end)
(redraw)
)
(defun _callback (dynpt)
(redraw)
(xd::pnts:mark verts 2 0.025)
(xdrx-setpropertyvalue
ents
"constantwidth"
(* (getvar "viewsize") 0.015)
"color" 6
)
(xdrx-grdraw 6 ents)
(xd::grdraw:drawtext
txt
totallen
(polar dynpt (/ pi 4.0) (/ (xd::doc:getpickboxheight) 2.0))
1
(* (getvar "viewsize") 0.03)
6
(getvar "ucsxdir")
nil
8
)
)
(xdrx-begin)
(if (and (setq e1 (car (xdrx-entsel
(xdrx-string-multilanguage
"\n拾取第一条多段线<退出>:"
"\nPick the first polyline<Exit>:"
)
'((0 . "*polyline"))
)
)
)
(setq e2 (car (xdrx-entsel
(xdrx-string-multilanguage
"\n拾取第一条多段线<退出>:"
"\nPick the first polyline<Exit>:"
)
'((0 . "*polyline"))
)
)
)
)
(progn
(if (setq data (xd::geom:getoverlaps e1 e2 t))
(progn
(setq txt (xdrx-mtext-make)
nums (length data)
tlen (apply '+ (xdrx-getpropertyvalue data "length"))
totallen (xdrx-string-formatex
(xdrx-string-multilanguage
"重叠段 %d,总长度 %.1f\r\n"
"Overlapping segment %d.\r\nTotal length=%.1f"
)
nums
tlen
)
verts (xdrx-getpropertyvalue data "vertices")
ents (xdrx-entity-make data)
verts (xd::list:flat-point verts)
)
(xdrx-pointmonitor "_callback")
(if (getpoint)
(progn
(xdrx-entity-make txt)
)
)
;(xdrx-entity-delete ents)
(xdrx-pointmonitor)
)
)
)
)
(redraw)
(xdrx-end)
(princ)
)
=======================
The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API
The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.