Jump to content

Recommended Posts

Posted

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

 

image.png

new block.dwg

Posted

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.

Posted (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 by Isaac26a
Posted

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.

image.thumb.png.84385f14259c1d3d095624cbc7f5a87f.png

 

  • Like 1
Posted

Waiting for asdfg, I think this is what is wanted answer on right.

 

image.thumb.png.4c67534f4b01b67284fd9fac81773ce8.png

 

Posted
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 ?

Posted
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? 

 

image.png.1eab0dd4a075046d380abd845df3efbb.png

 

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.

 

image.png.fe2b1557abd318cc386d36ec3168863e.png

Posted
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? 

 

image.png.1eab0dd4a075046d380abd845df3efbb.png

 

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.

 

image.png.fe2b1557abd318cc386d36ec3168863e.png

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 

Posted

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

 

  • Like 3
Posted
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

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