Hi @calderg1000 , thank you for your reply.
This is my current code, based on @Kent1Cooper lisp:
(defun C:QLCLP ; = Quadrilateral Long-direction Center Line or Point
(/ pap ss n pl seglen1 seglen2 dists parA)
(defun pap (i) (vlax-curve-getPointAtParam pl i))
(if (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1))))
; 4-sided closed only
(repeat (setq n (sslength ss))
(setq pl (ssname ss (setq n (1- n))))
(if
(and
; all straight-line segments [no bulge factors]:
(= (apply '+ (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 42)) (entget pl)))) 0.0)
; opposite sides equal lengths:
(equal (setq seglen1 (distance (pap 0) (pap 1))) (distance (pap 2) (pap 3)) 1e-6)
(equal (setq seglen2 (distance (pap 1) (pap 2))) (distance (pap 3) (pap 0)) 1e-6)
; right angle corner:
(equal (rem (abs (- (angle (pap 0) (pap 1)) (angle (pap 1) (pap 2)))) pi) (/ pi 2) 1e-6)
); and
(progn ; then
(setq dists (list seglen1 seglen2))
(if (> (/ (apply 'max dists) (apply 'min dists)) 4); ratio of sides
(progn; then -- Center Line in longer direction
(setq parA (vl-position (apply 'min dists) dists)); 0 or 1
(command
"_.line" "_non" (pap (+ parA 0.5)) "_non" (pap (+ parA 2.5)) ""
"_.chprop" (entlast) "" "_ltype" "CENTER" ""
"_.matchprop" pl (entlast) ""
); command
); progn
(command "_.point" "_non" (mapcar '/ (mapcar '+ (pap 0) (pap 2)) '(2 2 2))); else
); if [ratio]
); progn
); if [rectangular]
); repeat
); if [any 4-sided closed Polyline(s) selected]
(prin1)
)
Once if that line is correct, then I must have added it in the wrong place.
This is my new code, which i think is fine:
(defun C:QLCLP_layer ; = Quadrilateral Long-direction Center Line or Point
(/ pap ss n pl seglen1 seglen2 dists parA)
(defun pap (i) (vlax-curve-getPointAtParam pl i))
(if (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1))))
; 4-sided closed only
(repeat (setq n (sslength ss))
(setq pl (ssname ss (setq n (1- n))))
(if
(and
; all straight-line segments [no bulge factors]:
(= (apply '+ (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 42)) (entget pl)))) 0.0)
; opposite sides equal lengths:
(equal (setq seglen1 (distance (pap 0) (pap 1))) (distance (pap 2) (pap 3)) 1e-6)
(equal (setq seglen2 (distance (pap 1) (pap 2))) (distance (pap 3) (pap 0)) 1e-6)
; right angle corner:
(equal (rem (abs (- (angle (pap 0) (pap 1)) (angle (pap 1) (pap 2)))) pi) (/ pi 2) 1e-6)
); and
(progn ; then
(setq dists (list seglen1 seglen2))
(if (> (/ (apply 'max dists) (apply 'min dists)) 4); ratio of sides
(progn; then -- Center Line in longer direction
(setq parA (vl-position (apply 'min dists) dists)); 0 or 1
(command
"_.line" "_non" (pap (+ parA 0.5)) "_non" (pap (+ parA 2.5)) ""
"_.chprop" (entlast) "" "_ltype" "CENTER" ""
"_.matchprop" pl (entlast) "" ; new line
); command
); progn
(command
"_.point" "_non" (mapcar '/ (mapcar '+ (pap 0) (pap 2)) '(2 2 2))
"_.matchprop" pl (entlast) "" ; new line
); else
); if [ratio]
); progn
); if [rectangular]
); repeat
); if [any 4-sided closed Polyline(s) selected]
(prin1)
)
Just added in another place and its original position.
I think is good now!
Thanks for the tip @calderg1000 🙂 many thanks!