Runs once fine "multiple"...."loop".......no luck.....help

Discussion in 'AutoCAD' started by glennpoole, Feb 13, 2004.

  1. glennpoole

    glennpoole Guest

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; mxLINE - subfunction
    (defun mxline (snap1 snap2 / pt1 pt2)

    (setvar "cmdecho" 0)
    (setq osnapmode (getvar "OSMODE"))
    ; mark the start of an UNDO group
    (if (> (atoi (getvar "acadver")) 12)
    (command "_.undo" "_be") ; acad 13
    (command "_.undo" "_g") ; acad 12
    );

    (command "_.osnap" snap1)
    (prompt "\nEnter ")
    (setq pt1 (getpoint snap1))
    (chkint pt1 snap1)
    (prompt " Enter ")
    (command "_.osnap" snap2)
    (setq pt2 (getpoint pt1 snap2))
    (chkint pt2 snap2)
    (command "_.osnap" "none")
    (command "_.line" pt1 pt2 "")

    ; mark the end of our UNDO group
    (setvar "OSMODE" osnapmode)
    (command "_.undo" "_e")

    (princ)
    );end mxline




    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun C:MLEE() (mxline "ENDP" "ENDP" ))
    (defun C:MLNP() (mxline "NODE" "PERP" ))
    (defun C:MLEP() (mxline "ENDP" "PERP" ))
    (defun C:MLEN() (mxline "ENDP" "NODE" ))
    (defun C:MLEI() (mxline "ENDP" "INT" ))
    (defun C:MLEM() (mxline "ENDP" "MIDP" ))
    (defun C:MLEC() (mxline "ENDP" "CENTER" ))
    (defun C:MLES() (mxline "ENDP" "INSER))

    ect, ect, ect...................

    Thanks for the help

    Glenn Poole
     
    glennpoole, Feb 13, 2004
    #1
  2. Glen,

    Without seeing the (chkint) function, it seems your function is
    over-engineered.

    (defun mxLine (snap1 snap2 / pt1 pt2)
    (setq pt1 (getpoint "\nEnter ")
    pt2 (getpoint " Enter "))
    (setvar "CmdEcho" 0)
    (vl-cmdf "._Line" snap1 pt1 snap2 pt2 "")
    (setvar "CmdEcho" 1)
    (princ))


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; mxLINE - subfunction
    (defun mxline (snap1 snap2 / pt1 pt2)

    (setvar "cmdecho" 0)
    (setq osnapmode (getvar "OSMODE"))
    ; mark the start of an UNDO group
    (if (> (atoi (getvar "acadver")) 12)
    (command "_.undo" "_be") ; acad 13
    (command "_.undo" "_g") ; acad 12
    );

    (command "_.osnap" snap1)
    (prompt "\nEnter ")
    (setq pt1 (getpoint snap1))
    (chkint pt1 snap1)
    (prompt " Enter ")
    (command "_.osnap" snap2)
    (setq pt2 (getpoint pt1 snap2))
    (chkint pt2 snap2)
    (command "_.osnap" "none")
    (command "_.line" pt1 pt2 "")

    ; mark the end of our UNDO group
    (setvar "OSMODE" osnapmode)
    (command "_.undo" "_e")

    (princ)
    );end mxline




    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun C:MLEE() (mxline "ENDP" "ENDP" ))
    (defun C:MLNP() (mxline "NODE" "PERP" ))
    (defun C:MLEP() (mxline "ENDP" "PERP" ))
    (defun C:MLEN() (mxline "ENDP" "NODE" ))
    (defun C:MLEI() (mxline "ENDP" "INT" ))
    (defun C:MLEM() (mxline "ENDP" "MIDP" ))
    (defun C:MLEC() (mxline "ENDP" "CENTER" ))
    (defun C:MLES() (mxline "ENDP" "INSER))

    ect, ect, ect...................

    Thanks for the help

    Glenn Poole
     
    R. Robert Bell, Feb 13, 2004
    #2
  3. And even better... this version takes advantage of the way you call the
    function, and provides dynamic feedback to your users!

    (defun mxLine (snap1 snap2 / *Error* myDoc oldOSMode pt1 pt2)
    ;; Error handler/normal function exit
    (defun *Error* (Msg)
    (cond ((or (not Msg)
    (member (strcase Msg T) '("function cancelled" "quit / exit
    abort"))))
    ((princ (strcat "\nError: " Msg))))
    (setvar "CmdEcho" 1)
    (cond (oldOSMode (setvar "OSMode" oldOSMode)))
    (cond (myDoc (vla-EndUndoMark myDoc)))
    (princ))
    ;; Main code
    (vl-load-com)
    (setq myDoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
    (vla-StartUndoMark myDoc)
    (setq oldOSMode (getvar "OSMode"))
    (setvar "CmdEcho" 0)
    (command "._-OSnap" snap1)
    (setq pt1 (getpoint "\nEnter "))
    (command "._-OSnap" snap2)
    (setq pt2 (getpoint " Enter "))
    (vl-cmdf "._Line" "_non" pt1 "_non" pt2 "")
    (*Error* nil))


    --
    R. Robert Bell, MCSE
    www.AcadX.com



    ....

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun C:MLEE() (mxline "ENDP" "ENDP" ))
    (defun C:MLNP() (mxline "NODE" "PERP" ))
    (defun C:MLEP() (mxline "ENDP" "PERP" ))
    (defun C:MLEN() (mxline "ENDP" "NODE" ))
    (defun C:MLEI() (mxline "ENDP" "INT" ))
    (defun C:MLEM() (mxline "ENDP" "MIDP" ))
    (defun C:MLEC() (mxline "ENDP" "CENTER" ))
    (defun C:MLES() (mxline "ENDP" "INSER))

    ect, ect, ect...................

    Thanks for the help

    Glenn Poole
     
    R. Robert Bell, Feb 13, 2004
    #3
  4. glennpoole

    TCEBob Guest

    Guys, if the purpose is to have a machine for drawing lines with various
    osnaps, I gotta say that's an awful lot of programming. Here's mine:

    (defun lfromto (from to /)
    (while t
    (prompt "\nPick entities: ")
    (command "line" from pause to pause "")
    )
    (princ)
    )
    ;======================================================
    (defun c:LEE () (lfromto "end" "end"))
    (defun c:LEP () (lfromto "end" "per"))
    (defun c:LEC () (lfromto "end" "cen"))
    (defun c:LEI () (lfromto "end" "int"))

    .. . . etc.

    I hold that you don't have to bulletproof a function like this; if it
    blows it blows. How bad can it be? Of course, I wrote it for myself and
    I don't mind escaping out, but, heck, no local variables.

    rs
     
    TCEBob, Feb 14, 2004
    #4
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.