HOCHANZ Posted April 2, 2019 Posted April 2, 2019 i'm having difficulty creating a LISP routine to do the following. 1. get a selection set from the user 2. isolate diagonal (non horizontal and vertical) polylines 3. then do whatever is needed ie. change layer or delete i can get the polyline selection set, but i'm not sure how to write the condition. help. Quote
ronjonp Posted April 2, 2019 Posted April 2, 2019 (edited) Here is one way to do it checking that the start/endpoint x's or y's are not equal. (defun c:foo (/ a b s) (cond ((setq s (ssget '((0 . "lwpolyline") (90 . 2)))) (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq a (vlax-curve-getstartpoint x)) (setq b (vlax-curve-getendpoint x)) (if (or (equal (car a) (car b) 1e-8) (equal (cadr a) (cadr b) 1e-8)) (ssdel x s) ) ) (sssetfirst nil s) ) ) (princ) ) Edited April 3, 2019 by ronjonp *changed code to work on polylines 1 Quote
HOCHANZ Posted April 2, 2019 Author Posted April 2, 2019 yes. i have the code for a LINE. I'm trying to do this with LWPOLYLINES. Quote
BIGAL Posted April 3, 2019 Posted April 3, 2019 (edited) Ronjonp thats ok if closed else will error for every open pline. Like a U, also a closed pline can be a trapezoid with sloping sides, which OP has asked for. Would not just check vertices pt1-pt2 ang is 0 pi/2 pi 1.5pi may need to check at least 3 pts. Removed code Edited April 3, 2019 by BIGAL Quote
BIGAL Posted April 3, 2019 Posted April 3, 2019 (edited) Try this, tested on "U" pline, zigzag, rectang, one corner moved of rectang. ; check if pline has ortho sides ; By Alan H April 2019 ;(setq ent (entsel)) ;(if ent (setq co-ords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car ent)))))) (defun sqpline ( / ent ss x pt1 pt2 ang ans len) (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) (if ss (setq co-ords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0)))))) (setq x 0) (setq ans " ") (setq len (- (length co-ords) 1)) (setq pt1 (nth x co-ords)) (while (< x len) (setq pt2 (nth (setq x (+ x 1)) co-ords)) (setq ang (angle pt1 pt2)) (if (or (= ang 0.0) (= ang (/ pi 2.0)) (= ang pi) (= ang (* 1.5 pi))) (setq ans (strcat ans "Yes")) (setq ans (strcat ans "No" )) ) (setq pt1 pt2) ) (if (> (vl-string-search "No" ans )-1) (alert "pline is not square") (alert "square sided pline") ) (princ) ) (sqpline) Edited April 3, 2019 by BIGAL Quote
ronjonp Posted April 3, 2019 Posted April 3, 2019 15 hours ago, HOCHANZ said: yes. i have the code for a LINE. I'm trying to do this with LWPOLYLINES. The code I posted works on 2 vertex polylines Quote
ronjonp Posted April 3, 2019 Posted April 3, 2019 12 hours ago, BIGAL said: Ronjonp thats ok if closed else will error for every open pline. Like a U, also a closed pline can be a trapezoid with sloping sides, which OP has asked for. Would not just check vertices pt1-pt2 ang is 0 pi/2 pi 1.5pi may need to check at least 3 pts. Removed code Where did they ask for a trapezoid? The code I posted just compares the x's and y's of the start and end points .. no angle check. This is a good example where a sample drawing would be helpful. Quote
HOCHANZ Posted April 3, 2019 Author Posted April 3, 2019 RONJON - The revised does exactly what i was looking for. The criteria 1. 2 point polylines 2. non rectangular 3. not closed simple stuff. thank you. Quote
BIGAL Posted April 4, 2019 Posted April 4, 2019 ronjonp your right wasted a lot of time, the word was polylines and are generally more than 1 segment. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.