simple lisp

Discussion in 'AutoCAD' started by longshot, Mar 4, 2005.

  1. longshot

    longshot Guest

    does anyone have a lisp routine that will prompt for diameter & length &
    produce an enclosed polyline slotted hole?

    TIA
    Rob
     
    longshot, Mar 4, 2005
    #1
  2. longshot

    Paul Turvill Guest

    Like this?

    ;|
    SLOT.LSP - (c) 2004 Tee Square Graphics
    Draws a 2D slotted hole, represented by a closed
    LWPOLYLINE. User specifies endpoints of
    centerline, and radius of rounded ends.
    |;

    (defun C:SLOT (/ cmde cp1 cp2 rad1 wid ang ang1 rev lp1 lp2 lp3 lp4)
    (setq cmde (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (command "_.undo" "_be")
    (initget (+ 1 8))
    (setq cp1 (getpoint "\nFirst end center point: "))
    (initget (+ 1 8 32))
    (setq cp2 (getpoint cp1 "\nSecond end center point: ")
    rad (if rad rad 0.25)
    );setq
    (grdraw cp1 cp2 -1 1)
    (initget (+ 2 4 32 64))
    (setq rad1 (getdist cp2 (strcat "\nEnd radius <" (rtos rad) ">: "))
    rad (if rad1 rad1 rad)
    wid (* 2.0 rad)
    ang (angle cp1 cp2)
    ang1 (- ang (/ pi 2.0))
    rev (+ ang1 pi)
    lp1 (polar cp1 ang1 rad)
    lp2 (polar lp1 ang (distance cp1 cp2))
    lp3 (polar lp2 rev wid)
    lp4 (polar lp1 rev wid)
    );setq
    (entmake
    (list
    '(0 . "LWPOLYLINE")
    '(100 . "AcDbEntity")
    '(100 . "AcDbPolyline")
    '(90 . 4)
    '(70 . 129)
    (cons 10 lp1)
    (cons 10 lp2)
    '(42 . 1.0)
    (cons 10 lp3)
    (cons 10 lp4)
    '(42 . 1.0)
    );list
    );entmake
    (redraw)
    (command "_.undo" "_e")
    (setvar "cmdecho" cmde)
    (princ)
    )
    ___
     
    Paul Turvill, Mar 4, 2005
    #2
  3. longshot

    longshot Guest

    I really need to break down & learn how to do it my damn self.

    Thanks a bunch, beats having to draw them each time
    ..
    Rob
     
    longshot, Mar 4, 2005
    #3
  4. longshot

    Paul Turvill Guest

    It is possible, but I don't have a "ready" version that does that. To do so
    would just mean using the (trans) function on each of the points defined in
    the routine.
    ___
     
    Paul Turvill, Mar 4, 2005
    #4
  5. longshot

    Paul Turvill Guest

    .... or use this one. It uses the (command ...) function instead of (entmake
    ....), but it always draws the slot in the current UCS.

    ;|
    SLOT.LSP - (c) 2004 Tee Square Graphics
    Draws a 2D slotted hole, represented by a closed
    LWPOLYLINE. User specifies endpoints of
    centerline, and radius of rounded ends.
    |;

    (defun C:SLOT (/ cmde cp1 cp2 rad1 wid ang ang1 rev lp1 lp2 lp3 lp4)
    (setq cmde (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (command "_.undo" "_be")
    (initget (+ 1 8))
    (setq cp1 (getpoint "\nFirst end center point: "))
    (initget (+ 1 8 32))
    (setq cp2 (getpoint cp1 "\nSecond end center point: ")
    rad (if rad rad 0.25)
    );setq
    (grdraw cp1 cp2 -1 1)
    (initget (+ 2 4 32 64))
    (setq rad1 (getdist cp2 (strcat "\nEnd radius <" (rtos rad) ">: "))
    rad (if rad1 rad1 rad)
    wid (* 2.0 rad)
    ang (angle cp1 cp2)
    ang1 (- ang (/ pi 2.0))
    rev (+ ang1 pi)
    lp1 (polar cp1 ang1 rad)
    lp2 (polar lp1 ang (distance cp1 cp2))
    lp3 (polar lp2 rev wid)
    lp4 (polar lp1 rev wid)
    );setq
    (command "_.pline" lp1 lp2 "_a" lp3 "_l" lp4 "_a" lp1 "_cl")
    (redraw)
    (command "_.undo" "_e")
    (setvar "cmdecho" cmde)
    (princ)
    )
    ___
     
    Paul Turvill, Mar 4, 2005
    #5
  6. longshot

    Pete Guest

    The trans function can't be used in this "command" version?
     
    Pete, Mar 5, 2005
    #6
  7. longshot

    Paul Turvill Guest

    It's not needed with keyboard-style commands.
    ___
     
    Paul Turvill, Mar 5, 2005
    #7
  8. longshot

    B. W. Salt. Guest

    There is also this one from a few years ago. Attribution contained within
    the header:

    (defun C:SLOT () ; V1.00
    ;
    ; Mike Pillers 22:41:27 7/18/1986
    ; Machine/ Mechanism Design Consultant
    ; San Jose, CA (408) 280-7959
    ;
    ; Draws a long slot with rounded ends by specifying center point,
    ; width, overall length, and angle of slot.
    ; AutoCAD version 2.18 or above is required.

    (setq c1 (getpoint "Enter CENTER POINT of SLOT: ")
    sw (getdist c1 "\nEnter WIDTH of SLOT: ")
    sl (getdist c1 "\nEnter LENGTH of SLOT: ")
    phi (getangle c1 "\nEnter ANGLE of SLOT: ")
    dW (mapcar '- (polar c1 (+ phi (/ pi 2)) (/ sw 2)) c1) ;1/2 width
    vector
    dL (mapcar '- (polar c1 phi (/ (- sl sw) 2)) c1) ;1/2 length
    vector
    v1 (mapcar '+ dL (mapcar '* '(-1 -1) dW)) ; vector frm cen to
    p1
    v3 (mapcar '+ dW dL) ; vector frm cen to
    p3
    p1 (mapcar '+ c1 v1)
    p2 (polar c1 phi (/ sl 2))
    p3 (mapcar '+ c1 v3)
    p4 (mapcar '- c1 v1)
    p5 (polar c1 phi (/ sl -2))
    p6 (mapcar '- c1 v3)
    )
    (setvar "cmdecho" 0)
    (setq tmp (getvar "pdmode"))
    (setvar "pdmode" 0)
    (command "point" c1)
    (command "pline" p6 p1 "A" p3 "L" p4 "A" "CL")
    (setvar "pdmode" tmp)
    )
     
    B. W. Salt., Mar 5, 2005
    #8
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.