+ Reply to Thread
Results 1 to 7 of 7

Thread: Caliper fun

  1. #1
    Super Moderator fuccaro's Avatar
    Discipline
    Mechanical
    fuccaro's Discipline Details
    Occupation
    Mechanical eng.
    Discipline
    Mechanical
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,577

    Default Caliper fun

    Registered forum members do not see this ad.

    Hello people!
    Today I realized that AutoCAD is just waiting on my hard disc, so I started it and I wrote a short Lisp program.
    If someone wants to play: load the lisp and start it by typing TESTME in the command line. Probable you will have to double click with the wheel to get the zoom to the right place. You should see a caliper open at a random dimension. All you have to do is to read the caliper and enter the value. The command line should show at least 3 lines to see the result. Want to play again? Press enter.
    While AutoCAD waits for your input, you may use the mouse to zoom/pan. Or if you want to cheat, you can measure the opening of the caliper and enter the measured value.
    Have fun!
    Code:
    (defun c:TestMe()  
      (if (not (tblsearch "BLOCK" "SublerA")) (MakeBlockA))
      (if (not (tblsearch "BLOCK" "SublerB")) (MakeBlockB))
      (if (not (ssget "X" (list '(0 . "INSERT") '(2 . "SublerA")))) (entmake (list '(0 . "INSERT") '(2 . "SublerA") '(10 0 0 0))))
      (if (not (ssget "X" (list '(0 . "INSERT") '(2 . "SublerB")))) (entmake (list '(0 . "INSERT") '(2 . "SublerB") '(10 0 0 0))))
      (setq measured (/ (rem (getvar "millisecs") 1500) 10.0))
      (setq entl (entget (entlast)))
      (setq entl (subst (list 10 measured 0 0) (assoc 10 entl) entl))
      (entmod entl)
      (setq entered (getreal "Enter measured value "))
      (princ (if (= measured entered) "Ok " (strcat " Not Ok! The answer is " (rtos measured) )))
      (princ)
      )
    (defun MakeBlockA()
      (entmake (list '(0 . "BLOCK") '(2 . "SublerA") '(10 0.0 0.0 0.0)'(70 . 0)))
      (setq i 0)
      (repeat 151
        (cond
          ((= (* 5 (/ i 5)) i) (progn
                     (setq m 0.5)
                     (entmake (list '(0 . "text") (list 10 i 2.6 0) (cons 1 (itoa i)) '(40 . 1.4) (cons 50 0.7)))
                     )
           )
          )
        (entmake (list '(0 . "LINE") (list 10 i 0 0) (list 11 i (+ 1.5 m) 0)))
        (setq i (1+ i) m 0)
        )
      (setq points (list '(-3 0 0) '(170 0 0) '(170 8 0) '(-10 8 0) '(-10 -15 0) '(-5 -25 0) '(-5 -30 0) '(-3 -30 0)))
      (setq p1 (list -3 -30 0))
      (foreach p points
        (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p)))
        (setq p1 p)
        )
      (entmake (list '(0 . "ENDBLK")))
    )
    
    (defun MakeBlockB()
      (entmake (list '(0 . "BLOCK") (cons 2 "SublerB") (list 10 0.0 0.0 0.0)'(70 . 0)))
      (setq i 0)
      (repeat 11    
        (cond ((= i (* 5 (/ i 5))) (progn (setq n -0.5)
                     (entmake (list '(0 . "text") (list 10 (- (* 0.9 i) 0.5) -5 0) (cons 1 (itoa i)) '(40 . 1.4) (cons 50 0)(cons 62 1)))
                     )))
        (entmake (list '(0 . "LINE") (list 10 (* 0.9 i) 0 0) (list 11 (* 0.9 i) (+ -2 n) 0)(cons 62 1)))
        (setq i (1+ i) n 0)
        )
      (setq p1 '(-3 -30 0))
      (setq points (list '(-3 0 0) '(15 0 0) '(15 -7 0) '(4 -7 0) '(4 -15 0) '(-1 -25 0) '(-1 -30 0) '(-3 -30 0)))
       (foreach p points
         (entmake (list '(0 . "LINE") (cons 10 p1) (cons 11 p)))
        (setq p1 p)
        )
      (entmake (list '(0 . "ENDBLK")))
      )
    It's nice to be nice, but sometimes is nicer to be evil!
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  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
    19,322

    Default

    Great fun! Superb program fuccaro, and nice to see you posting again! - I hope all is well.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  3. #3
    Super Moderator f700es's Avatar
    Computer Details
    f700es's Computer Details
    Operating System:
    Windows 7 Pro (W)/Windows 7 Home Premium (H)
    Computer:
    Dell Optiplex 9020 (W)/ Dell Inspiron 570 (H)
    Motherboard:
    Intel (W)/AMD (H)
    CPU:
    Intel Core i7-4770 quad (W)/AMD Athlon 2 X4 (H)
    RAM:
    16 GB DDR3 (W)/ 6GB DDR3 (H)
    Graphics:
    nVidia Geforce GTX 645 (W)/nVidia GF GT430 (H)
    Primary Storage:
    256 gb SSD 0/ 1TB 1 (W)/1 TB (H)
    Secondary Storage:
    Seagate FreeAgent Go 320gb
    Monitor:
    Samsung P2770HD 28" LCD and Samsung B2430 (W)/Acer 28" LCD (H)
    Discipline
    Facilities Mgmt
    f700es's Discipline Details
    Occupation
    Space Database Admin
    Discipline
    Facilities Mgmt
    Details
    Archibus Management, Space planning, Design
    Using
    AutoCAD 2017
    Join Date
    Sep 2002
    Location
    Winston-Salem, NC - USA
    Posts
    5,531

    Default

    Welcome back
    Please do not PM me with CAD questions. Post your question on the forum. Our users are the best out there and you'll get the best possible answer to your question.

    - http://f700es.deviantart.com/gallery/ -


  4. #4
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,720

    Default

    Welcome back! Nice program!
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  5. #5
    Super Moderator fuccaro's Avatar
    Discipline
    Mechanical
    fuccaro's Discipline Details
    Occupation
    Mechanical eng.
    Discipline
    Mechanical
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,577

    Default

    Many thanks for your welcome messages, I hope you are well too!
    It's nice to be nice, but sometimes is nicer to be evil!
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,060

    Default

    Very cool program!
    BTW note that the progn functions are redundant, since cond evaluates all expressions after the test one.

    I think it would be funny to implement grread to use that caliper for "measuring", but thats another type of program.

  7. #7
    Super Moderator fuccaro's Avatar
    Discipline
    Mechanical
    fuccaro's Discipline Details
    Occupation
    Mechanical eng.
    Discipline
    Mechanical
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,577

    Default

    Registered forum members do not see this ad.

    Thanks for that PROGN thing -I will try to remember that for the future.
    It's nice to be nice, but sometimes is nicer to be evil!
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

Similar Threads

  1. Replies: 4
    Last Post: 13th Feb 2007, 03:45 pm

Tags for this Thread

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