Author Topic: Lisp help needed. Check user input using 'if' statement  (Read 3379 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Lisp help needed. Check user input using 'if' statement
« on: February 15, 2005, 05:03:16 PM »
I'm attempting to write a lisp to set up my drawing sheets and add some title information.

I have this pseudo code

Code: [Select]
(defun c:setup ()
(setq sht (getstring "\nEnter sheet size: "))

if A0 sheet then insert A0 title block
or if A1 sheet insert A1 title block
or if A2 sheet insert A2 title block
if any other response except A0, A1, A2 or esc, print error message "Not a valid sheet size" and return to "Enter sheet size"


But I don't know how to write the selection code.

Anyone have any ideas?

*edit MST*
added to the "Subject" a bit.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7529
Lisp help needed. Check user input using 'if' statement
« Reply #1 on: February 15, 2005, 05:18:55 PM »
I use this for my tblocks:

Code: [Select]
(defun C:titleb (/ cmd att clay pt)
(if (tblsearch "layer" "m-sheet")
(command "-layer" "thaw" "m-sheet" "on" "m-sheet" "")
(princ "\n Layer 'm-sheet' Created")
)

(setq cmd  (getvar 'cmdecho)
att  (getvar 'attdia)
clay (getvar 'clayer)
)
(setvar 'tilemode 0)
(setvar 'cmdecho 0)
(setvar 'attdia 1)
 
(initget 0 "8 11 22 24 30 34")
  (setq P (cond ((getkword
       "\nEnter Titleblock Size: (8).5x11 (11)x17 (22)x34 (24)x36 (30)x42 (34)x44: <<Hit Enter for 22x34>>: "))
   ("22")
  )
)
  (if (= P "8")
    (progn

  (setq pt (getpoint "\nSpecify insertion point or hit enter for [0,0,0]: "))
  (if (null pt) (setq pt '(0 0 0)))
  (command ".-layer"
  "m"
  "m-sheet"
  ""
  ".-INSERT"
  "Aei8.5x11=Aei8.5x11.dwg"
  pt
  "1"
  "1"
  "0"
  )
  (command ".zoom" "extents")
  (setvar "cmdecho" cmd)
  (setvar "attdia" att)
  (setvar "clayer" clay)
  (princ)
)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Lisp help needed. Check user input using 'if' statement
« Reply #2 on: February 15, 2005, 05:26:19 PM »
Since you have a list of allowable input lets use something along these lines.
Code: [Select]

 (defun c:setup ()
   (setq sht (getstring "\nEnter sheet size: "))

   (if (member sht (list "A0" "A1" "A2"))
      (then proceed with "insert" command)
      ; else
      ; prompt the user
      (alert "Not a valid sheet size" and return to "Enter sheet size")
      ); if
    ); defun
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp help needed. Check user input using 'if' statement
« Reply #3 on: February 15, 2005, 05:34:30 PM »
How about a key word?
Code: [Select]
 (initget 1 "a0 a1 a2")
  (setq choice (getkword "\nEnter a choice [0=A0 1=A1 2=A2 ]"))

 
  Look up initget in the Help section.
 
You could do it this way.
Code: [Select]
 (initget 1 "A0,0 A1,1 A2,2")
  (setq choice (getkword "\nEnter a choice [0=A0 1=A1 2=A2 ]"))

 
You should understand how that works before you move on to the next step.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp help needed. Check user input using 'if' statement
« Reply #4 on: February 15, 2005, 05:36:01 PM »
Boy do I type slow or what! :shock:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hudster

  • Gator
  • Posts: 2848
Lisp help needed. Check user input using 'if' statement
« Reply #5 on: February 16, 2005, 04:30:43 AM »
Ok, this is what I have now

Code: [Select]
;;
;;TITLE SHEET INSERTION ROUTINE
;;BY ANDY HUDSON
;;
;;ADAPTED FORM AN ORIGINAL LISP BY RONJOP
;;UPLOADED AT http://theswamp.org/phpBB2/viewtopic.php?p=48413#48413
;;
(defun C:rybka (/ cmd att clay p)
  (if (tblsearch "layer" "TITLE")
    (command "-layer" "thaw" "TITLE" "on" "TSHEET" ""))
  ;;
  (setq cmd  (getvar 'cmdecho)
att  (getvar 'attdia)
clay (getvar 'clayer))
  ;;

  (setvar 'tilemode 0)
  (setvar 'cmdecho 0)
  (setvar 'attdia 1)
  (initget 0 "1 2 3 4 5")
  (setq P
(cond
  ((getkword
     "\nEnter Titleblock Size: (1)-A0 (2)-A1 (3)-A1B (4)-A3 (5)-A4 <<Hit Enter for A1>>: "
   )
  )
  ("2")
)
  )
  ;;A0 SHEET
  (if (= P "1")
  (progn (command ".-layer" "m" "TITLE" "" ".-INSERT" "A0_SHEET.dwg" "0,0" "" "" "")))
  ;;A1 SHEET
  (if (= P "2")
  (progn(command ".-layer" "m" "TITLE" "" ".-INSERT" "A1_SHEET.dwg" "0,0" "" "" "")))
  ;;A1B_SHEET
  (if (= P "3")
    (progn (command ".-layer" "m" "TITLE" "" ".-INSERT" "A1-B_SHEET.dwg" "0,0" "" "" "")))
  ;;A3 SHEET
  (if (= P "4")
    (progn (command ".-layer" "m" "TITLE" "" ".-INSERT" "A3_SHEET.dwg" "0,0" "" "" "")))
  ;;;A4 SHEET
  (if (= P "5")
    (progn (command ".-layer" "m" "TITLE" "" ".-INSERT" "A4_SHEET.dwg" "0,0" ""  "" "")))
  ;;;ZOOM EXTENTS
  (command ".zoom" "extents")
  ;;;RESET USER VARIABLES
  (setvar "cmdecho" cmd)
(setvar "attdia" att)
(setvar "clayer" clay)
  ;;;CLEAN EXIT
  (princ)
  )


next question
to alter the attribute information for each revision, I need to find out the block name of which ever sheet is installed and pass this information to the lisp routine to allow me to change the attributes.

Ideas?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp help needed. Check user input using 'if' statement
« Reply #6 on: February 16, 2005, 08:00:09 AM »
Here is another way to code it.
See this example

Code: [Select]
;;
;;TITLE SHEET INSERTION ROUTINE
;;BY ANDY HUDSON
;;
;;ADAPTED FORM AN ORIGINAL LISP BY RONJOP
;;UPLOADED AT http://theswamp.org/phpBB2/viewtopic.php?p=48413#48413
;;
(defun c:rybka (/ cmd att clay sheet sheet# sheetnames)
  (if (tblsearch "layer" "TITLE")
    (command "-layer" "thaw" "TITLE" "on" "TSHEET" "")
  )
 
  (setq cmd  (getvar 'cmdecho)
        att  (getvar 'attdia)
        clay (getvar 'clayer)
  )

  (setvar 'tilemode 0)
  (setvar 'cmdecho 0)
  (setvar 'attdia 1)
  (setq SheetNames
         '(
           ("1" "A0_SHEET.dwg")
           ("2" "A1_SHEET.dwg")
           ("3" "A1-B_SHEET.dwg")
           ("4" "A3_SHEET.dwg")
           ("5" "A4_SHEET.dwg")
          )
  )

  (initget 0 "1 2 3 4 5")
  (setq sheet#
         (cond
           ((getkword
              "\nEnter Titleblock Size: (1)-A0 (2)-A1 (3)-A1B (4)-A3 (5)-A4 <<Hit Enter for A1>>: "
            )
           )
           ("2")
         )
  )

  (if (setq sheet (assoc sheet# SheetNames))
    (command ".-layer" "m" "TITLE" ""
             ".-INSERT" sheet "0,0" "" "" "")
  )


  (command ".zoom" "extents")
  ;;RESET USER VARIABLES
  (setvar "cmdecho" cmd)
  (setvar "attdia" att)
  (setvar "clayer" clay)
  ;;CLEAN EXIT
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.