+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    May 2009
    Posts
    7

    Default lisp to draw line on same angle as line picked

    Hi All,
    Does anyone have a lisp or can help me make one that can draws a line based on the angle of a line that is selected?

    Example: I have a line that is on a 45 degrees
    and I have text at the end of the line
    I want to select the line and have a predetermined line
    drawn in after the text based on scale of the drawing

    see attached picture for better clarification.

    Thank you
    Attached Images

  2. #2
    Forum Newbie
    Using
    AutoCAD 2009
    Join Date
    May 2009
    Posts
    7

    Default

    can anyone help?

  3. #3
    Super Member Raggi_Thor's Avatar
    Using
    AutoCAD 2008
    Join Date
    Aug 2007
    Location
    Trondheim, NORWAY
    Posts
    718

    Default

    How about OSNAP Extension turned on?
    Or in this (special?) case Polar angle 45?
    Mvh, Kvedja, Kind Regards,
    Ragnar Thor Mikkelsen
    http://www.DESIGNDATA.no/English.htm

  4. #4
    Full Member LauKwokFai's Avatar
    Discipline
    See details...
    LauKwokFai's Discipline Details
    Occupation
    Interior Design, CAD superior
    Discipline
    See details below.
    Details
    Interior Design
    Using
    AutoCAD 2011
    Join Date
    Sep 2009
    Location
    Hong Kong
    Posts
    63

    Default

    try "snapang" maybe...

    (setq draw_obj (entget (car (entsel))))
    (command "snapang" (cdr (assoc 10 draw_obj)) (cdr (assoc 11 draw_obj)))

  5. #5
    Super Member Raggi_Thor's Avatar
    Using
    AutoCAD 2008
    Join Date
    Aug 2007
    Location
    Trondheim, NORWAY
    Posts
    718

    Default

    See here, turn on Extension and Parallell.
    Then draw your line, use extension to find the first point, move the cursor over your first line and then to the second point to get the Paralell Osnap.
    Attached Images
    Mvh, Kvedja, Kind Regards,
    Ragnar Thor Mikkelsen
    http://www.DESIGNDATA.no/English.htm

  6. #6
    Full Member
    Using
    AutoCAD 2009
    Join Date
    Jul 2009
    Posts
    41

    Default

    not sure if this is what you want, good exercise it was none the less

    Code:
    (defun c:angline (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad)
      (setq scale (getvar "cannoscalevalue"))
      (setq lne (entsel "\nSelect line: "))
      (setq selpt (cadr lne))
      (setq pt1 (cdr (assoc 10 (entget (car lne)))))
      (setq pt2 (cdr (assoc 11 (entget (car lne)))))
      (setq dist1 (/ (distance pt1 pt2) 2))
      (setq dist2 (distance pt1 selpt))
      (if (< dist1 dist2)
        (progn
        (setq rad (angle pt1 pt2))
        (setq bp (polar pt2 rad (* 1 (/ 1 scale))))
        (setq bp2 (polar bp rad 1))
        (command "_.line" bp bp2 "")
        (command "_.lengthen" "dy" bp2  pause)
        )
        (progn
        (setq rad (angle pt2 pt1))
        (setq bp (polar pt1 rad (* 1 (/ 1 scale))))
        (setq bp2 (polar bp rad 1))
        (command "_.line" bp bp2 "")
        (command "_.lengthen" "dy" bp2 pause "" "")
        )
      )
      (princ)
    )
    this is probably what many of you would call 'clumpsy' code, and as I'm very much a learner I'd love some input on this code and how to possibly improve it

  7. #7
    Super Member Raggi_Thor's Avatar
    Using
    AutoCAD 2008
    Join Date
    Aug 2007
    Location
    Trondheim, NORWAY
    Posts
    718

    Default

    I tried your code in Acad 2010.
    It starts Lengthen again it seems.
    Maybe you need an extra (Command) to cancel everything?

    Otherwise it works very good.
    Mvh, Kvedja, Kind Regards,
    Ragnar Thor Mikkelsen
    http://www.DESIGNDATA.no/English.htm

  8. #8
    Senior Member
    Using
    AutoCAD 2011
    Join Date
    Mar 2009
    Location
    Queensland, Australia
    Posts
    350

    Default

    Quote Originally Posted by dhl View Post
    not sure if this is what you want, good exercise it was none the less

    Code:
    (defun c:angline (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad)
      (setq scale (getvar "cannoscalevalue"))
      (setq lne (entsel "\nSelect line: "))
      (setq selpt (cadr lne))
      (setq pt1 (cdr (assoc 10 (entget (car lne)))))
      (setq pt2 (cdr (assoc 11 (entget (car lne)))))
      (setq dist1 (/ (distance pt1 pt2) 2))
      (setq dist2 (distance pt1 selpt))
      (if (< dist1 dist2)
        (progn
        (setq rad (angle pt1 pt2))
        (setq bp (polar pt2 rad (* 1 (/ 1 scale))))
        (setq bp2 (polar bp rad 1))
        (command "_.line" bp bp2 "")
        (command "_.lengthen" "dy" bp2  pause)
        )
        (progn
        (setq rad (angle pt2 pt1))
        (setq bp (polar pt1 rad (* 1 (/ 1 scale))))
        (setq bp2 (polar bp rad 1))
        (command "_.line" bp bp2 "")
        (command "_.lengthen" "dy" bp2 pause "" "")
        )
      )
      (princ)
    )
    this is probably what many of you would call 'clumpsy' code, and as I'm very much a learner I'd love some input on this code and how to possibly improve it
    I am by no means an expert but two things I'd suggest to improve your code is error trapping for your entsel and pts, eg:
    Code:
     (if (setq lne (entsel "\nSelect line: ")) 
        (progn ...)
        (princ "\nNothing Selected."))
    The other thing is that you'll notice with other peoples code pretty soon, you can assign multiple variables with setq, eg:
    Code:
    (setq a 1 b 2 
        c 3)
    sets a = 1, b = 2 and c = 3
    Hope that helps a bit.

  9. #9
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,137

    Default

    Would something like this help?
    Code:
    (defun c:PAR (/ #Obj #Point)
      (vl-load-com)
      (and (setq #Obj (car (entsel "\nSelect line: ")))
           (eq "LINE" (cdr (assoc 0 (entget #Obj))))
           (setq #Point (getpoint "\nSpecify first point: "))
           (vl-cmdf "_.line"
                    "_non"
                    #Point
                    (strcat "<" (angtos (vla-get-angle (vlax-ename->vla-object #Obj)) 0 4))
                    PAUSE
                    ""
           ) ;_ vl-cmdf
      ) ;_ and
      (princ)
    ) ;_ defun
    When you get to the point to pick a point, just use the osnap override "ext" and mouse-over the other line.
    Last edited by alanjt; 20th Oct 2009 at 02:48 am.
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  10. #10
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,137

    Default

    Registered forum members do not see this ad.

    Oh, and here's a nice addon, perpendicular.

    Code:
    (defun c:Per (/ #Obj #Point #Ang)
      (and (setq #Obj (entsel "\nSelect line: "))
           (eq "LINE" (cdr (assoc 0 (entget (car #Obj)))))
           (or (setq #Point (getpoint "\nSpecify first point <At Selection>: "))
               (setq #Point (vlax-curve-GetClosestPointTo (car #Obj) (cadr #Obj)))
           ) ;_ or
           (setq #Ang (angtos (+ (* 0.5 pi) (vla-get-angle (vlax-ename->vla-object (car #Obj)))) 0 4))
           (vl-cmdf "_.line" "_non" #Point (strcat "<" #Ang) PAUSE "")
      ) ;_ and
      (princ)
    ) ;_ defun
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

Similar Threads

  1. How do i draw line at specific angle?
    By nbaryosef in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 20
    Last Post: 14th Jan 2013, 07:54 pm
  2. draw a line using VBA with an angle and a length?
    By wbluem88 in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 12th Aug 2008, 06:07 pm
  3. A Challenege - Draw Line, Blocks Placed on Line
    By CADken in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 5th Feb 2008, 03:46 am
  4. Offset arc, connection line draw lisp
    By romparkin in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 16th Apr 2007, 06:53 pm
  5. Line under angle
    By TevsR in forum AutoCAD Beginners' Area
    Replies: 12
    Last Post: 9th Jan 2004, 04:16 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts