asdfgh Posted September 13, 2023 Posted September 13, 2023 Hello everyone, I have a lot of polylines like the ones in the picture. I wan to mirror all of them on the longest side of the polyline like the following picture. Does anyone have a lisp like that ? new block.dwg Quote
Steven P Posted September 13, 2023 Posted September 13, 2023 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. 1 Quote
fuccaro Posted September 14, 2023 Posted September 14, 2023 (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) 1 Quote
Tharwat Posted September 14, 2023 Posted September 14, 2023 (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 September 14, 2023 by Tharwat ssget mode string added 1 Quote
asdfgh Posted September 17, 2023 Author Posted September 17, 2023 @Tharwat @fuccaro @Steven P Thanks for your replies 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.