Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Extend a line without borders

16 REPLIES 16
Reply
Message 1 of 17
ammar.ahmed.iaeste
647 Views, 16 Replies

Extend a line without borders

Hi there Smiley Happy

 

I want a lisp code that makes me extend a line as follow: 

 

1. Select a line (l1)

2. Select any point in space (pt1)

3. Create a line (l2) passing by (pt1) and perpendicular to (l1) 

4. Extend to l1 to l2 

5. Delete the line (l2)

 

Thanks in advance 🙂

16 REPLIES 16
Message 2 of 17
pbejse
in reply to: ammar.ahmed.iaeste


@ammar.ahmed.iaeste wrote:

Hi there Smiley Happy

 

I want a lisp code that makes me extend a line as follow: 

 

1. Select a line (l1)

2. Select any point in space (pt1)

3. Create a line (l2) passing by (pt1) and perpendicular to (l1) 

4. Extend to l1 to l2 

5. Delete the line (l2)

 

Thanks in advance 🙂


Cant see the logic on this one.

 

Aat any rate, i think the native "change" command will work for you

 

command: Change or -ch

 

Result may vary depending on the orthomode settings

Message 3 of 17
ammar.ahmed.iaeste
in reply to: pbejse

Ok I know it's hard to explain, but at least what I want is a lisp routine that return the angle of any selected line please. I think I can manage the rest.

Message 4 of 17
pbejse
in reply to: ammar.ahmed.iaeste


@ammar.ahmed.iaeste wrote:

Ok I know it's hard to explain, but at least what I want is a lisp routine that return the angle of any selected line please. I think I can manage the rest.


Tell you what, if its that hard to explain, the least you can do is post a picture of "before" and "after". A sample cad drawing would be enough.

 

Message 5 of 17


@ammar.ahmed.iaeste wrote:

.... 

I want a lisp code that makes me extend a line as follow: 

 

1. Select a line (l1)

2. Select any point in space (pt1)

3. Create a line (l2) passing by (pt1) and perpendicular to (l1) 

4. Extend to l1 to l2 

5. Delete the line (l2)

....


It can be done without drawing the temporary Line [minimally tested]:

 

(defun C:LE2P (/ lin pt); = Line Extend to Point
  (setq
    lin (car (entsel "\nSelect Line: ")); could use selection controls, etc....
    ldata (entget lin)
    linstart  (cdr (assoc 10 ldata))
    linend (cdr (assoc 11 ldata))
    pt (getpoint "\nSelect Point: ")
  ); setq
  (command "_.change" lin ""
    "_none"
    (inters linstart linend pt (polar pt (+ (angle linstart linend) (/ pi 2)) 1) nil)
  ); command
); defun

 

EDIT:  That may Trim rather than Extend the selected Line, depending on the relationship, but that would also be a possibility if it did it as you describe and a Fillet command was used.  If you don't want it to do that, i.e. if you want it to leave the selected Line alone if it already crosses the perpendicular direction from the designated point, that can be accounted for, with [using an Extend command] or without drawing a temporary Line.

Kent Cooper, AIA
Message 6 of 17
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
.... 

(defun C:LE2P (/ lin pt); = Line Extend to Point
  ....


Oops -- didn't get all the local variables in there....

 

(defun C:LE2P (/ lin ldata linstart linend pt); = Line Extend to Point

Kent Cooper, AIA
Message 7 of 17
alanjt_
in reply to: Kent1Cooper

If I understand correctly, the Lengthen command, using the Dynamic fucntion should do what you are wanting. 

Message 8 of 17
Kent1Cooper
in reply to: alanjt_


@alanjt_ wrote:

If I understand correctly, the Lengthen command, using the Dynamic fucntion should do what you are wanting. 


Why yes, it does -- didn't think of that!  If that's all they want to do, and can do it manually, that's better, but oddly, I find in a very quick experiment that doing it in AutoLisp [for example, as part of a larger routine] doesn't give the result I anticipate:

 

(command "_.lengthen" "_dynamic" LineEntityName pt "")

 

behaves unexpectedly -- it moves the farther [from the given point] end of the Line to the place you want, rather than the nearer end, regardless of which end is the start and which the end of the Line!  I didn't try a lot of configurations, so it may not always work that way.  [And it may not be the same in all versions, and I have an older one here -- I'll have to try it where I have Acad2015, later.]

Kent Cooper, AIA
Message 9 of 17
alanjt_
in reply to: Kent1Cooper

Works fine in c3d 2014. Try adding a "_non" before the pt variable.

Message 10 of 17
Kent1Cooper
in reply to: alanjt_


@alanjt_ wrote:

Works fine in c3d 2014. Try adding a "_non" before the pt variable.


The Osnap issue wasn't relevant to my original trial [nothing in the vicinity that it could have snapped to, whether or not any running modes were on], but I tried adding that anyway, and it made no difference.  I can only assume it must be version-dependent, unless there's something else we're not thinking of.

Kent Cooper, AIA
Message 11 of 17
alanjt_
in reply to: Kent1Cooper

Not sure, but honestly, I would make the macro just: (command "_.lengthen" "_dynamic")

Message 12 of 17
Kent1Cooper
in reply to: alanjt_


@alanjt_ wrote:

Not sure, but honestly, I would make the macro just: (command "_.lengthen" "_dynamic")


That sounds like it would do what the OP described, provided it's in isolation, and not part of some larger routine that may have the Line and the point otherwise designated.

Kent Cooper, AIA
Message 13 of 17
alanjt_
in reply to: Kent1Cooper

True, but a limited question receives a limited answer. 

Message 14 of 17
Kent1Cooper
in reply to: pbejse


@pbejse wrote:
.... i think the native "change" command will work for you

.... 

Result may vary depending on the orthomode settings


That would do what they're describing only with Ortho on and if the selected Line is orthogonal.  For a diagonal Line, even with Ortho off, it would need a calculated Change point, and couldn't use the User's selected point unless that happens to fall on the extension of the Line.  But it makes me aware that my suggestion [if the Lengthen Dynamic approach doesn't fill the bill for some reason] should have Ortho turned off to work correctly with diagonal Lines.

Kent Cooper, AIA
Message 15 of 17

The 'lengthen' command, with the 'dynamic' option, evaluates the entity name and a supplied point, to be able to define which object end/start point will be modified, so I would use something like this

 

(defun c:demo ( / pt sel)
(if (and (setq sel (entsel "\nSelect line end to modify: "))
	 (setq pt (getpoint "\nEnter reference point: "))
	 )
  (command "_.lengthen" "dy" sel pt "")
  )
(princ)
)

 

HTH

Henrique

EESignature

Message 16 of 17
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@pbejse wrote:
.... i think the native "change" command will work for you

.... 

Result may vary depending on the orthomode settings


That would do what they're describing only with Ortho on and if the selected Line is orthogonal.  For a diagonal Line, even with Ortho off, it would need a calculated Change point, and couldn't use the User's selected point unless that happens to fall on the extension of the Line.  But it makes me aware that my suggestion [if the Lengthen Dynamic approach doesn't fill the bill for some reason] should have Ortho turned off to work correctly with diagonal Lines.


I concur. Here's my take.

 

(Defun c:demo (/ ss pt1 i e ort)
(setq ort (getvar 'orthomode))
(setvar 'orthomode 0) 
  (if (and (setq ss (ssget ":L" '((0 . "LINE"))))
	   (setq Pt1 (getpoint "\nPick Reference point:"))
      )
    (repeat (setq i (sslength ss))
      (command "change"
	       (vlax-curve-getStartPoint
		 (setq e (ssname ss (setq i (1- i))))
	       )
	       ""
	       "_non"
	       (vlax-curve-getClosestPointTo e pt1 t)
      )
    )
  )(setvar 'orthomode ort)
  (princ)
)

 

Message 17 of 17
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

... in a very quick experiment that doing it in AutoLisp ... doesn't give the result I anticipate:

(command "_.lengthen" "_dynamic" LineEntityName pt "")

 

behaves unexpectedly -- it moves the farther [from the given point] end of the Line to the place you want, rather than the nearer end, regardless of which end is the start and which the end of the Line!  ....  [And it may not be the same in all versions, and I have an older one here -- I'll have to try it where I have Acad2015, later.]


I've now tried it in Acad2015, and it does the same backwards thing.  Since that is the same as the operational part of hmsilva's routine, I loaded and tried that routine, and it doesn't do it!  I'm completely at a loss to explain the difference....

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost