robertbon Posted November 10, 2014 Share Posted November 10, 2014 I have a drawing with lots of lines approx. 300mm long. Each of these lines is the centreline of a rectangle that is 20mm wide and the same length as the line. So my CAD exercise is to offset the centreline 10mm in each direction and then connect the end points of these new lines to create a rectangle. And repeat several hundred times! I know that a lisp routine should be able to do this for me and that it probably involves polar coordinates, but I am at a loss at how to do it. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 10, 2014 Share Posted November 10, 2014 Quickly done (defun c:Test (/ ss i e 1p 2p a d p1 p2 p3 p4 _line) (defun _line (q p) (entmakex (list '(0 . "LINE") (cons 10 q) (cons 11 p))) ) (if (setq ss (ssget "_:L" '((0 . "LINE")))) (repeat (setq i (sslength ss)) (setq e (entget (ssname ss (setq i (1- i)))) 1p (cdr (assoc 10 e)) 2p (cdr (assoc 11 e)) a (angle 1p 2p) d (distance 1p 2p) ) (setq p1 (polar 1p (+ a (* pi 0.5)) 10.) p2 (polar p1 a d) p3 (polar 1p (+ a (* pi 1.5)) 10.) p4 (polar p3 a d) ) (mapcar '_line (list p1 p2 p4 p3) (list p2 p4 p3 p1) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
robertbon Posted November 10, 2014 Author Share Posted November 10, 2014 That's brilliant Tharwat, exactly what I need, thank you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 10, 2014 Share Posted November 10, 2014 Here's another way, using some trans trickery: (defun c:l2r ( / i e l n p q s ) (if (setq s (ssget '((0 . "LINE")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) p (cdr (assoc 10 e)) q (cdr (assoc 11 e)) n (mapcar '- p q) l (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (mapcar x (trans y 0 n) '(10 0 0))) (list p q) ) ) '(+ -) ) ) (entmake (append '( (000 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (090 . 4) (070 . 1) ) (mapcar '(lambda ( x ) (cons 10 (trans x n 0))) (append (car l) (reverse (cadr l)))) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 10, 2014 Share Posted November 10, 2014 And another, using matrix math: (defun c:l2r ( / a d e i p q s ) (if (setq s (ssget '((0 . "LINE")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) p (cdr (assoc 10 e)) q (cdr (assoc 11 e)) a (angle p q) d (distance p q) ) (entmake (append '( (000 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (090 . 4) (070 . 1) ) ( (lambda ( m ) (mapcar '(lambda ( x ) (cons 10 (mapcar '+ p (mapcar '(lambda ( y ) (apply '+ (mapcar '* y x))) m)))) '( (0.0 -0.5) (1.0 -0.5) (1.0 0.5) (0.0 0.5) ) ) ) (list (list (* (cos a) d) (* (sin a) -20.0)) (list (* (sin a) d) (* (cos a) 20.0)) ) ) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted November 10, 2014 Share Posted November 10, 2014 That's brilliant Tharwat, exactly what I need, thank you. You're welcome . Quote Link to comment Share on other sites More sharing options...
Anakozza Posted April 8, 2022 Share Posted April 8, 2022 Hi guys, what about drawing a polyline, open or closed, and by a simple click obtain (choosing a value 1, 2, 3....) an offset polyline, like i can do in 3D with polysolid justify center. Can you help me ? Quote Link to comment Share on other sites More sharing options...
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.