+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 23
  1. #1
    Senior Member
    Using
    AutoCAD 2000
    Join Date
    Nov 2008
    Posts
    182

    Default Shortcut command for circle

    Registered forum members do not see this ad.

    This is my code:
    ;; Shortcut command for circle
    (defun c:ctd (/ a)
    (setq a (/ (getreal "\nd:") 2))
    (command "circle" "_ttr" pause pause a)
    (princ)
    )
    At present this is what appears on my command line,
    Command: ctd
    d:100
    circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr
    Specify point on object for first tangent of circle:
    Specify point on object for second tangent of circle:
    Specify radius of circle: 50.00000000000000
    Command:
    Command:

    And this if I press ESCAPE at prompt,
    Command:
    CTD
    d:
    ; error: bad argument type: numberp: nil


    What I want to achieve is something like this,
    Command: ctd
    d<0>:100 <------NOTICE THIS
    circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr
    Specify point on object for first tangent of circle:
    Specify point on object for second tangent of circle:
    Specify radius of circle: 50.00000000000000
    Command:
    Command:

    And when I press ENTER,
    Command: ctd
    d<100>: ( press ENTER key at this point)
    circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr
    Specify point on object for first tangent of circle:
    Specify point on object for second tangent of circle:
    Specify radius of circle <50.0000>: 50.00000000000000
    Command:
    Command:

    How will I do that?
    We learn more by looking for the answer to a question and not finding it than we do from learning the answer itself. ~Lloyd Alexander

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

    Perhaps this?

    Code:
    ;; Shortcut command for circle
    (defun c:ctd (/ a)
        (or (getenv "DIAM") (setenv "DIAM" "0"))
        (if    (setq a (/ (getreal (strcat "\nd<" (getenv "DIAM") ">: ")) 2))
        (setenv "DIAM" (rtos (* 2 a)))
        ) ;_  end if
        (command "_circle" "_ttr" pause pause (getenv "DIAM"))
        (princ)
    ) ;_  end defun
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Senior Member
    Using
    AutoCAD 2000
    Join Date
    Nov 2008
    Posts
    182

    Default

    Thanks Lee Mac! That was pretty quick.
    How can I fix this error when I press escape?

    Command: ctd
    d<100>: *Cancel*
    ; error: Function cancelled
    We learn more by looking for the answer to a question and not finding it than we do from learning the answer itself. ~Lloyd Alexander

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

    I thought maybe this, but it doesn't really get around it.

    Code:
    ;; Shortcut command for circle
    (defun c:ctd (/ a)
        (defun *error* (msg)
        (if (= msg "")
            (princ "\nFunction Complete.")
            (princ (strcat "\n" (strcase msg)))
        ) ;_  end if
        (princ)
        ) ;_  end defun
        (or (getenv "DIAM") (setenv "DIAM" "0"))
        (if    (setq a (/ (getreal (strcat "\nd<" (getenv "DIAM") ">: ")) 2))
        (setenv "DIAM" (rtos (* 2 a)))
        ) ;_  end if
        (command "_circle" "_ttr" pause pause (getenv "DIAM"))
        (princ)
    ) ;_  end defun
    Plus, if I hit enter when the default is there it says, bad argument, numerp nil.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

    Sorry, haven't got much time today
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Senior Member
    Using
    AutoCAD 2000
    Join Date
    Nov 2008
    Posts
    182

    Default

    Ok, thanks, I'll wait for others...
    We learn more by looking for the answer to a question and not finding it than we do from learning the answer itself. ~Lloyd Alexander

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

    Looked over it again - stupid mistake really.

    Can't quite sort your error problem though:

    Code:
    ;; Shortcut command for circle
    (defun c:ctd (/ a)
        (defun *error* (msg)
        (if (= msg "")
            (princ "\nFunction Complete.")
            (princ (strcat "\n" (strcase msg)))
        ) ;_  end if
        (princ)
        ) ;_  end defun
        (or (getenv "DIAM") (setenv "DIAM" "0"))
        (if    (setq a (getreal (strcat "\nd<" (getenv "DIAM") ">: ")))
        (setenv "DIAM" (rtos a))
        ) ;_  end if
        (command "_circle" "_ttr" pause pause (rtos (/ (atof (getenv "DIAM")) 2)))
        (princ)
    ) ;_  end defun
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,082

    Default

    totzky,

    You need a lot of trapping on something like this to insure the command call is complete.

    I take the approach of having all of the values before calling CIRCLE:

    Code:
    (defun c:ctd (/ olderr oldsnp lent dia pt1 pt2)
    
      (setq olderr *error*
           *error* (lambda (e)
                     (while (> (getvar "CMDACTIVE") 0)
                            (command))
                     (and (/= e "quit / exit abort")
                          (princ (strcat "\nError: *** " e " *** "))))
           oldsnp (getvar "OSMODE"))
    
      (setvar "OSMODE" 512)
      (setvar "CMDECHO" 0)
    
      (setq lent (entlast))
    
      (initget 7)
      (setq dia (getdist "\nDiameter:   "))
    
      (while (not pt1)
             (setq pt1 (osnap (getpoint "\nSelect 1st TANGENT Point:  ") "_TAN")))
    
      (while (not pt2)
             (setq pt2 (osnap (getpoint "\nSelect 2nd TANGENT Point:  ") "_TAN")))
    
      (command "_.CIRCLE" "_TTR" pt1 pt2 (/ dia 2.))
    
      (and (eq lent (entlast))
           (princ "\nCommand Failed..."))
    
      (setvar "OSMODE" oldsnp)
    
      (setq *error* olderr)
    
      (prin1))
    Good Luck -David
    R12 (Dos) - A2K

  9. #9
    Senior Member
    Using
    AutoCAD 2000
    Join Date
    Nov 2008
    Posts
    182

    Default

    Test your code David and this is what happens,

    Command: ctd
    Diameter: 100
    Select 1st TANGENT Point:
    Select 1st TANGENT Point:
    Select 1st TANGENT Point:
    Select 1st TANGENT Point: *Cancel* (At this point I pressed ESCAPE)
    Error: *** Function cancelled ***
    We learn more by looking for the answer to a question and not finding it than we do from learning the answer itself. ~Lloyd Alexander

  10. #10
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,082

    Default

    Registered forum members do not see this ad.

    Kinda lost me there ?

    Did you pick a valid tangent point?

    -David
    R12 (Dos) - A2K

Similar Threads

  1. Creating a shortcut for a command and a layer
    By Siberian in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 27th Nov 2007, 08:43 pm
  2. Shortcut Key
    By johnengineer in forum AutoCAD General
    Replies: 7
    Last Post: 10th Sep 2007, 04:32 pm
  3. Shortcut Command
    By gofindsam in forum AutoCAD Drawing Management & Output
    Replies: 11
    Last Post: 30th May 2007, 09:15 pm
  4. Tutorial: Create a command alias (keyboard shortcut)
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 18th Mar 2007, 12:11 am
  5. Line from inner circle to outer circle
    By jocaan in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 11th Mar 2004, 09:28 pm

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