Jump to content

Lisp to Mirror Polyline on its longest line


asdfgh

Recommended Posts

So you could use one of these: https://stackoverflow.com/questions/36852628/autolisp-entity-data-retrieval/48857993#48857993 massoc functions to get the coordinates of the polyline, and loop though this list to work out the distance between points - the largest distance will give you the mirror line. Should be simple then to use (command "mirror"..... ) afterward.

 

 

  • Like 1
Link to comment
Share on other sites

(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
Link to comment
Share on other sites

(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
Link to comment
Share on other sites

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