Extend/Trim selected lines

Extend/Trim selected lines

jtm2020hyo
Collaborator Collaborator
4,639 Views
22 Replies
Message 1 of 23

Extend/Trim selected lines

jtm2020hyo
Collaborator
Collaborator

I request for help to create an electrical lisp to connect multiple/selected lines (POLYLINE, LINE, ARC, LWPOLYLINE, SPLINE, ELLIPSE, 3DPOLYLINE, MULTILINE, RAY, CIRCLE) in 2 options (below):

 

imagen.png

0 Likes
Accepted solutions (3)
4,640 Views
22 Replies
Replies (22)
Message 2 of 23

jtm2020hyo
Collaborator
Collaborator

PD: here sample

 

;;; Touch.LSP                                              *
;;; Small routine to align endpoints of lines to an edge.  *
;;; The edge have to be a line.                            *
;;; The routine works by calculating the point of inter-   *
;;; section and change the nearest endpoint to that point  *
;;; 2001 Stig Madsen, no rights reserved                   *
;;; modified by qjchen, the edge line can be line or polyline *

(defun C:Ttt (/ cmd ent entl spt ept sset a lent lentl lspt lept lint)
  (vl-load-com)
  (setq cmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "UNDO" "Begin")
  (while (not ent)
    (setq ent (car (entsel "Select edge line: ")))
    (if ent
      (progn
	(setq entl (entget ent))
      )
    )
  )
  (if ent
    (progn
      (redraw ent 3)
      (prompt "\nSelect lines to touch edge: ")
      (setq sset (ssget '((0 . "LINE")))
	    a 0
      )
      (if sset
	(repeat (sslength sset)
	  (setq lentl (entget (setq lent (ssname sset a)))
		lspt (cdr (assoc 10 lentl))
		lept (cdr (assoc 11 lentl))
	  )
	  (setq entttt (ssname sset a))
	  (setq lint (nth 0 (x_intlst ent entttt acExtendOtherEntity)))
	  (if lint
	    (progn

	      (if (< (distance lint lspt) (distance lint lept))
		(entmod (subst
			  (cons 10 lint)
			  (assoc 10 lentl)
			  lentl
			)
		)
		(entmod (subst
			  (cons 11 lint)
			  (assoc 11 lentl)
			  lentl
			)
		)
	      )
	    )
	  )
	  (setq a (1+ a))
	)
	(princ "\nNo objects found")
      )
      (redraw ent 4)
    )
    (princ "\nNo edge selected")
  )
  (setvar "CMDECHO" cmd)
  (command "UNDO" "End")
  (princ)
)

;;; by kuangdao at xdcad
(defun x_intlst (obj1 obj2 param / intlst1 intlst2 ptlst)

  (if (= 'ENAME (type obj1))
    (setq obj1 (vlax-ename->vla-object obj1))
  )
  (if (= 'ENAME (type obj2))
    (setq obj2 (vlax-ename->vla-object obj2))
  )
  (setq intlst1 (vlax-variant-value (vla-intersectwith obj1 obj2 param)))
  (if (< 0 (vlax-safearray-get-u-bound intlst1 1))
    (progn
      (setq intlst2 (vlax-safearray->list intlst1))
      (while (> (length intlst2) 0)
	(setq ptlst (cons (list (car intlst2) (cadr intlst2) (caddr intlst2))
			  ptlst
		    )
	      intlst2 (cdddr intlst2)
	)
      )
    )
  )
  ptlst
)

imagen.pngimagen.png

 

source:

https://www.theswamp.org/index.php?topic=3517.0

 

hotel:

trivago

 

0 Likes
Message 3 of 23

Sea-Haven
Mentor
Mentor

I was redoing this method for another post. Will finish now and do in or out. Just need a bit of time.

 

screenshot142.png

Message 4 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

Try this 

 

(defun c:mfillet (/ pt1 pt2 pt3 pt4 obj1 obj2 lst1 lst2 lst dist1 dist2 x ss ss2)

  (setq pt1 (getpoint "Pick outside"))
  (setq pt2 (getpoint pt1 "Pick inside"))
  (setq pt3 (getpoint pt2 "Pick outside"))

  (setq lst (list pt1 pt2))
  (setq ss (ssget "F" lst (list (cons 0 "*line"))))

  (setq lst (list pt2 pt3))
  (setq ss2 (ssget "F" lst (list (cons 0 "*line"))))

  (if (= (sslength ss) (sslength ss2))
    (progn
      (command "line" pt1 pt2 "")
      (setq obj1 (vlax-ename->vla-object (entlast)))
      (command "Line" Pt2 pt3 "")
      (setq obj2 (vlax-ename->vla-object (entlast)))

      (setq lst1 '())
      (repeat (setq x (sslength ss))
        (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
        (setq pt4 (vlax-invoke obj1 'intersectWith obj acExtendThisEntity))
        (setq dist1 (distance pt2 pt4))
        (setq lst1 (cons (list dist1 pt4) lst1))
      )
      (setq lst1 (vl-sort lst1
                          (function (lambda (e1 e2)
                                            (< (car e1) (car e2))
                                    )
                          )
                 )
      )

      (setq lst2 '())
      (repeat (setq x (sslength ss2))
        (setq obj (vlax-ename->vla-object (ssname ss2 (setq x (- x 1)))))
        (setq pt4 (vlax-invoke obj2 'intersectWith obj acExtendThisEntity))
        (setq dist1 (distance pt2 pt4))
        (setq lst2 (cons (list dist1 pt4) lst2))
      )
      (setq lst2 (vl-sort lst2
                          (function (lambda (e1 e2)
                                            (< (car e1) (car e2))
                                    )
                          )
                 )
      )

      (vla-delete obj1)
      (vla-delete obj2)

      (Setq choice (getstring "\n Press Enter for In any key for out"))

      (if (= choice "") (setq lst1 (reverse lst1)))
      (setvar 'filletrad 0.0)
      (setq x 0)
      (repeat (sslength ss)
        (setq pt1 (cadr (nth x lst1)))
        (setq pt2 (cadr (nth x lst2)))
        (command "fillet" pt1 pt2)
        (setq x (+ x 1))
      )
    )

  )
  (princ)
)
(c:mfillet)
Message 5 of 23

jtm2020hyo
Collaborator
Collaborator

I tried, but I can not make it work.

 

can you explain the use please?

0 Likes
Message 6 of 23

Sea-Haven
Mentor
Mentor

Like the image just pick P1 P2 P3 in that order, maybe remove last line (c:mfillet) but you will need to type mfillet. 

 

Start test with simple example and get more complex.

 

screenshot145.png

Message 7 of 23

jtm2020hyo
Collaborator
Collaborator

I do not know what I did bad. that does not work for me.

 

imagen.png

 

 

Command: MFILLET
Pick outsidePick insidePick outsideline
Specify first point:
Specify next point or [Undo]:
Specify next point or [eXit/Undo]:
Command: Line
Specify first point:
Specify next point or [Undo]:
Specify next point or [eXit/Undo]:
Command:
 Press Enter for In any key for out
fillet Unknown command "FILLET".  Press F1 for help.

Command:
Command:
Command: fillet Unknown command "FILLET".  Press F1 for help.

Command:
Command:
Command: fillet Unknown command "FILLET".  Press F1 for help.

Command:
Command:
Command: fillet Unknown command "FILLET".  Press F1 for help.

Command:
Command:
Command: fillet Unknown command "FILLET".  Press F1 for help.

Command:
Command:
Command:

PD: attached drawing

 

imagen.png

0 Likes
Message 8 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

There may have been something odd in the copy and paste to a file, so here is the file to try. One thing I did do is SNAP OFF.

 

Just thought add (vl-load-com) as 1st line.

Message 9 of 23

jtm2020hyo
Collaborator
Collaborator

here my test.

 

snap on:

works partially.

selecting multiple lines do not work.

 

imagen.png

imagen.png

 

imagen.png

 

snap off:

works awesome

 

imagen.png

 

imagen.png

 

 

just one last request more (if possible), can you add the "undo multiple" command and let user create 2 different no consecutive lines (4 points)? for example:

 

imagen.png

0 Likes
Message 10 of 23

Sea-Haven
Mentor
Mentor

You must draw in a L as per out in out for it to work this is required to work out the join order, doing it with variations should only reverse the way the fillets are done inside or outside as I have called them. Do not need ortho on. 

 

Yes could add a num question say 4 means 1st 4, -4 means last 4.

Message 11 of 23

jtm2020hyo
Collaborator
Collaborator

IF we have the option to do 2 separates lines to determinate the order the result should be this.

 

imagen.pngimagen.png

 

IMO should work. that do not form a square. Another suggestion might be: add an option to let 2 polylines to choice the sort order.

 

just a question here:

why this does not works for AutoCAD MEP 2020 student version with snap "off" and "on"?

 

0 Likes
Message 12 of 23

Sea-Haven
Mentor
Mentor

If you change the in out bit and add an extra point pt4 it so it makes 2 lines still but compare say pt1 - pt2 and pt3 - pt4 a pretty simple code adjust have a go. 

 

(setq pt1 (getpoint "Pick outside"))
  (setq pt2 (getpoint pt1 "Pick inside"))
  (setq pt3 (getpoint pt2 "Pick inside"))
(setq pt4 (getpoint pt2 "Pick outside"))

Do only 2 etc press f3 so snap off zoom in cross 2 lines cross 2 lines all done no code edit required. 

Message 13 of 23

jtm2020hyo
Collaborator
Collaborator

Hello again sir, I am interested in your house again, but I can not replicate how to use your lisp. Can you do a guide step to step for lisp? I mean for do both type of connections as showed in the image above

0 Likes
Message 14 of 23

Sea-Haven
Mentor
Mentor

Look at message 3 and 6.

Message 15 of 23

jtm2020hyo
Collaborator
Collaborator

@Sea-Haven wrote:

Like the image just pick P1 P2 P3 in that order, maybe remove last line (c:mfillet) but you will need to type mfillet. 

 

Start test with simple example and get more complex.

 

screenshot145.png


In the image, I can see 1 initial polyline and 2 types of connection, with your lisp I can create the first type of connection (middle) but I tried the second type of connection (right) can not be done with your instruction. you mentioned that I need to disable Object Snap, I tried, but I still can not do it. please, teach us to do the second one (right).

0 Likes
Message 16 of 23

Sea-Haven
Mentor
Mentor

Just in case this version definately works. Just press enter or any key when asked in will get an in or out answer.

 

 

Message 17 of 23

jtm2020hyo
Collaborator
Collaborator

@Sea-Haven wrote:

Just in case this version definately works. Just press enter or any key when asked in will get an in or out answer.

 

 


enter for in

any key for out

 

when I press any key as abcd... do nothing, so I think I should press SPACE BAR. is correct?

 

I tried to use it again but know I received this message. the lisp, after request press key, do nothing, just show that FILLET command is unknow

 

Command: mfillet
Pick outsidePick insidePick outside
 Press Enter for In any key for out
Unknown command "FILLET".  Press F1 for help.

 

 

0 Likes
Message 18 of 23

Sea-Haven
Mentor
Mentor

Are you using a non English version of Autocad ?

 

Change this line (command "_fillet" pt1 pt2)

0 Likes
Message 19 of 23

jtm2020hyo
Collaborator
Collaborator

I have the next message when I tried use it in 4 polylines, in AutoCAD Vanilla student (Spanish):

Command: MFILLET
Pick outsidePick insidePick outside; error: bad ssget mode string
Command:

 

 

 

I have the next message when I tried use it in 4 polylines, in AutoCAD MEP student (English):

Command: mfillet
Pick outsidePick insidePick outside
 Press Enter for In any key for out
Unknown command "FILLET".  Press F1 for help.
Unknown command "FILLET".  Press F1 for help.
Unknown command "FILLET".  Press F1 for help.
Unknown command "FILLET".  Press F1 for help.

 

 

PD: attached the lisp that was tested with the suggested modifications.

 

 

0 Likes
Message 20 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

trying to find the international coding reference like (command "._FILLET"  or (command "_.FILLET"