Jump to content

Recommended Posts

Posted

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.

Posted (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 by ronjonp
*changed code to work on polylines
  • Thanks 1
Posted

yes. i have the code for a LINE.

I'm trying to do this with LWPOLYLINES.

Posted (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 by BIGAL
Posted (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 by BIGAL
Posted
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

Posted
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.

Posted

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.

Posted

ronjonp your right wasted a lot of time, the word was polylines and are generally more than 1 segment.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...