Autotrim lines

Discussion in 'AutoCAD' started by rseyda, Dec 30, 2003.

  1. rseyda

    rseyda Guest

    Is there a simple way to have lines that you draw get the ends trimmed back a certain distance, like 6"? I have been working with the code but I keep running into dead ends. The problem I have is if the line is at a certain angle other than zero I get undesirable results. Any help?

    Thanks,
     
    rseyda, Dec 30, 2003
    #1
  2. rseyda

    Jeff Mishler Guest

    Kinda tough to help without seeing what you are trying, but I'll start with:
    get the angle of the line immediately after drawing it (getvar "lastang"),
    set the new endpoint (polar endpt ang dist). BTW, using vla-* functions will
    make this easier.....

    Jeff

    back a certain distance, like 6"? I have been working with the code but I
    keep running into dead ends. The problem I have is if the line is at a
    certain angle other than zero I get undesirable results. Any help?
     
    Jeff Mishler, Dec 30, 2003
    #2
  3. rseyda

    Tom Smith Guest

    See the lisp attached under the "overshoots" thread. It will shorten or
    extend selected lines by a given amount on both ends.

    back a certain distance, like 6"? I have been working with the code but I
    keep running into dead ends. The problem I have is if the line is at a
    certain angle other than zero I get undesirable results. Any help?
     
    Tom Smith, Dec 30, 2003
    #3
  4. rseyda

    rseyda Guest

    I tried to check it but it said that the file was not uploaded because it was too big. It sounds like what I need though.
     
    rseyda, Dec 30, 2003
    #4
  5. rseyda

    Jim Claypool Guest

    (defun chglen (ename len / ent pt1 pt2 pt3)
    (setq
    ent (entget ename)
    pt1 (cdr (assoc 10 ent))
    pt2 (cdr (assoc 11 ent))
    pt3 (polar pt2 (angle pt1 pt2) len)
    )
    (entmod (subst (cons 11 pt3) (assoc 11 ent) ent))
    )

    (chglen (entlast) -6) will shorten the last line
    (chglen (entlast) 6) will lengthen it

    back a certain distance, like 6"? I have been working with the code but I
    keep running into dead ends. The problem I have is if the line is at a
    certain angle other than zero I get undesirable results. Any help?
     
    Jim Claypool, Dec 30, 2003
    #5
  6. rseyda

    David Bethel Guest

    Something simple like this will work:

    (defun c:sline (/ sp ep ed)
    (if (not tv)
    (progn
    (initget 7)
    (setq tv (getdist "\nTrim Distance: "))))
    (initget 1)
    (setq sp (getpoint "\nStart Point: "))
    (initget 1)
    (setq ep (getpoint sp "\nEnd Point: "))
    (command "_.LINE" sp ep "")
    (setq ed (entget (entlast)))
    (entmod (subst (cons 10 (polar (cdr (assoc 10 ed))
    (angle (cdr (assoc 10 ed))
    (cdr (assoc 11 ed)))
    tv))
    (assoc 10 ed) ed))
    (setq ed (entget (entlast)))
    (entmod (subst (cons 11 (polar (cdr (assoc 11 ed))
    (angle (cdr (assoc 11 ed))
    (cdr (assoc 10 ed)))
    tv))
    (assoc 11 ed) ed))
    (prin1))

    -David
     
    David Bethel, Dec 30, 2003
    #6
  7. rseyda

    Rudy Tovar Guest

    First you don't have to see the actual line until the end, and I'm assuming
    you're possibly going to insert a block or something at the beginning and
    end point.

    With that said you could do the following:

    (defun c:yourline (/ p1 p2 a1 a2 b1 b2)
    (setq p1 (getpoint "\nPick Start: "))
    (if p1
    (progn
    (setq p2 (getpoint p1 "\nPick End: "))
    (if p2
    (progn
    (setq a1 (angle p1 p2)
    a2 (angle p2 p1)
    b1 (polar p1 a1 6)
    b2 (polar p2 a2 6)
    )
    (entmake (list (cons 0 "LINE")(cons 10 b1)(cons 11 b2)))
    )
    )
    )
    )
    (princ)
    )
    --

    AUTODESK
    Authorized Developer
    www.Cadentity.com
    MASi


    back a certain distance, like 6"? I have been working with the code but I
    keep running into dead ends. The problem I have is if the line is at a
    certain angle other than zero I get undesirable results. Any help?
     
    Rudy Tovar, Dec 30, 2003
    #7
  8. rseyda

    mataeux Guest

    just use the LENGTHEN command

    (COMMAND "._LENGTHEN" "DELTA" -6)

    back a certain distance, like 6"? I have been working with the code but I
    keep running into dead ends. The problem I have is if the line is at a
    certain angle other than zero I get undesirable results. Any help?
     
    mataeux, Dec 30, 2003
    #8
  9. rseyda

    Tom Smith Guest

    Sorry, try again, it's only 1.4 kb and I can open it.

    was too big. It sounds like what I need though.
     
    Tom Smith, Dec 31, 2003
    #9
  10. rseyda

    Jeff Mishler Guest

    Tom,
    They are undoubtedly tryin to acces it from the web interface which is still
    not functioning as advertised. The big thing is NO attachments are seen as
    available in most groups when using the web interface.

    Jeff
     
    Jeff Mishler, Dec 31, 2003
    #10
  11. rseyda

    Tom Smith Guest

    Sorry, I'd put it in customer files except I can't seem to get that NG
    synchronized, can't do anything with it.
     
    Tom Smith, Dec 31, 2003
    #11
  12. rseyda

    Jim Claypool Guest

    Here it is.

    ;EXTLINES.LSP
    ;Extend selected lines.
    ;Written by Tom Smith

    ;Change length of line in <edata> by <amount> on both ends:
    (defun chglen (edata amount / p1 p2 a1 a2 d1 d2 short)
    (setq
    p1 (trans (cdr (assoc 10 edata)) 0 1)
    p2 (trans (cdr (assoc 11 edata)) 0 1)
    a1 (angle p2 p1)
    a2 (angle p1 p2))
    (if (minusp amount)
    (if (< (distance p1 p2) (* 2 (abs amount)))
    (progn
    (princ "\nLine is too short.")
    (setq short t))))
    (if (null short)
    (entmod
    (setq edata
    (subst
    (cons 10 (trans (polar p1 a1 amount) 1 0))
    (assoc 10 edata)
    (subst
    (cons 11 (trans (polar p2 a2 amount) 1 0))
    (assoc 11 edata)
    edata))))))

    ;Change length of multiple lines:
    (defun chgmlin (prmpt amount / oce i ss ent)
    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (command "undo" "g")
    (princ prmpt)
    (setq
    i 0
    ss(ssget '((0 . "LINE"))))
    (if ss
    (repeat (sslength ss)
    (setq
    ent (chglen (entget (ssname ss i)) amount)
    i (1+ i))))
    (command "undo" "e")
    (setvar "cmdecho" oce)
    (princ))

    (defun c:extlines (/ def)
    (princ "\nShorten or Extend lines...")
    (setq def (getvar "userr5"))
    (chgmlin
    "\nSelect lines to change: "
    (setvar
    "userr5"
    (cond
    ((getdist (strcat "\nAmount to change lines <" (rtos def) ">: ")))
    (def)))))


    (princ)
     
    Jim Claypool, Dec 31, 2003
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.