Author Topic: prompt or message  (Read 2941 times)

0 Members and 1 Guest are viewing this topic.

DanB

  • Bull Frog
  • Posts: 367
prompt or message
« on: July 25, 2018, 05:19:35 PM »
It's been a long time since I hacked my way through LISP routines. I need some assistance with the following:

Code: [Select]
   (progn
    (prompt "\nCreating standard layers...")   
    (command "insert" "layers=C:/Cad/Layers.dwg" (command))
   ); progn

I would like the prompt or message to be on the command line as there is a small delay during the layer creation. Right now the message isn't displayed until the block is inserted and completed. Right now it all shows up at the same time. There is an additional line:

Code: [Select]
  (prompt "\nDone...")

This would show upon completion.

Suggestions on adding some sort of pause or priority to the message being displayed?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: prompt or message
« Reply #1 on: July 26, 2018, 12:22:26 AM »
Try this:
Code: [Select]
(prompt "\nCreating standard layers...\n")
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.

DanB

  • Bull Frog
  • Posts: 367
Re: prompt or message
« Reply #2 on: July 26, 2018, 09:31:04 AM »
Thanks, there's some improvement but there's still a long pause/delay before the message shows and the layers are created. I'm thinking this must be network server lag (the layers.dwg recides there). The prompt is showing just as the delay ends and just sort of runs together. Not a huge ordeal, just trying to improve upon it.

Is it possible to prompt a message and insert an intentional small delay before the code even tries to run the insert?


<edit> just came across this:

(command "._delay" 2000)
« Last Edit: July 26, 2018, 09:34:19 AM by DanB »

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: prompt or message
« Reply #3 on: July 26, 2018, 10:10:59 AM »
No, it's not network delays, its the synchronous nature of the command line panel.  You used to be able to fool the system a bit, but when they changed the panel to accept clicking options right on the command line, that went away.  Any long-running loop will cause AutoCAD to wait to flush prompts to the command line.

You might want to look at the ACET progress bar (acet-ui-progress-init ...), (acet-ui-progress-safe ...), and (acet-ui-progress-done) functions for an inline progress indication.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: prompt or message
« Reply #4 on: July 26, 2018, 10:26:03 AM »
.......its the synchronous nature of the command line panel.  You used to be able to fool the system a bit, but when they changed the panel to accept clicking options right on the command line, that went away.  Any long-running loop will cause AutoCAD to wait to flush prompts to the command line..

Thanks for that confirmation.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: prompt or message
« Reply #5 on: July 26, 2018, 12:34:09 PM »
It used to be that inserting a (princ) after the message would cause the command-line to update prior to evaluating the command expression, e.g.:

Code - Auto/Visual Lisp: [Select]
  1.     (princ "\nCreating standard layers...")
  2.     (princ)
  3.     (command "_.-insert" "layers=C:/Cad/Layers.dwg" nil)
  4. ); progn

I'm unsure whether this holds true in recent releases.

DanB

  • Bull Frog
  • Posts: 367
Re: prompt or message
« Reply #6 on: July 26, 2018, 01:33:09 PM »
Thanks, appreciate the help with this.

<edit>
The following works well..

Code: [Select]
   (progn
    (acet-ui-status "" "Creating Standard layers...")
    (princ "\nCreating Standard layers...\n")
    (princ)
    (command "_.-insert" "layers=G:/Layers.dwg" nil) ;update path as needed, redefines block
    (acet-ui-status)
    (princ "\nDone...")
   ); progn
« Last Edit: July 26, 2018, 02:49:47 PM by DanB »

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: prompt or message
« Reply #7 on: July 26, 2018, 05:05:48 PM »
I use that method on all routines any more. I can have a floating box appear while the command is going. Towards the end of the routine I can close the window too. Best thing I have used.

(acet-ui-status "Save As NAME OF DRAWING.DWG." "Floating Information Popup") (Shows the pop up window)

(acet-ui-status) (Hides the pop up window)
Civil3D 2020

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: prompt or message
« Reply #8 on: July 27, 2018, 11:03:58 AM »
I cant help on the prompt thing but I suspect it's just the way it is (AutoCAD will prompt after it completes the insert -ie. insert takes priority).

You could always use another method for updating layers. The following is something I wrote a while back for myself. I used this as a subroutine for another process but it could easily be a separate call by the end user and I have kept/commented out sections for you to review/change (I also uncommitted out the timer function).

This lisp should be very quick on your machines (users may not know it even runs) -e.g. I just created 200 layers in 0.047 seconds- and this was the purpose of it, I used to call this as part of a larger standards set of functions.

Code - Auto/Visual Lisp: [Select]
  1. ;; NAME
  2. ;;         Layer Settings
  3. ;;
  4. ;; SYNOPSIS
  5. ;;         Load a previous saved layer file.
  6. ;;
  7. ;; DESCRIPTION
  8. ;;         This application will allow you to load previous saved layers
  9. ;;         (name, color, line type, and state) to the current drawing. If
  10. ;;         the layers do not exist they will be created using the
  11. ;;         settings in the file. If the layer name already exists in the
  12. ;;         drawing, those settings will not be updated -- this is to
  13. ;;         allow for custom, per drawing, layer overrides-.
  14. ;;              //-- SEE CHANGE LOG --//
  15. ;;
  16. ;;         This procedure starts upon load into AutoCAD.
  17. ;;
  18. ;;         To save the current drawings layers use:
  19. ;;              (process-on-drawing (save-layer-list-to-file))
  20. ;;         A file with the current drawings file name, with the `.la'
  21. ;;         suffix will be saved to the current drawings location.
  22. ;;
  23. ;; NOTES
  24. ;;      |  This procedure was published (posted) to offered as a starting
  25. ;;    O |  point for your own layer state restore procedure. Although it
  26. ;;    U |  can be used as is, the procedure can be expanded to offer a
  27. ;;    T |  better overall layer creator application for your company
  28. ;;      |  standards. Currently I do not have any time to spend working
  29. ;;      |  on this application.
  30. ;;
  31. ;;    D |  My overall objective was to create a fast way for me to load
  32. ;;    A |  up layer settings for my CAD users. I have run several
  33. ;;    T |  benchmarks on the procedures I used in this application and as
  34. ;;    E |  a whole as well. I tested this application's time for creating
  35. ;;    D |  10,000 layers in a blank drawing and this app took approximately
  36. ;;      |  0.23 seconds to preform that operation.
  37. ;;
  38. ;; AUTHOR
  39. ;;         John (Se7en) Ka
  40. ;;
  41. ;; VERSION
  42. ;;         1.0.ave
  43. ;;
  44. ;; CHANGE LOG
  45. ;;         1.0.0        Orig issue
  46. ;;                      05.20.08
  47. ;;         1.0.1        Revised to handle plot/noplot setting
  48. ;;                      (dxf code 290)
  49. ;;                      Closed layer file once done reading
  50. ;;                      05.27.08
  51. ;;         1.0.2        Removed parsing of drawings layer list to
  52. ;;                      names ...making it faster.
  53. ;;                      New time for creating 10,000 layers was 1.36 seconds
  54. ;;                      05.28.08
  55. ;;         1.0.3        Added the ability to modify layers already in dwg which
  56. ;;                      are different the ones found in the layer file.
  57. ;;         1.0.4        Added the ability to load and handle linetypes not in
  58. ;;                      drawing or located in .lin file in search path
  59. ;;                      07.22.08
  60. ;;
  61. ;;
  62. ;; //-- CAUTION (After version 1.0.4) --//
  63. ;;           since the addition of the layer and linetype over rides this
  64. ;;           application has become very sloppy and needs to go thru a re-write
  65. ;;           I plan on re-writing this applicaion when I have more time.
  66. ;;
  67. ;;
  68. ;; Last Updated: 07.22.08 9:32:29 AM
  69.  
  70. ;; //-- BEGIN SUPPORT PROCEDURES --//
  71.  
  72. (defun process-on-drawing ( process )
  73.   ;; a simple `hook' to run a process
  74. ;;       (if (= (getvar 'DWGTITLED) 1)
  75.         (eval process)
  76. ;;         "Drawing not saved"
  77. ;;          )
  78.         )
  79.  
  80. (defun save-layer-list-to-file ( / x f fp )
  81.   ;; retrieve all layers from dwg dict and save
  82.   ;; to a file.  file saved where drawing is located
  83.       (setq f (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) ".la")
  84.             fp (open f "A"))
  85.       (while (setq x (tblnext "LAYER" (not x)))
  86.              (cond
  87.                ((not (>= (cdr (assoc 70 x)) 16))
  88.                 (prin1 x fp)
  89.                 (princ "\n" fp)) )
  90.              )
  91.       (close fp)
  92.       (princ) )
  93.  
  94. (defun get-list-from-file ( name / fp lst read-file-into-list )
  95.   ;; general file reader
  96.   ;; given a file name this procedure will read the contents
  97.   ;; into a list
  98.          (defun read-file-into-list ( str file )
  99.            (if str
  100.              (cons
  101.                (if str str)
  102.                (read-file-into-list (read-line file) file))))
  103.   (setq fp (open name "R"))
  104.   (setq lst (read-file-into-list (read-line fp) fp))
  105.   (close fp)
  106.  lst
  107. )
  108.  
  109. (defun get-drawing-dictionary-list ( what / x lst)
  110.   ;; retrieve a list of drawing dictionary entries
  111.        (while (setq x (tblnext what (not x)))
  112.           (setq lst (cons x lst))) )
  113.  
  114. (defun build-name-list ( lst )
  115.   ;; given a list of raw dic entries this proced
  116.   ;; will report entity names
  117.          (if (null lst)
  118.            nil
  119.            (cons (cdr (assoc 2 (car lst)))
  120.                 (build-name-list (cdr lst)))) )
  121.  
  122. (defun build-modify-list ( ls )
  123.   ;; return list of items found in dwg but different from list
  124.           (mapcar
  125.             '(lambda ( x )
  126.                (if (not (member x dwg-layer-list))
  127.                  x))
  128.             ls) )
  129.  
  130. (defun remove-uncomon-names ( ls )
  131.   ;; return the items that are not in drawing
  132.           (mapcar
  133.             '(lambda ( x )
  134.                (if (not (and
  135. ;;                     (member x dwg-layer-list)
  136.                       (member (cdr (assoc 2 x)) dwg-layer-name-list)
  137.                      ))
  138.                  x))
  139.             ls) )
  140.  
  141. (defun get-value ( val lst )
  142.   ;; shortcut for returning value in assoc list
  143.        (cdr (assoc val lst)) )
  144.  
  145. (defun files-p ( path pattern )
  146.   ;; files-p
  147.   ;;
  148.   ;; Returns a list of all the files in a given path
  149.   ;; with a given search pattern. If a nill pattern
  150.   ;; to search for is not given, defaults to ``*.*''.
  151.   ;;
  152.   ;; Ex:
  153.   ;; (files-p "C:\\" nil)
  154.   ;;
  155.   ;; => returns all files in directory specified.
  156.   ;;
  157.   ;; By: John (7) K
  158.   ;;
  159.   (
  160.    (lambda ( a e )
  161.      (if (null a)
  162.        nil
  163.        (cond
  164.          ((null e)
  165.           (vl-directory-files a "*.*" 1))
  166.          (T(vl-directory-files a e 1)))) )
  167.    path ; a
  168.    pattern ; e
  169.    ) )
  170.  
  171. (defun strParse (aStr delim / strList pos)
  172.   (while
  173.     (setq pos (vl-string-search delim aStr 0))
  174.     ;; Find the postition where the delimiter first shows up.
  175.     (setq strList (cons (substr aStr 1 POS) strList)
  176.     ;; create a list of the fist substring (up untill the delimiter)
  177.           strList (cons (substr aStr (1+ POS) 1) strList)
  178.           aStr (substr aStr (+ pos 2)))
  179.     ;; Skip over the delimiter and grab the rest of the string,
  180.     ;; Set that as the new string
  181.     )
  182.   (reverse (cons aStr strList))
  183.  )
  184.  
  185.  ;; //-- END SUPPORT PROCEDURES --//
  186.  
  187. (defun laf ( file-layer-list / dwg-layer-list dwg-layer-name-list
  188.               todo-layer-list timer layers-to-modify
  189.               ltype-file-locations file-layer-list
  190.               ltype-locations dwg-ltype-name-list
  191.               )
  192. ;;;
  193. ;;;(defun c:laf ( / dwg-layer-list dwg-layer-name-list
  194. ;;;              todo-layer-list timer layers-to-modify
  195. ;;;              ltype-file-locations file-layer-list
  196. ;;;              ltype-locations dwg-ltype-name-list
  197. ;;;              )
  198.  
  199.     (setq
  200.       dwg-layer-list (process-on-drawing '(get-drawing-dictionary-list "LAYER"))
  201.       ;; build a list of layers in current drawing
  202.  
  203.       dwg-layer-name-list (build-name-list dwg-layer-list)
  204.  
  205.  
  206.       dwg-ltype-name-list
  207.                 (build-name-list
  208.                   (process-on-drawing '(get-drawing-dictionary-list "LTYPE")))
  209.       ;; build a list of litetype names loaded in dwg
  210.  
  211.       ltype-file-locations
  212.                    (apply
  213.                      ;; itterate thru the entire search path to look for .lin files
  214.                      'append
  215.                      (mapcar
  216.                        '(lambda ( x / tmp-str)
  217.                           (setq tmp-str (files-p x "*.lin"))
  218.                           (if (and tmp-str (not (eq ";" x)))
  219.                             (list
  220.                               (strcat
  221.                                 x
  222.                                 "\\"
  223.                                 (car tmp-str)))))
  224.                        (strparse (getvar "ACADPREFIX") ";") ))
  225.       ltype-locations
  226.        ;; a list of lists for the lietypes and their locations
  227.        ;; ( <path>+<file> ( <ltype> <ltype> ... ))
  228.                    (mapcar
  229.                     '(lambda ( x / f lt-list)
  230.                        (setq lt-list
  231.                           (mapcar
  232.                              '(lambda ( x )
  233.                                 (if x
  234.                                   (substr (car (strparse x ",")) 2)))
  235.                                 (get-list-from-file x)
  236.                              )
  237.                           )
  238.                        (cons x (list lt-list))
  239.                        )
  240.                     ltype-file-locations
  241.                     )
  242.  
  243.       file-layer-list (mapcar
  244.                         'read (get-list-from-file
  245.                                 file-layer-list
  246. ;;;                          (getfiled "Layer file" "" "la" 0)
  247.                           ))
  248.       ;; get the layers from the file (layers to impliment)
  249.  
  250.                 timer (getvar "millisecs")
  251.       ;;          ;; set up a timer
  252.  
  253.       todo-layer-list (remove-uncomon-names file-layer-list)
  254.       ;; build a list of layers that need to be created.
  255.  
  256.       )
  257.          ;; parse out the already defined common layers
  258.  
  259.     (mapcar
  260.       ;;
  261.       ;; create layers not in drawing already
  262.       ;;
  263.       ;; TODO: Add Linetype support -- inline
  264.       '(lambda (x / lt plot)
  265.          ;; create the layers
  266.          (if (not (null x))
  267.            ;; do not opperate on null entries.
  268.            (progn
  269.              (setq lt (get-value 6 x)
  270.                    lt
  271.                    (cond
  272.                      ((member lt dwg-ltype-name-list)
  273.                       (cons 6 lt))
  274.                      ((and
  275.                         (not (tblsearch "LTYPE" (get-value 6 x)))
  276.                         (not (member (get-value 6 x) dwg-ltype-name-list)))
  277.                       (mapcar
  278.                        '(lambda ( x )
  279.                                (if (member lt (car (cdr x)))
  280.                                 (progn
  281.                                  (command-s "_.linetype" "_load" lt (car x) "")
  282.                                  (setq dwg-ltype-name-list
  283.                                     ;; remake the drawing ltype list
  284.                                     (build-name-list
  285.                                      (process-on-drawing
  286.                                       '(get-drawing-dictionary-list "LTYPE"))))
  287.                                 );_ end progn
  288.                                );_ end if
  289.                                );_ end lambda
  290.                         ltype-locations)
  291.                        (if (not (tblsearch "LTYPE" lt))
  292.                         ;; another search level incase we still coulnt find lt.
  293.                          (progn
  294.                          (mapcar
  295.                            'princ
  296.                            (list
  297.                              "\nLinetype for Layer: "
  298.                              (get-value 2 x)
  299.                              " Not found, using continuous instead."))
  300.                          (cons 6 "Continuous")
  301.                          )
  302.                          (cons 6 (get-value 6 x)))
  303.                        )
  304.                      )
  305.                    plot
  306.                    (cond
  307.                      ((get-value 290 x)
  308.                       (cons 290 (get-value 290 x)))
  309.                      (t (cons 290 1))))
  310.              (entmake (list
  311.                         '(0 . "LAYER")
  312.                         '(100 . "AcDbSymbolTableRecord")
  313.                         '(100 . "AcDbLayerTableRecord")
  314.                         (cons 2 (get-value 2 x))
  315.                         (cons 70 (get-value 70 x))
  316.                         (cons 62 (get-value 62 x))
  317.                         plot
  318.                         lt
  319.                         );_ end list
  320.                       );_ end entmake
  321.              );_ end progn
  322.            );_ end if
  323.          )
  324.       todo-layer-list
  325.       )
  326.  
  327.  (setq  dwg-layer-list (process-on-drawing '(get-drawing-dictionary-list "LAYER"))
  328.         layers-to-modify (build-modify-list file-layer-list)
  329.         ;; build a list of layers that need to be modified.
  330.         )
  331.  
  332.       (mapcar
  333.         ;;
  334.         ;; Update or change layers that do not have properties
  335.         ;; listed in layer file
  336.         ;;
  337.         ;; TODO: Add linetype support -- inline
  338.         '(lambda ( x / lt plot layer )
  339.            (if (not (null x ))
  340.              ;; do not opperate on null entries in list
  341.              (progn
  342.                (setq layer (entget (tblobjname "LAYER" (cdr (assoc 2 x)))))
  343.                ;; get the layer from the dwg dict.
  344.                (mapcar
  345.                  '(lambda ( key / plot )
  346.                     ;; we are going to modify several of the drawing layer props at once
  347.                     ;; the dxf codes can be found at the end of the mapcar function call
  348.                     (cond
  349.                       ((eq key 290)
  350.                        ;; if we are on key 290 (ploting flag)
  351.                        (set 'plot (if (get-value key x) 0 1))
  352.                        ;; determine if the layer value has the 290 entry;
  353.                        ;; if not return 1 (plot able) if it does return 0
  354.                        (setq layer (append layer (list (cons 290 plot))))
  355.                        ;; mod the layer list
  356.                        )
  357.                       ((get-value key layer)
  358.                        ;; other wise just mod the layer list
  359.                        (setq layer (subst (assoc key x) (assoc key layer) layer)))) )
  360.                  '(6 62 70 290) )
  361.  
  362.                (entmod layer)
  363.                ;; make modifications
  364.                );_ end progn
  365.              );_ end if
  366.            )
  367.         layers-to-modify
  368.         )
  369.          (princ
  370.                (strcat
  371.                  "\n;; Process took "
  372.                  (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
  373.                  " seconds."))
  374.   )
  375.  
  376. ; (laf "blah\\blah\\Company-Layers.la")
  377.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

DanB

  • Bull Frog
  • Posts: 367
Re: prompt or message
« Reply #9 on: July 27, 2018, 03:15:28 PM »
Thanks John, I will definitely have a look at this.