Jump to content

Lisp to Mirror Polyline on its longest line


Recommended Posts

Posted

Hello everyone,

I have a lot of polylines  like the ones in the picture.

image.png.89afcb10749db15a25ab7fa2dc43c0a3.png

I wan to mirror all of them on the longest side of the polyline like the following picture.

image.png.a6425ae2559146d2c38966ad60dfaa66.png

Does anyone have a lisp like that ?

new block.dwg

Posted
(defun c:pp()
  (setq ssp (ssget "X" (list '(0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ssp))
    (setq pl1 (ssname ssp (setq i (1- i)))
    	  el1 (entget pl1)
	  points (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) el1))
	  )
    (cond ((= 3 (length points)) (setq points (if (< (distance (car points) (cadr points))(distance (cadr points) (caddr points)))(reverse points)points))))
    (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(8 . "0") '(90 . 3) '(70 . 0) '(38 . 0) '(67 . 0)  (cons 10 (car points)) (cons 10 (cadr points)) (cons 10  (mapcar '- (cadr points) (mapcar '- (caddr points)(cadr points))))))    
  )
)

Does this work for you?

It draws new polylines on the layer "0". Change to suit your needs...

 

*** editing ***

Should the original polyline have been deleted? If so, please insert at the end of the loop:

 (entdel pl1)

 

  • Like 1
Posted (edited)
(defun c:Test ( / int sel ent pts 1st grp )
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq int -1 sel (ssget "_:L" '((0 . "LWPOLYLINE"))))
       (while (setq int (1+ int) ent (ssname sel int))
         (and (mapcar (function (lambda (q)
                                  (and (= (car q) 10) (setq pts (cons (cdr q) pts)))
                                  )
                                )
                      (entget ent))
              (< 1 (length pts))
              (setq 1st (car pts))
              (mapcar (function (lambda (p) (setq grp (cons (list (distance 1st p) 1st p) grp) 1st p))) (cdr pts))
              (setq grp (car (vl-sort grp (function (lambda (j k) (> (car j) (car k)))))))
              (vlax-invoke (vlax-ename->vla-object ent) 'mirror (append (cadr grp) '(0.0)) (append (caddr grp) '(0.0)))
              (entdel ent)
              (setq grp nil pts nil)
              )
         )
       )
  (princ)
  ) (vl-load-com)
           
            

 

Edited by Tharwat
ssget mode string added
  • Like 1

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