asdfgh Posted October 2, 2022 Posted October 2, 2022 Hello everyone, I am asking for a lisp to make offset between 2 selected lines. So for example i want to select the 2 lines in blue and the lisp creates line offset between them (layer doesn't matter). new block.dwg Quote
BIGAL Posted October 2, 2022 Posted October 2, 2022 There is some discrepancies in your dwg, look top left, should it be square off and confirming inside offset is shorter based on angle but outsides are sq off. Quote
Isaac26a Posted October 2, 2022 Posted October 2, 2022 (edited) Try this and let me know if it works for you ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;; Program o2l ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; 20221002 V1.0 Program to create a midpoint offset from 2 lines ;;; ;;; ;;; ;;; Isaac A ;;; ;;; https://www.cadtutor.net/forum/topic/76114-offset-between-2-selected-lines/ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (defun c:o2l (/ d enam oldec oldsmo p sset) (setq oldec (getvar 'cmdecho)) (setvar 'cmdecho 0) (vl-cmdf "_.undo" "_begin") (setq oldsmo (getvar 'osmode)) (setvar "osmode" 0) (princ "\nSelect The first line: ") (while (not (setq sset (ssget ":S:E" '((0 . "LINE,*POLYLINE"))))) (princ "\nSelect The first line: \n") ) (setq enam (ssname sset 0)) (setq p (car (cdr (entsel "\nSelect the second line: "))) d (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object enam) p) p) ) (vl-cmdf "._offset" (/ d 2.) enam p "") (setvar 'osmode oldsmo) (setvar 'cmdecho oldec) (vl-cmdf "_.undo" "_end") (princ) ) Edited October 2, 2022 by Isaac26a Quote
Jonathan Handojo Posted October 3, 2022 Posted October 3, 2022 I think there's a Centerline command that you can use instead of a LISP code. The only result is that it's a centerline entity and not a line entity. 1 Quote
BIGAL Posted October 3, 2022 Posted October 3, 2022 Waiting for asdfg, I think this is what is wanted answer on right. Quote
asdfgh Posted October 3, 2022 Author Posted October 3, 2022 8 hours ago, Isaac26a said: Try this and let me know if it works for you ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;; Program o2l ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; 20221002 V1.0 Program to create a midpoint offset from 2 lines ;;; ;;; ;;; ;;; Isaac A ;;; ;;; https://www.cadtutor.net/forum/topic/76114-offset-between-2-selected-lines/ ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (defun c:o2l (/ d enam oldec oldsmo p sset) (setq oldec (getvar 'cmdecho)) (setvar 'cmdecho 0) (vl-cmdf "_.undo" "_begin") (setq oldsmo (getvar 'osmode)) (setvar "osmode" 0) (princ "\nSelect The first line: ") (while (not (setq sset (ssget ":S:E" '((0 . "LINE,*POLYLINE"))))) (princ "\nSelect The first line: \n") ) (setq enam (ssname sset 0)) (setq p (car (cdr (entsel "\nSelect the second line: "))) d (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object enam) p) p) ) (vl-cmdf "._offset" (/ d 2.) enam p "") (setvar 'osmode oldsmo) (setvar 'cmdecho oldec) (vl-cmdf "_.undo" "_end") (princ) ) Thank you for your effort, it actually works for me but i have to select the first line and then the second line and as i will do this for large number this will be little bit time consuming, can there be a way to select both lines at once ? Quote
Jonathan Handojo Posted October 3, 2022 Posted October 3, 2022 1 hour ago, asdfgh said: Thank you for your effort, it actually works for me but i have to select the first line and then the second line and as i will do this for large number this will be little bit time consuming, can there be a way to select both lines at once ? If you want the program to work by selecting all the blue lines in one hit, what should the program generate in this situation? Plus, just want to confirm that, because you said "offset", I would assume that the program would be expected to work as such that it would only process parallel lines, is this correct? Because technically lines don't have to be parallel and can still work like the image below. Quote
asdfgh Posted October 3, 2022 Author Posted October 3, 2022 13 minutes ago, Jonathan Handojo said: If you want the program to work by selecting all the blue lines in one hit, what should the program generate in this situation? Plus, just want to confirm that, because you said "offset", I would assume that the program would be expected to work as such that it would only process parallel lines, is this correct? Because technically lines don't have to be parallel and can still work like the image below. Thank you for your reply, i don't want to select all the blue lines all at once i just want to select 2 lines which i need at once not one by one then to select other to lines and so on. For your second point, mostly the lines i have are parallel but if it is easy to make the line at middle of the blue lines (as the second picture) it would be great Quote
Jonathan Handojo Posted October 3, 2022 Posted October 3, 2022 This will do it, using regular selection like you would using the MOVE or COPY command. If the two lines are already in a group, that makes it even better because then you can just select the group in one click, but you said you've got a large number of lines, so I highly doubt you have them... Command will keep continuing until you select nothing (or 'Esc'): (defun c:foo ( / ip m p1 p2 p3 p4 ss) (defun m (a b) (mapcar '/ (mapcar '+ a b) '(2.0 2.0 2.0))) (while (setq ss (ssget '( (-4 . "<OR") (0 . "LINE") (-4 . "<AND") (0 . "LWPOLYLINE") (90 . 2) (-4 . "<NOT") (-4 . "!=") (42 . 0.0) (-4 . "NOT>") (-4 . "AND>") (-4 . "OR>") ) ) ) (if (/= (sslength ss) 2) (princ "\nSelect only two straight lines to proceed.") (progn (setq p1 (vlax-curve-getstartpoint (ssname ss 0)) p2 (vlax-curve-getendpoint (ssname ss 0)) p3 (vlax-curve-getstartpoint (ssname ss 1)) p4 (vlax-curve-getendpoint (ssname ss 1)) ) (cond ( (setq ip (inters p1 p2 p3 p4 nil)) (if (> (distance ip p1) (distance ip p2)) (mapcar 'set '(p1 p2) (list p2 p1))) (if (> (distance ip p3) (distance ip p4)) (mapcar 'set '(p3 p4) (list p4 p3))) ) ( (not (equal (angle p1 p2) (angle p3 p4) 1e-6)) (mapcar 'set '(p3 p4) (list p4 p3)) ) ) (entmake (list '(0 . "LINE") (cons 10 (m p1 p3)) (cons 11 (m p2 p4)))) ) ) ) (princ) ) 3 Quote
asdfgh Posted October 3, 2022 Author Posted October 3, 2022 2 hours ago, Jonathan Handojo said: This will do it, using regular selection like you would using the MOVE or COPY command. If the two lines are already in a group, that makes it even better because then you can just select the group in one click, but you said you've got a large number of lines, so I highly doubt you have them... Command will keep continuing until you select nothing (or 'Esc'): (defun c:foo ( / ip m p1 p2 p3 p4 ss) (defun m (a b) (mapcar '/ (mapcar '+ a b) '(2.0 2.0 2.0))) (while (setq ss (ssget '( (-4 . "<OR") (0 . "LINE") (-4 . "<AND") (0 . "LWPOLYLINE") (90 . 2) (-4 . "<NOT") (-4 . "!=") (42 . 0.0) (-4 . "NOT>") (-4 . "AND>") (-4 . "OR>") ) ) ) (if (/= (sslength ss) 2) (princ "\nSelect only two straight lines to proceed.") (progn (setq p1 (vlax-curve-getstartpoint (ssname ss 0)) p2 (vlax-curve-getendpoint (ssname ss 0)) p3 (vlax-curve-getstartpoint (ssname ss 1)) p4 (vlax-curve-getendpoint (ssname ss 1)) ) (cond ( (setq ip (inters p1 p2 p3 p4 nil)) (if (> (distance ip p1) (distance ip p2)) (mapcar 'set '(p1 p2) (list p2 p1))) (if (> (distance ip p3) (distance ip p4)) (mapcar 'set '(p3 p4) (list p4 p3))) ) ( (not (equal (angle p1 p2) (angle p3 p4) 1e-6)) (mapcar 'set '(p3 p4) (list p4 p3)) ) ) (entmake (list '(0 . "LINE") (cons 10 (m p1 p3)) (cons 11 (m p2 p4)))) ) ) ) (princ) ) That worked so well, thank you very much 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.