Polar Lisp Help...

Discussion in 'AutoCAD' started by akdrafter, Jan 2, 2004.

  1. akdrafter

    akdrafter Guest

    Hello,

    I am trying to figure out how to do this:

    Line1 from PointA to PointB
    Line2 from PointC to PointD
    Line3 from Midpoint of Line1 to Midpoint of Line2

    Can anyone suggest some code to do this?

    Thanks in advance.

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Jan 2, 2004
    #1
  2. akdrafter

    Mike Weaver Guest

    I would use this approach:
    (defun test( / p1 p2 p3 p4 p5 p6)
    (setq
    p1 (getpoint)
    p2 (getpoint p1)
    p3 (getpoint)
    p4 (getpoint p3)
    p5 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P1 P2)
    p6 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P3 P4)
    )
    (command "._line" p1 p2 "")
    (command "._line" p3 p4 "")
    (command "._line" p5 p6 "")
    )

    Using Polar doesn't take into account differing Z ordinates (which may be
    your preference):

    (defun test2 ( / p1 p2 p3 p4 p5 p6)
    (setq
    p1 (getpoint)
    p2 (getpoint p1)
    p3 (getpoint)
    p4 (getpoint p3)
    a1 (angle p1 p2)
    a2 (angle p3 p4)
    p5 (polar p1 a1 (/ (distance p1 p2) 2.0))
    p6 (polar p3 a2 (/ (distance p3 p4) 2.0))
    )
    (command "._line" p1 p2 "")
    (command "._line" p3 p4 "")
    (command "._line" p5 p6 "")
    )

    HTH,
    Mike Weaver
     
    Mike Weaver, Jan 2, 2004
    #2
  3. akdrafter

    akdrafter Guest

    Mike,

    Excellent. Thank you. I have pasted the code into this message as I seem to always have problems with attaching files.

    Basically this routine is for the structural discipline. It is a Lintel creation routine. However, there are still a couple of things that would be useful. I am not sure if you can help me with this, but if you can. That would be excellent.

    First, if the user does not actually pick the endpoint of a line at any of the 4 required points, prompt the user to pick an endpoint before storing that point and moving on to the next point.

    Second, how to stretch the p3 to p4 line 4" on either side.

    Again, I appreciate your help. I have 100's of these things to create and don't look forward to doing plain ol commands to do it. That is why I am writing this routine, with your help of course. :)

    Thanks again.

    "Catch" Ya Later,
    AKDRAFTER

    ;;;
    ;;; Lintel Creation Routine
    ;;;
    ;;; Timothy J. Jaronik Sr.
    ;;; January, 2004
    ;;;
    ;;; Credit to Mike Weaver for helping me with this routine.
    ;;
    ;;
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (prompt "\nResetting System Variables... ")
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun c:LINTEL (/)
    (setq CME(getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (setq OSM(getvar "OSMODE"))
    (setvar "OSMODE" 1)
    (setq SNM(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (setq CLA(getvar "CLAYER"))
    (command "-layer" "thaw" "S-LINTEL" "on" "S-LINTEL" "make" "S-LINTEL" "color" "7" "S-LINTEL" "lt" "center2" "S-LINTEL" "")
    (command "-layer" "thaw" "S-HWALL" "on" "S-HWALL" "make" "S-HWALL" "color" "1" "S-HWALL" "lt" "hidden" "S-HWALL" "")
    ;;;
    (setvar "CLAYER" "S-HWALL")
    (setq P1A(getpoint "\nSelect First Wall Opening 1st Point: "))
    (setq P1B(getpoint P1A "\nSelect First Wall Opening 2nd Point: "))
    (command "._line" P1A P1B "")
    (setq P2A(getpoint "\nSelect Second Wall Opening 1st Point: "))
    (setq P2B(getpoint P2A "\nSelect Second Wall Opening 2nd Point: "))
    (command "._line" P2A P2B "")
    (setq
    P3 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P1A P1B)
    P4 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P2A P2B)
    )
    ;;;
    (setvar "CLAYER" "S-LINTEL")
    (command "._line" P3 P4 "")
    ;;;
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (princ)
    )
     
    akdrafter, Jan 2, 2004
    #3
  4. akdrafter

    Mark Propst Guest

    fwiw
    any time you use the command method
    (command "._line" P2A P2B "")
    be sure to include the none osnap
    (command "._line" "_non" P2A "_non" P2B "")
    to avoid problems with running osnaps

    the 4 required points, prompt the user to pick an endpoint before storing
    that point and moving on to the next point.

    your osmode 1 should give the user endpoints if they are careful
    otherwise, it would be extra processing to identify every line in the
    drawing and see if the picked point was equal to any start or end point of
    any line in the dwg. and how would you confirm which line was desired?
    unless you select the lines in addition to the points it would be a lot of
    work to confirm correct point acquisition it seems to me. and that would add
    an extra step in the user interface.
    maybe an extra prompt threatening disembowelment if the user doesn't pick an
    endpoint?
    :)

    (setq p3(polar p3 (angle p4 p3) 4))
    (setq p4(polar p4 (angle p3 p4) 4))
     
    Mark Propst, Jan 2, 2004
    #4
  5. akdrafter

    akdrafter Guest

    Mark,

    Doesn't storing the current osmode, changing osmode to 1 then returning to the stored osmode at the end of the routine cover that?

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Jan 2, 2004
    #5
  6. akdrafter

    Scot-65 Guest

    Akdrafter,

    By adding the value of 16384 to the current value of OSMODE, OSMODE is thus supressed.

    Then check value in the *Error* handling to see if OSMODE
    is equal to or greater than 16384. If yes, subtract 16384
    from the current OSMODE value to restore this setting...

    Very few of my programs set specific OSMODE settings while
    the user is inputing his values. When executing the program
    (third section of a typical program), OSMODE is supressed
    in ther manner shown above.

    1) Get User input.
    2) Test User input for correctness.
    3) If User imput is to satisification, Execute the program, otherwise kick it out and try again.


    (does not work in all conditions, please no grief...)

    Scot-65
     
    Scot-65, Jan 2, 2004
    #6
  7. akdrafter

    Mark Propst Guest

    setting the osmode to 1 when user is picking points should (if user is
    carefull) give you the 'endpoint' that you want.
    then manipulating that point to get P2A and P2B or whatever (if you wanted
    to stretch it 4 inches for example) will give you a new point that is not
    the original endpoint
    then the (command "line" P2A P2B "") might snap back to the endpoints
    depending on zoom factor, pick box size etc
    that's why if you have an exact point P2A that you want, you don't want the
    osnap to modify it when you get to the command "line" statement, thus the
    use of the "_non" osnap modifier.
    theoretically you could also do (setvar"osmode" 0) before the command
    statement to get the same effect but in my experience that doesn't always
    work, I never could find out why it did sometimes and sometimes not, so I
    got in the habit of using "_non" and I've never had it fail.
    even better is entmake or now vla-addline etc
    but for starters "command" is easiest and when you get the basic program
    doing what you want you can finese the methods of how to get there.

    Others may disagree. Just my $0.02
    You might also consider localizing your error trap.

    (defun c:LINTEL (/ *error*)
    (defun *error*(msg)
    ....
    )
    (defun cleanup()
    (*error* nil)
    )
    ....
    (cleanup)
    (princ)
    )




    the stored osmode at the end of the routine cover that?
     
    Mark Propst, Jan 3, 2004
    #7
  8. akdrafter

    akdrafter Guest

    Gentlemen,

    All good information and all taken into consideration. Thanks for your help.

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Jan 3, 2004
    #8
  9. akdrafter

    Mike Weaver Guest

    The first question. Where are you located? I work for Charles Bettisworth
    & Co. I didn't think there were many folks from Alaska on these newsgroups.

    Okay. Now for business:

    First, I localized your error handler so it wouldn't interfere with mine. I
    typically do this to customize my error handlers to the routine.

    Second, I changed the order of your layer command calls. Make the layer
    first, then thaw it and turn it on. This avoids the error of trying to thaw
    a layer that doesn't exist.

    Third, the call to setvar "clayer" "S-HWall" is unnecessary since the
    preceding layer make leaves that as the current layer.

    Fourth, in the setq for P3 and P4, I added three lines of code to extend the
    lintel beyond the edge of the opening.

    Your request for dealing with picks that don't get an endpoint is a bit
    tougher, since getpoint will return a point even if the int osnap wasn't
    involved. If your operator were required to select the wall lines at either
    side of the opening, say near P1A and P2B then these could be used to derive
    the other points. The second function here (lintel3) will do this.

    HTH,

    Mike Weaver


    (defun c:LINTEL (/ *ERROR* )
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (prompt "\nResetting System Variables... ")
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    (setq CME(getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (setq OSM(getvar "OSMODE"))
    (setvar "OSMODE" 1)
    (setq SNM(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (setq CLA(getvar "CLAYER"))
    (command "-layer" "make" "S-LINTEL" "thaw" "S-LINTEL" "on" "S-LINTEL"
    "color" "7" "S-LINTEL" "lt" "center2" "S-LINTEL" "")
    (command "-layer" "make" "S-HWALL" "thaw" "S-HWALL" "on" "S-HWALL" "color"
    "1" "S-HWALL" "lt" "hidden" "S-HWALL" "")
    ;;;
    ;;;(setvar "CLAYER" "S-HWALL") This is unnecessary since the layer
    command above sets the layer
    (setq P1A(getpoint "\nSelect First Wall Opening 1st Point: "))
    (setq P1B(getpoint P1A "\nSelect First Wall Opening 2nd Point: "))
    (command "._line" P1A P1B "")

    (setq P2A(getpoint "\nSelect Second Wall Opening 1st Point: "))
    (setq P2B(getpoint P2A "\nSelect Second Wall Opening 2nd Point: "))
    (command "._line" P2A P2B "")

    (setq
    P3 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P1A P1B)
    P4 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P2A P2B)
    ;;Added the following 3 lines of code to extend the lintel 4" beyond the
    opening on each side
    a1 (angle p3 p4)
    P3 (polar p3 a1 -4)
    p4 (polar p4 a1 4)
    )
    ;;;
    (setvar "CLAYER" "S-LINTEL")
    (setvar "osmode" 0) ;Added this line
    (command "._line" P3 P4 "")

    ;;;
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (princ)
    ) ;end c:lintel

    (defun c:LINTEL3 (/ *ERROR* LintelPoints)
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (prompt "\nResetting System Variables... ")
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    ;;;;;;;;;;;;;;; Begin subroutine to get lintel points from selected lines
    ;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun LintelPoints( / ent1 ent2 elist1 elist2 l1p1 l1p2 l2p1 l2p2 pickpt1
    pickpt2 p1a p1b p2a p2b a1 a2)
    (cond
    ((null (setq ent1 (entsel "\nSelect Wall at first side of opening:
    ")))
    ;nothing selected
    nil
    )
    ((not (= "LINE" (cdr (assoc 0 (setq elist1 (entget (car ent1)))))))
    (princ "\nNot a line ")
    nil
    )
    ((null (setq ent2 (entsel "\nSelect wall at diagonal side of opening:
    ")))
    ;nothing selected
    nil
    )
    ((not (= "LINE" (cdr (assoc 0 (setq elist2 (entget (car ent2)))))))
    (princ "\nNot a line ")
    nil
    )
    (T
    (Setq
    l1p1 (cdr (assoc 10 elist1))
    l1p2 (cdr (assoc 11 elist1))
    l2p1 (cdr (assoc 10 elist2))
    l2p2 (cdr (assoc 11 elist2))
    pickpt1 (cadr ent1)
    pickpt2 (cadr ent2)
    p1a (if (> (distance pickpt1 l1p1) (distance pickpt1 l1p2))
    l1p2
    l1p1
    )
    p2b (if (> (distance pickpt2 l2p1)(distance pickpt2 l2p2))
    l2p2
    l2p1
    )
    a1 (angle l1p1 l1p2)
    a2 (+ a1 (/ pi 2))
    p1b (inters l2p1 l2p2 p1a (polar p1a a2 1) nil)
    p2a (inters l1p1 l1p2 p2b (polar p2b a2 1) nil)
    )
    (list p1a p1b p2a p2b)
    )
    ) ;end cond
    ) ;end lintelpoints
    ;;;;;;;;;;;;;;; End subroutine to get lintel points from selected lines
    ;;;;;;;;;;;;;;;;;;;;;;;;;



    (if (setq ptlist (lintelpoints))
    (progn
    (setq CME(getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (setq OSM(getvar "OSMODE"))
    (setvar "OSMODE" 1)
    (setq SNM(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (setq CLA(getvar "CLAYER"))
    (command "-layer" "make" "S-LINTEL" "thaw" "S-LINTEL" "on" "S-LINTEL"
    "color" "7" "S-LINTEL" "lt" "center2" "S-LINTEL" "")
    (command "-layer" "make" "S-HWALL" "thaw" "S-HWALL" "on" "S-HWALL"
    "color" "1" "S-HWALL" "lt" "hidden" "S-HWALL" "")
    (setq
    p1a (nth 0 ptlist)
    p1b (nth 1 ptlist)
    p2a (nth 2 ptlist)
    p2b (nth 3 ptlist)
    P3 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P1A P1B)
    P4 (MapCar '(LamBDA (x1 x2) (/ (+ x1 x2) 2)) P2A P2B)
    ;;Added the following 3 lines of code to extend the lintel 4" beyond the
    opening on each side
    a1 (angle p3 p4)
    P3 (polar p3 a1 -4)
    p4 (polar p4 a1 4)
    )
    (command "._line" "_non" P1A "_non" P1B "")
    (command "._line" "_non" P2A "_non" P2B "")
    ;;;
    (setvar "CLAYER" "S-LINTEL")
    (setvar "osmode" 0) ;Added this line
    (command "._line" "_non" P3 "_non" P4 "")

    ;;;
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    ) ;end progn
    ) ;end if
    (princ)
    )
     
    Mike Weaver, Jan 3, 2004
    #9
  10. akdrafter

    CAB2k Guest

    There are many ways to approach a routine, here is mine.

    Set snaps to END
    Pick the lintel by one side and the width.
    Set snaps to None
    Draw the line with extensions
    Offset the line
    Exit via the error routine.

    Did not address the error of not picking the end points
    because a simple Escape will abort the routine and
    a simple Undo will remove the lintels because I added
    Undo begin/end and the snaps are set END.

    Just the way i would do it.

    CAB



    (defun c:LINTEL (/ *ERROR*)
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    (defun *error* (msg) ; error function
    (if
    (not
    (member
    msg
    '("console break" "Function cancelled" "quit / exit abort" "")
    )
    )
    (princ (strcat "\nError: " msg))
    ) ; endif

    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (setvar "CLAYER" CLA)
    (command "undo" "end")
    (prompt "\nResetting System Variables... ")
    (princ)
    ) ;end error function
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    ;; Routine Starts Here
    (setq CME (getvar "CMDECHO")
    OSM (getvar "OSMODE")
    SNM (getvar "SNAPMODE")
    CLA (getvar "CLAYER"))
    (setvar "CMDECHO" 0)
    (setvar "SNAPMODE" 0)
    (command "-layer" "make" "S-LINTEL" "thaw" "S-LINTEL"
    "on" "S-LINTEL" "color" "7" "S-LINTEL"
    "lt" "center2" "S-LINTEL" ""
    )
    (command "-layer" "make" "S-HWALL" "thaw" "S-HWALL"
    "on" "S-HWALL" "color" "1" "S-HWALL"
    "lt" "hidden" "S-HWALL" ""
    )

    (command "undo" "begin")
    (setvar "OSMODE" 1) ; Endpoint
    ;; This is a three point selection method, no error checking
    (setq P1A (getpoint "\nSelect First Wall Opening 1st Point: "))
    (setq P1B (getpoint P1A "\nSelect First Wall Opening 2nd Point: "))
    (setq P2B (getpoint P1B "\nSelect Wall Width Point: "))
    (setvar "OSMODE" 0) ; None
    (command "._line" (polar P1A (angle p1b p1a) 4) (polar P1B (angle p1a p1b) 4) "")
    (setq ln (entlast))
    (command "._offset" (distance p1b p2b) ln p2b "")

    (*error* "") ; use the error routine to reset variables

    ) ;end c:lintel
    (prompt "\nLintel Routine loaded, Enter LINTEL to run.")
    (princ)
     
    CAB2k, Jan 3, 2004
    #10
  11. akdrafter

    akdrafter Guest

    Mike,

    I work for Schneider & Associates. New Structural outfit here in Los Anchorage. :) Get it, Los Anchorage. hahahaha In my many years of drawing lines and circles I have always strived to use this multi thousand dollar program like a multi thousand dollar program and not a 2 cent pencil. Now, I am no super programmer by any means and not even a good programmer, but since visiting these newsgroups I have begun to really understand what it is I try to write and what others are helping me write. I have learned a lot to say the least. Also, ticked off at least one person with my code etiquite. Was totally my bad and I have changed my ways. :)

    Anyway, I have taken your code and tried it out. Works just like I had imagined. However, I am not sure how the lintel3 routine you added works.

    Thanks for your help. We are gaining light now and the fish are just growing bigger and bigger. :) We are on the uphill swing now. Yeah baby.

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Jan 5, 2004
    #11
  12. akdrafter

    Mike Weaver Guest

    AKDrafter,
    I tried Anchorage for a while, decided I liked Fairbanks better, though most
    people in Anchorage just don't undertstand why someone would have that
    preference. We like it that way.

    The lintel3 routine may be a solution in search of a problem:) It is
    intended to let the operator select two of the wall lines instead of
    selecting their endpoints. This enables it to deal with the missed endpoint
    problem. However, I realized as I was finishing it that the plan you're
    working off is probably an xref making the lines nested - in which case
    lintel3 won't work.

    6 hours 57 minutes of visible daylight, a gain of 3 minutes over yesterday.
    We are on the downhill leg.

    Mike Weaver

    Anchorage. :) Get it, Los Anchorage. hahahaha In my many years of drawing
    lines and circles I have always strived to use this multi thousand dollar
    program like a multi thousand dollar program and not a 2 cent pencil. Now, I
    am no super programmer by any means and not even a good programmer, but
    since visiting these newsgroups I have begun to really understand what it is
    I try to write and what others are helping me write. I have learned a lot to
    say the least. Also, ticked off at least one person with my code etiquite.
    Was totally my bad and I have changed my ways. :)
    imagined. However, I am not sure how the lintel3 routine you added works.
    growing bigger and bigger. :) We are on the uphill swing now. Yeah baby.
     
    Mike Weaver, Jan 7, 2004
    #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.