这里有个,只供参考- (defun c:tt ( / dist ename ept fdist file fistpt fpt gcdz i lename lept lobj lspt lst maxx maxy minx miny Name obj objname pt ptl rename rept robj rspt slen spt ss v x zpt zsdist)
- (vl-load-com)
- (while (setq ename (car (entsel "\n请选择断面线:")))
- (if ename
- (progn
- (setvar "osmode" 33)
- (setq zPt (getpoint "\n拾取断面起点:")
- zPt (list (car zPt) (cadr zPt))
- )
- (setvar "osmode" 0)
- (setq obj (vlax-ename->vla-object ename))
- (setq objname (vlax-get obj 'ObjectName ))
- (if (or (= objname "AcDbLine") (= objname "AcDbPolyline"))
- (progn
- (setq sPt (vlax-curve-getStartPoint obj)
- ePt (vlax-curve-getEndPoint obj)
- )
- (vla-Offset (vlax-ename->vla-object ename) -0.3) ;控制中线两边
- (setq Lename (entlast)
- Lobj (vlax-ename->vla-object Lename)
- Lspt (vlax-curve-getStartPoint Lobj)
- Lept (vlax-curve-getEndPoint Lobj)
- )
- (vla-Offset (vlax-ename->vla-object ename) 0.3) ;控制中线两边
- (setq Rename (entlast)
- Robj (vlax-ename->vla-object Rename)
- Rspt (vlax-curve-getStartPoint Robj)
- Rept (vlax-curve-getEndPoint Robj)
- )
- (setq lst (list Lspt Lept Rept Rspt))
- (setq minX (apply 'min (mapcar '(lambda (x) (car x)) lst))
- minY (apply 'min (mapcar '(lambda (x) (cadr x)) lst))
- maxX (apply 'max (mapcar '(lambda (x) (car x)) lst))
- maxY (apply 'max (mapcar '(lambda (x) (cadr x)) lst))
- )
- (entdel Lename) (entdel Rename)
- (command "zoom" (list minX minY) (list maxX maxY))
- (setq i -1 ss (ssget "_CP" lst '((0 . "INSERT") (2 . "GC200"))))
- (if ss
- (progn
- (setq slen (sslength ss))
- (repeat slen
- (setq Name (ssname ss (setq i (1+ i))))
- (setq pt (cdr (assoc 10 (entget Name))))
- (setq ptl (cons pt ptl))
- )
- (setq ptl (gcd_sort ptl obj))
- (setq fpt (car ptl))
- (setq zsdist (distance zPt sPt)) ;线起点至断面中点的距离
- (if (setq file (getfiled "保存数据" "D:\\K0+000" "csv" 1))
- (progn
- (setq file (open file "a"))
- (write-line "距离,高程值" file)
- (while ptl
- (setq npt (car ptl))
- (setq pt (vlax-curve-getClosestPointTo obj npt))
- (setq dist (- (vlax-curve-getDistAtPoint obj pt) zsdist))
- (setq gcdz (caddr npt))
- (write-line (strcat (rtos dist 2 3) "," (rtos gcdz 2 3)) file)
- (setq ptl (cdr ptl))
- )
- (close file)
- )
- )
- )
- )
- )
- )
- (setq ptl nil)
- )
- )
- )
- )
- (defun gcd_sort (ptl obj / lst x n)
- (if (= (type obj) 'ENAME) (setq curve (vlax-ename->vla-object obj)))
- (setq lst (mapcar '(lambda (x /) (vlax-curve-getParamAtPoint obj (vlax-curve-getClosestPointTo obj x))) ptl))
- (mapcar '(lambda (n) (nth n ptl)) (vl-sort-i lst '<))
- )
|