Visual LISP, AutoLISP and General Customization

Reply
Member
jsbernholt
Posts: 4
Registered: ‎01-17-2012
Message 1 of 8 (303 Views)

Need a LISP to cut a line back

303 Views, 7 Replies
01-17-2012 08:30 AM

I struggle with LISP's and would greatly appreciate if someone could find or write one.

 

What I need is a command to cut back a line. There are a lot of lines we need to add in paper space such as grid and hand rail lines. These lines get cut back 1/16" back from where they connect to. Right now I have to click on the line, grab the grip, move the mouse back and type in 1/16" and then enter, and then repeat a bunch more time on all the other lines that require a cut back. Would it be possible to have a command that once prompted would let me click on the desired line, then click on an end point, then click in the direction that I want the line cut back, and end up with a 1/16" gap?

 

Respectfully,

John S. Bernholt

Member
jsbernholt
Posts: 4
Registered: ‎01-17-2012
Message 2 of 8 (297 Views)

Re: Need a LISP to cut a line back

01-17-2012 09:10 AM in reply to: jsbernholt

I forgot to add, somtimes I need it to extend 1/16". Could the LSP mentioned above not just be able to cut the line back 1/16", but aslo be able to extend it 1/16" depending upon which side of the end point you click on?

 

 

Thanks.

*Expert Elite*
Patchy
Posts: 6,155
Registered: ‎09-16-2009
Message 3 of 8 (294 Views)

Re: Need a LISP to cut a line back

01-17-2012 09:17 AM in reply to: jsbernholt

You can use LENGTHEN command, DE for delta and type in (minus) -1/16" or 1/16" for extending.

Member
jsbernholt
Posts: 4
Registered: ‎01-17-2012
Message 4 of 8 (287 Views)

Re: Need a LISP to cut a line back

01-17-2012 09:34 AM in reply to: Patchy

I appreciate the respose, but I have to invoke the lengthen command and type DE everytime. I was looking for a LSP where I could just click on the line and then click the direct that needs to move by 1/16". I'm really looking for two clicks and not typing anything in. Thanks again for your time.

*Expert Elite*
Patchy
Posts: 6,155
Registered: ‎09-16-2009
Message 5 of 8 (285 Views)

Re: Need a LISP to cut a line back

01-17-2012 09:41 AM in reply to: jsbernholt

(defun c:LEN ()
(gc)
(setvar "cmdecho" 0)
(command "lengthen" "DE" "1/16")
)

 

 

(defun c:LEN- ()
(gc)
(setvar "cmdecho" 0)
(command "lengthen" "DE" "-1/16")
)

*Expert Elite*
Kent1Cooper
Posts: 4,953
Registered: ‎09-13-2004
Message 6 of 8 (264 Views)

Re: Need a LISP to cut a line back

01-17-2012 11:54 AM in reply to: jsbernholt

jsbernholt wrote:

....

.... Would it be possible to have a command that once prompted would let me click on the desired line, then click on an end point, then click in the direction that I want the line cut back, and end up with a 1/16" gap?

....

....somtimes I need it to extend 1/16". Could the LSP mentioned above not just be able to cut the line back 1/16", but aslo be able to extend it 1/16" depending upon which side of the end point you click on?


If they're always only Line entities, and you don't have to deal with other-than-World Coordinate Systems or other such complications, try the code below, which lets you change Lines in either direction under the same command, and as many as you want with one invocation of it.

 

Select a Line, and it will Zoom in close enough to the nearer end that you can easily see the 1/16" increment, and you pick where you want that endpoint changed to, in either direction [or to the side if you wish, though I assume you wouldn't].  It turns on Snap to 1/16", aligned with the Line and with the snap origin at that endpoint, so the new endpoint location you pick will be a clean 1/16" from the old endpoint [or a multiple of 1/16" -- you can change it by more if you want, though I assume you wouldn't].  It pauses for half a second so you can see that the Change took place, and then Zooms back and asks you to pick another.  Escape to get out of it, and all the settings return to what they were.

 

Minimally tested, and without other possible enhancements it could have, such as allowing only Lines, or conversely, working with Polylines too [much more complicated], or asking again if you miss, etc., but see what you think.

 

(defun C:CES ; = Change End by Sixteenths
  (/ *error* snapu snapa snapb ls lin ne)
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); end if
    (setvar 'snapunit snapu)
    (setvar 'snapang snapa)
    (setvar 'snapbase snapb)
    (princ)
  ); defun - *error*
  (setq
    snapu (getvar 'snapunit)
    snapa (getvar 'snapang)
    snapb (getvar 'snapbase)
  ); setq
  (setvar 'snapunit '(0.0625 0.0625))
  (while T
    (setq
      ls (entsel "\nSelect Line to change end of [Esc to exit]: "); = Line Selection
      lin (car ls)
      ne (osnap (cadr ls) "_end"); = Near End
    ); setq
    (setvar 'snapbase (list (car ne) (cadr ne)))
    (setvar
      'snapang
      (angle
        '(0 0 0)
        (vlax-curve-getFirstDeriv
          lin
          (vlax-curve-getParamAtPoint lin ne)
        ); FirstDeriv
      ); angle
    ); setvar
    (command
      "_zoom" "_c" ne 0.5
      "_change" lin "" pause
      "_delay" 500
      "_zoom" "_previous"
    ); change
  ); while
); defun

Kent Cooper
*Expert Elite*
Patchy
Posts: 6,155
Registered: ‎09-16-2009
Message 7 of 8 (261 Views)

Re: Need a LISP to cut a line back

01-17-2012 12:03 PM in reply to: Kent1Cooper

That's some fancy work you created Kent

*Expert Elite*
scot-65
Posts: 2,082
Registered: ‎12-11-2003
Message 8 of 8 (231 Views)

Re: Need a LISP to cut a line back

01-19-2012 03:55 PM in reply to: jsbernholt

Here's another method for your use (I'm in a generous mood today).

 

You can declare any value weather adding to the line or subtracting.

Just declare these in your favorite ACAD**.MNL/LSP file and have the attached file loaded.

 

(if (findfile "STR_TRIM.lsp") (load "STR_TRIM"))

 

(defun c:T16 () (STR_TRIM -0.0625)) ;trims 1/16 inch.

(defun c:smileyfrustrated:4 () (STR_TRIM 4.0)) ;stretch 4 inch.

(defun c:smileyfrustrated:B () (STR_TRIM 5.5)) ;stretch 5 1/2" for brick.

...populate with any other distances you see fit.

 

If you select something else besides a LINE, you will be asked to try again.

The nearest endpoint of where you selected will be the end that is edited.

The program lets you know if the trim value is greater than the line's length.

This program does not loop.

 

Scot-65

 

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community