Jump to content

Recommended Posts

Posted

I'm currently writing a lisp that uses (getstring) in order to pick from about 48 values. Quite a lot, I know. However, I've set up my lisp to take advantage of the dynamic input menus so you can point and click rather than type out a long string. The problem I'm having is, is it's only grabbing the first part of the string. Anything after the first space is ignored. If I manually type one of the options, the lisp continues like nothing's happened. Originally I was using getkword, but the same issue.

 

I've attached the code as it's written right now, and appreciate any help. I'm about to pull my hair out figuring this out.

 

Edit: Apologies for the formatting. I use notepad++ with a tab indenting of 2 and the ZenBurn theme if you'd like to view it as I've written it.

Command-CopyPlotConfigs.lsp

Posted

You can fill the optional argument for getstring with T and it will accept strings with spaces (getstring T "\nSay it: "). However, in your situation, I'd either use a DCL list box or getkword.

Posted
You can fill the optional argument for getstring with T and it will accept strings with spaces (getstring T "\nSay it: "). However, in your situation, I'd either use a DCL list box or getkword.

 

I did use getstring T, so I can manually type in the page setup and it works just fine. Actually clicking on it through DYN Input doesn't.

 

How would I use getkword in this instance? I still haven't quite figured out the nuances of it yet (I just started going back through all my code to use getkword, so it's relatively new to me). I tried doing A) Page Setup 1, B) Page Setup 2, etc. so the first would be type-in A, the second type-in B, etc. but that doesn't seem to work either. And I'm trying to avoid the DCL to appease the keyboard jockeys in the firm (like myself), and plan on creating a ribbon tab that utilizes the lisp for the point-and-click types.

Posted
(defun c:test (/)
 (initget 0 "Yes No")
 (getkword "\nDo you understand now? [Yes/No]: ")
)

Posted

I tried the following with initget and getkword:

 

(setq V:Plot01 "Page Setup 01")
(setq V:Plot02 "Page Setup 02")
(setq V:Plot03 "Page Setup 03")

(setq V:PlotList (strcat "[" V:Plot01 "/" V:Plot02 "/" V:Plot03 "]"))

(initget 0 V:PlotList)
(if (= nil V:Plot)
   (setq V:Plot (getkword (strcat "\nEnter page setup: " V:PlotList)))
   (setq V:Plot (getkword (strcat "\nEnter page setup: " VPlotList "<" V:Plot "> ")))
)

(if (= V:Plot V:Plot01)
   (progn
       // (command "._-PSetupIN" "D:/AutoCAD/Templates/Page Setups - 64bit.dwt" "*")
       // (command "-Plot" "No" "" V:Plot01 "" "No" "Yes" "No")
       (PurgeUnused)
       (princ (strcat "/n" V:Plot " page setup has been imported and set."))
       (princ)
   )
)

Posted

How so? I was under the impression that initget 0 only doesn't allow someone to just hit enter. Or is it that I have to do it like this?

 

(initget 1 "Page Setup 01 Page Setup 02 Page Setup 03")

 

How would I go about accounting for spaces in each option at that point then?

 

Edit: Crap, just saw this thread: http://www.cadtutor.net/forum/showthread.php?48047-initget

 

So, I guess using getstring probably was the best course since I have spaces in the options, which bring me back to my original issue.

Posted
How so? I was under the impression that initget 0 only doesn't allow someone to just hit enter. Or is it that I have to do it like this?

 

(initget 1 "Page Setup 01 Page Setup 02 Page Setup 03")

 

How would I go about accounting for spaces in each option at that point then?

Yeah, I just really looked at your 'list'. getkword just isn't going to work in this situation. However, what I meant was that you can't feed initget a string like (initget 0 "[Yes/No]"), it has to be (initget 0 "Yes No").

You are either going to have to take the horrible getstring route or use a List Box (my suggestion).

Posted

If you aren't wanting to do the list box, you could try this...

 

(defun c:TEst (/ lst int choice)
 ((lambda (i)
    (setq lst (mapcar (function (lambda (x) (cons (setq i (1+ i)) x)))
                      '("PDF - 11 x 17" "PDF - 11 x 17 - ByLayer" "PDF - 17 x 22"
                        "PDF - 17 x 22 - ByLayer" "PDF - 18 x 24" "PDF - 18 x 24 - ByLayer"
                        "PDF - 22 x 34" "PDF - 22 x 34 - ByLayer" "PDF - 24 x 36"
                        "PDF - 24 x 36 - ByLayer" "PDF - 30 x 42" "PDF - 30 x 42 - ByLayer"
                        "PDF - 34 x 44" "PDF - 34 x 44 - ByLayer" "PDF - 36 x 48"
                        "PDF - 36 x 48 - ByLayer" "Xerox 6204 - 17 x 22 - STF"
                        "Xerox 6204 - 17 x 22 - STF - ByLayer" "Xerox 6204 - 18 x 24 - STF"
                        "Xerox 6204 - 18 x 24 - STF - ByLayer" "Xerox 6204 - 22 x 34"
                        "Xerox 6204 - 22 x 34 - ByLayer" "Xerox 6204 - 22 x 34 - STF"
                        "Xerox 6204 - 22 x 34 - STF - ByLayer" "Xerox 6204 - 24 x 36"
                        "Xerox 6204 - 24 x 36 - ByLayer" "Xerox 6204 - 24 x 36 - STF"
                        "Xerox 6204 - 24 x 36 - STF - ByLayer" "Xerox 6204 - 30 x 42"
                        "Xerox 6204 - 30 x 42 - ByLayer" "Xerox 6204 - 30 x 42 to 18 x 24"
                        "Xerox 6204 - 30 x 42 to 24 x 36" "Xerox 6204 - 34 x 44"
                        "Xerox 6204 - 34 x 44 - ByLayer" "Xerox 6204 - 36 x 48"
                        "Xerox 6204 - 36 x 48 - ByLayer" "Sharp Color - 8.5 x 11"
                        "Sharp Color - 8.5 x 11 - ByLayer" "Sharp Color - 11 x 17"
                        "Sharp Color - 11 x 17 - ByLayer" "Sharp Color - 11 x 17 - STF"
                        "Sharp Color - 11 x 17 - STF - ByLayer" "HP LaserJet 8150N - 8.5 x 11"
                        "HP LaserJet 8150N - 8.5 x 11 - ByLayer" "HP LaserJet 8150N - 11 x 17"
                        "HP LaserJet 8150N - 11 x 17 - ByLayer" "HP LaserJet 8150N - 11 x 17 - STF"
                        "HP LaserJet 8150N - 11 x 17 - STF - ByLayer"
                       )
              )
    )
  )
   -1
 )

 (textscr)
 (mapcar (function print) lst)
 (if (setq int (getint "\nSpecify number for Page Setup option: "))
   (if (setq choice (cdr (assoc int lst)))
     (progn
       (command
         "._-PSetupIN"
         "C:/Users/TAbel/AppData/Roaming/PortableApps/Dropbox/Dropbox/AutoCAD/Templates/Page Setups - 64bit.dwt"
         "*"
       )
       (command "-Plot" "No" "" choice "" "No" "Yes" "No")
     )
     (princ "\nInvalid selection.")
   )
 )
 (princ)
)

Posted

Completely impractical (will crowd screen)...

 

(defun c:TEst (/ lst choice)
 ((lambda (i)
    (setq lst (mapcar (function (lambda (x) (list (setq i (1+ i)) x)))
                      '("PDF - 11 x 17" "PDF - 11 x 17 - ByLayer" "PDF - 17 x 22"
                        "PDF - 17 x 22 - ByLayer" "PDF - 18 x 24" "PDF - 18 x 24 - ByLayer"
                        "PDF - 22 x 34" "PDF - 22 x 34 - ByLayer" "PDF - 24 x 36"
                        "PDF - 24 x 36 - ByLayer" "PDF - 30 x 42" "PDF - 30 x 42 - ByLayer"
                        "PDF - 34 x 44" "PDF - 34 x 44 - ByLayer" "PDF - 36 x 48"
                        "PDF - 36 x 48 - ByLayer" "Xerox 6204 - 17 x 22 - STF"
                        "Xerox 6204 - 17 x 22 - STF - ByLayer" "Xerox 6204 - 18 x 24 - STF"
                        "Xerox 6204 - 18 x 24 - STF - ByLayer" "Xerox 6204 - 22 x 34"
                        "Xerox 6204 - 22 x 34 - ByLayer" "Xerox 6204 - 22 x 34 - STF"
                        "Xerox 6204 - 22 x 34 - STF - ByLayer" "Xerox 6204 - 24 x 36"
                        "Xerox 6204 - 24 x 36 - ByLayer" "Xerox 6204 - 24 x 36 - STF"
                        "Xerox 6204 - 24 x 36 - STF - ByLayer" "Xerox 6204 - 30 x 42"
                        "Xerox 6204 - 30 x 42 - ByLayer" "Xerox 6204 - 30 x 42 to 18 x 24"
                        "Xerox 6204 - 30 x 42 to 24 x 36" "Xerox 6204 - 34 x 44"
                        "Xerox 6204 - 34 x 44 - ByLayer" "Xerox 6204 - 36 x 48"
                        "Xerox 6204 - 36 x 48 - ByLayer" "Sharp Color - 8.5 x 11"
                        "Sharp Color - 8.5 x 11 - ByLayer" "Sharp Color - 11 x 17"
                        "Sharp Color - 11 x 17 - ByLayer" "Sharp Color - 11 x 17 - STF"
                        "Sharp Color - 11 x 17 - STF - ByLayer" "HP LaserJet 8150N - 8.5 x 11"
                        "HP LaserJet 8150N - 8.5 x 11 - ByLayer" "HP LaserJet 8150N - 11 x 17"
                        "HP LaserJet 8150N - 11 x 17 - ByLayer" "HP LaserJet 8150N - 11 x 17 - STF"
                        "HP LaserJet 8150N - 11 x 17 - STF - ByLayer"
                       )
              )
    )
  )
   -1
 )

 (initget
   0
   (vl-list->string
     (cdr (apply (function append)
                 (mapcar (function (lambda (x) (cons 32 (vl-string->list (itoa (car x)))))) lst)
          )
     )
   )
 )
 (if (setq choice
            (getkword
              (strcat
                "\nSpecify number for Page Setup option ["
                (substr
                  (apply
                    'strcat
                    (mapcar (function (lambda (x) (strcat "/" (itoa (car x)) " = " (cadr x)))) lst)
                  )
                  2
                )
                "]: "
              )
            )
     )
   (progn
     (command
       "._-PSetupIN"
       "C:/Users/TAbel/AppData/Roaming/PortableApps/Dropbox/Dropbox/AutoCAD/Templates/Page Setups - 64bit.dwt"
       "*"
     )
     (command "-Plot" "No" "" (cadr (nth (atoi choice) lst)) "" "No" "Yes" "No")
   )
 )
 (princ)
)

Posted

Now, you could mimic the Dynamic Properties menu and use the DosLib (must download) popup menu.

 

eg.

(defun c:TEst (/ lst choice)
 (setq lst '("PDF - 11 x 17" "PDF - 11 x 17 - ByLayer" "PDF - 17 x 22" "PDF - 17 x 22 - ByLayer"
             "PDF - 18 x 24" "PDF - 18 x 24 - ByLayer" "PDF - 22 x 34" "PDF - 22 x 34 - ByLayer"
             "PDF - 24 x 36" "PDF - 24 x 36 - ByLayer" "PDF - 30 x 42" "PDF - 30 x 42 - ByLayer"
             "PDF - 34 x 44" "PDF - 34 x 44 - ByLayer" "PDF - 36 x 48" "PDF - 36 x 48 - ByLayer"
             "Xerox 6204 - 17 x 22 - STF" "Xerox 6204 - 17 x 22 - STF - ByLayer"
             "Xerox 6204 - 18 x 24 - STF" "Xerox 6204 - 18 x 24 - STF - ByLayer"
             "Xerox 6204 - 22 x 34" "Xerox 6204 - 22 x 34 - ByLayer" "Xerox 6204 - 22 x 34 - STF"
             "Xerox 6204 - 22 x 34 - STF - ByLayer" "Xerox 6204 - 24 x 36"
             "Xerox 6204 - 24 x 36 - ByLayer" "Xerox 6204 - 24 x 36 - STF"
             "Xerox 6204 - 24 x 36 - STF - ByLayer" "Xerox 6204 - 30 x 42"
             "Xerox 6204 - 30 x 42 - ByLayer" "Xerox 6204 - 30 x 42 to 18 x 24"
             "Xerox 6204 - 30 x 42 to 24 x 36" "Xerox 6204 - 34 x 44"
             "Xerox 6204 - 34 x 44 - ByLayer" "Xerox 6204 - 36 x 48"
             "Xerox 6204 - 36 x 48 - ByLayer" "Sharp Color - 8.5 x 11"
             "Sharp Color - 8.5 x 11 - ByLayer" "Sharp Color - 11 x 17"
             "Sharp Color - 11 x 17 - ByLayer" "Sharp Color - 11 x 17 - STF"
             "Sharp Color - 11 x 17 - STF - ByLayer" "HP LaserJet 8150N - 8.5 x 11"
             "HP LaserJet 8150N - 8.5 x 11 - ByLayer" "HP LaserJet 8150N - 11 x 17"
             "HP LaserJet 8150N - 11 x 17 - ByLayer" "HP LaserJet 8150N - 11 x 17 - STF"
             "HP LaserJet 8150N - 11 x 17 - STF - ByLayer"
            )
 )

 (if (setq choice (dos_popupmenu lst))
   (progn
     (command
       "._-PSetupIN"
       "C:/Users/TAbel/AppData/Roaming/PortableApps/Dropbox/Dropbox/AutoCAD/Templates/Page Setups - 64bit.dwt"
       "*"
     )
     (command "-Plot" "No" "" (nth choice lst) "" "No" "Yes" "No")
   )
 )
 (princ)
)

 

popup.jpg

Posted

I really appreciate the help. Unfortunately my lisp knowledge extends to...lisp. :P

 

One more thing to learn.

Posted
I really appreciate the help. Unfortunately my lisp knowledge extends to...lisp. :P

 

One more thing to learn.

DosLib is just free a LISP addon pacakge. Did you actually look at the code I posted, there's nothing but LISP.
Posted

Ah, I see what you're saying. Just extra functions. Unfortunately our company gives us zero admin rights. So having to install this on 70 computers will mean my IT admin will tell me to go pound sand. lol.

Posted
Ah, I see what you're saying. Just extra functions. Unfortunately our company gives us zero admin rights. So having to install this on 70 computers will mean my IT admin will tell me to go pound sand. lol.

That sucks. I've worked for those companies.

Try this for a list selection...

 

(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
 ;; List Select Dialog (Temp DCL list box selection, based on provided list)
 ;; title - list box title
 ;; label - label for list box
 ;; height - height of box
 ;; width - width of box
 ;; multi - selection method ["true": multiple, "false": single]
 ;; lst - list of strings to place in list box
 ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
 (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
 (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                  (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                  (strcat "width = " (vl-princ-to-string width) ";")
                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
            )
   (write-line x fo)
 )
 (close fo)
 (new_dialog "list_select" (setq d (load_dialog fn)))
 (start_list "lst")
 (mapcar (function add_list) lst)
 (end_list)
 (setq item (set_tile "lst" "0"))
 (action_tile "lst" "(setq item $value)")
 (setq f (start_dialog))
 (unload_dialog d)
 (vl-file-delete fn)
 (if (= f 1)
   ((lambda (s / i s l)
      (while (setq i (vl-string-search " " s))
        (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
        (setq s (substr s (+ 2 i)))
      )
      (reverse (cons (nth (atoi s) lst) l))
    )
     item
   )
 )
)

 

Time to go home, or I'd help with a little demo.

Posted

So far I've just converted the lisp routine to work with two ribbon panels. One for 32-bit, one for 64-bit. I'll try tinkering with your code tomorrow to see how it works. Always nice to reverse engineer others' code to make myself a better programmer. That and I might just use it on a future command. Either way, I definitely appreciate the help you've given me.

Posted
So far I've just converted the lisp routine to work with two ribbon panels. One for 32-bit, one for 64-bit. I'll try tinkering with your code tomorrow to see how it works. Always nice to reverse engineer others' code to make myself a better programmer. That and I might just use it on a future command. Either way, I definitely appreciate the help you've given me.

Let's see what you have. I might can help - if you are interested.

Posted
Let's see what you have. I might can help - if you are interested.

 

Here's everything I've managed to complete so far. Again, apologies for the formatting in the .lsp file itself as I use notepad++ to program.

 

https://www.dropbox.com/s/up6g04jekn53hrx/Lisp.zip

 

Sorry, there was a size limit, so the link above will take you to what you need.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...