Jump to content

LISP Code to Extend Line


florida35

Recommended Posts

Hi all,

 

I am new to creating lisp routines and am hoping to get some help on a routine I need. I am looking for a command that prompts you to draw a line, then prompts you to extend a line, and then deletes the initial line. I used to work at a company that had this command and it was very useful. Instead of creating a polyline, performing the extend command, and then deleting the polyline, it did all of it in one command. Any help would be greatly appreciated. Thanks.

 

 

Jim

Link to comment
Share on other sites

Welcome to CADTutor

 

There are a lot of ways to approach this

 

This would be my starting point :

 

[b][color=BLACK]([/color][/b]defun c:eline [b][color=FUCHSIA]([/color][/b]/ sp ep e1 e2 p1 ip[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq sp [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nStart Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq ep [b][color=NAVY]([/color][/b]getpoint sp [color=#2f4f4f]"\nEnd Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]grdraw sp ep 2 0[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq e1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nExtention Line Point 1:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq e2 [b][color=NAVY]([/color][/b]getpoint e1 [color=#2f4f4f]"\nExtention Line Point 2:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]setq ip [b][color=GREEN]([/color][/b]inters sp ep e1 e2 nil[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]alert [color=#2f4f4f]"These Lines Do Not Intersect"[/color][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]progn
      [b][color=MAROON]([/color][/b]setq p1 [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]> [b][color=RED]([/color][/b]distance sp ip[b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b]distance ep ip[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] sp ep[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
      [b][color=MAROON]([/color][/b]entmake [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]cons 10 p1[b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]cons 11 ip[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

The new line will default to the current entity creation properties. ie LAyer CECcolor CELtype etc

 

 

-David

Edited by David Bethel
Link to comment
Share on other sites

David,

 

I appreciate the quick reply. I was hoping for the extended line to remain part of the original line. Basically, I am hoping for the routine to be very similar to the extend command with just a temporary line added in. I know the command I have seen before worked exactly the same as extend and am hoping to duplicate that. Thanks!

 

 

 

Jim

Link to comment
Share on other sites

Hi florida

 

this one?

(defun c:extline ( / p1 p2 e)
 (while
   (setq p1 (getpoint "\nSpecify first point: "))
   (if
     (setq p2 (getpoint p1 "\nSecond point: "))
     (progn
       (setq e
         (entmakex
           (list
             '(0 . "LINE")
             (cons 10 p1)
             (cons 11 p2)
           )
         )
       )
       (command "_extend" e "")
       (while (> (getvar 'cmdactive) 0)
         (command "\\")
         )
       (entdel e)
       )
     )
   )
 (princ)
 )

Link to comment
Share on other sites

Stefan,

 

 

That is exactly what I was looking for! Thank you so much for your help. Is there any chance you have one for the same command, but using a temporary trim line instead of extend? Thank you all for being so helpful.

 

 

 

 

 

 

Jim

Link to comment
Share on other sites

Stefan,

 

That is exactly what I was looking for! Thank you so much for your help. Is there any chance you have one for the same command, but using a temporary trim line instead of extend? Thank you all for being so helpful.

 

Jim

You're welcome Jim.

 

You can replace "_extend" with "_trim" in the lisp above... Or you can hold down Shift when pick the object. Shift temporarily switch Extend to Trim, and vice versa.

Link to comment
Share on other sites

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