Author Topic: help fast!!! Popup_list and List_box  (Read 4593 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
help fast!!! Popup_list and List_box
« on: March 26, 2016, 05:53:36 PM »
Hi I have a question:
I have several ready in a "popup list" and I want every time you choose one of these lists the contents of these look a "list_box"

Code Lisp:
Code: [Select]
;;;---------------------------------------- setvar --------------------------
(defun saveVars()
  (setq blkList (list))
  (setq ignlist (get_tile "bloqlist")) 
  (setq count 1)   
  (while (setq fila (read ignlist))
    (setq blkList (append blkList (list (nth fila bloList))))
    (while
      (and
        (/= " " (substr ignlist count 1))
        (/= ""  (substr ignlist count 1)))
      (setq count (1+ count)))
    (setq ignlist (substr ignlist count))))

;;;---------------------------------------- read file "1-DWG-TOMACORRIENTES.txt" for default --------------------------
(defun blokinf ()
(setq bloList (list))   
(if (findfile "1-DWG-TOMACORRIENTES.txt")
(progn
(if (setq ruta (open (findfile "C:/Program Files/AutoCAD 2008/1-DWG-TOMACORRIENTES.txt") "r"))
(progn       
(read-line ruta) 
(while (setq pa (read-line ruta))         
(setq bloList         
(append
bloList
(list (list pa)))))
(close ruta))))) bloList )


;;;---------------------------------------- main program --------------------------
(defun c:E1 ( / bloqlist$ infolist$)
(if (not *E1@) (setq *E1@ (list nill "" "")))
(setq bloqlist$ (nth 1 *E1@))
(setq infolist$ (nth 2 *E1@))
(setvar "cmdecho" 0)
(setq bloList (blokinf))   
(if bloList   
(progn
(setq dcl_id (load_dialog "INSERT-1.dcl"))     
(if (not (new_dialog "INSERTA" dcl_id "" (cond (*screenpointE1*) ('(-1 -1)))))     
(progn
(princ "\n**ERROR**") (exit)))
(setq bloNames (list))   
(foreach pa bloList
(setq bloNames (append bloNames(list (car pa)))))

(setq folder (GetDwgsMob "AutoCAD 2008")) ;;add version autocad to folder

;;;;(_addlist "bloqlist" bloNames)

(_addlist "infolist" folder)

(set_tile "bloqlist" bloqlist$)
(set_tile "infolist" infolist$)
(action_tile "bloqlist" "(setq bloqlist$ $value)")
(action_tile "infolist" "(start_list \"bloqlist\") (mapcar 'add_list (eval (read (strcat \"1-DWG-\" $value \".TXT\")))) (end_list)")
(action_tile "cancel" "(setq *screenpointE1* (done_dialog 1))")
(action_tile "accept" "(saveVars)(setq *screenpointE1* (done_dialog 2))")
(setq ddiag (start_dialog))
(unload_dialog dcl_id)
(setq *E1@ (list nil bloqlist$ infolist$))
(if (= ddiag 1) (prompt "\n**Cancel**")) 
(princ))))

;;----------------- Path-2DAMobBasico ------------------------------------
;; main route ---> "C:/Program Files/"
;;------------------------------------------------------------------------

(defun Path-2DAMobBasico () "C:/Program Files/")

;;------------------------ GetDwgsMob ------------------------------------------------------------------
;; collects data from the specified directory  (setq folder (GetDwgsMob "AutoCAD 2008"))
;; return ---> "C:/Program Files/AutoCAD 2008/"
;;------------------------------------------------------------------------------------------------------
(defun GetDwgsMob (sParentMob / ListaMob DirMobTipo)         
     (if (setq DirMobTipo (strcat (Path-2DAMobBasico) sParentMob))
      (setq ListaMob (vl-directory-files (strcat DirMobTipo "\\") "*.txt" 1)
       ListaMob (mapcar (function vl-filename-base) ListaMob))   
     );c.if
     ListaMob
    );c.defun

(defun _addlist ( key lst )
        (start_list key)
        (foreach x lst (add_list x))
        (end_list)
        lst)

   

Code DCL
Code: [Select]
INSERTA : dialog { label = "Program.....";
          initial_focus="bloqlist";
          : column {
            spacer_1;
          : boxed_row { label = "content of each list"; alignment = centered;
  spacer_1;
           : list_box { key = "bloqlist"; allow_accept = true; fixed_width = true; width = 40; value = "0";}
         }
          spacer_1;
          }
         spacer_1;
: popup_list { width =40; key = "infolist"; value = "1"; is_enabled = true ; }
spacer_1;
: row {
: button { key = "accept";label = "accept"; is_default = true;width =14;}
           : button { key = "cancel";label = "cancel"; is_default = false; is_cancel = true;width =14;}
   }
 }


 :| :| :| :| :| :| :| :| :| :| :wideeyed2: :wideeyed2:
« Last Edit: March 27, 2016, 02:40:04 PM by amc.dicsac »
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #1 on: March 28, 2016, 10:26:47 AM »
For a more complete understanding of your code. I suggest that you attach the text files you are referencing. On examination of your code I believe the problem is that in your action tile for "infolist", you are trying to populate the "bloqlist" list box by doing a (eval (read... of the text file. I don't believe this will produce a list from the text file like you wish. You need to use a function like the (blokinf) function in your code to open the text file, read the contents into a list, and close it.

Try this alteration to your code - Please NOTE this is UNTESTED since I do not have your text files to work with. I have altered "blokinf" to accept any file and separated out the path and put it in in the main program. Then in the action_tile statement, I am using your existing "_addlist" function along with the altered "blokinf" to read the text file.

Code - Auto/Visual Lisp: [Select]
  1. ;;;---------------------------------------- setvar --------------------------
  2. (defun saveVars()
  3.    (setq blkList (list))
  4.    (setq ignlist (get_tile "bloqlist"))
  5.    (setq count 1)
  6.    (while (setq fila (read ignlist))
  7.       (setq blkList (append blkList (list (nth fila bloList))))
  8.       (while
  9.          (and
  10.            (/= " " (substr ignlist count 1))
  11.            (/= ""  (substr ignlist count 1))
  12.          )
  13.          (setq count (1+ count))
  14.       )
  15.       (setq ignlist (substr ignlist count))
  16.    )
  17. )
  18.  
  19. ;;;---------------------------------------- read file "1-DWG-TOMACORRIENTES.txt" for default --------------------------
  20. ;; Altered by PKenewell to work for any file - 3-28-2016
  21. (defun blokinf (file / blolist pa ruta)
  22.    (if (and (findfile file) (setq ruta (open file "r")))
  23.       (progn
  24.          (read-line ruta)
  25.          (while (setq pa (read-line ruta))
  26.             (setq bloList
  27.                   (append bloList (list (list pa)))
  28.             )
  29.          )
  30.          (close ruta)
  31.       )
  32.    )
  33.    bloList
  34. )
  35.  
  36.  
  37. ;;;---------------------------------------- main program --------------------------
  38. (defun c:E1 ( / bloqlist$ infolist$)
  39.    (if (not *E1@) (setq *E1@ (list nil "" "")))
  40.    (setq bloqlist$ (nth 1 *E1@))
  41.    (setq infolist$ (nth 2 *E1@))
  42.    (setvar "cmdecho" 0)
  43.    (setq path "C:/Program Files/AutoCAD 2008/"
  44.          f1 "1-DWG-TOMACORRIENTES.txt"
  45.    )
  46.    (setq bloList (blokinf (strcat path f1)))
  47.    (if bloList
  48.       (progn
  49.          (setq dcl_id (load_dialog "INSERT-1.dcl"))
  50.          (if (not (new_dialog "INSERTA" dcl_id "" (cond (*screenpointE1*) ('(-1 -1)))))
  51.             (progn
  52.                   (princ "\n**ERROR**")
  53.                   (exit)
  54.             )
  55.          )
  56.          (setq bloNames (list))
  57.          (foreach pa bloList
  58.             (setq bloNames (append bloNames (list (car pa))))
  59.          )
  60.  
  61.          (setq folder (GetDwgsMob "AutoCAD 2008")) ;;add version autocad to folder
  62.  
  63.          ;;;;(_addlist "bloqlist" bloNames)
  64.  
  65.          (_addlist "infolist" folder)
  66.  
  67.          (set_tile "bloqlist" bloqlist$)
  68.          (set_tile "infolist" infolist$)
  69.          (action_tile "bloqlist" "(setq bloqlist$ $value)")
  70.  
  71.          ;;(action_tile "infolist" "(start_list \"bloqlist\") (mapcar 'add_list (eval (read (strcat \"1-DWG-\" $value \".TXT\")))) (end_list)")
  72.  
  73.          ;; Use the existing _addlist and altered blokinf functions to create your list.
  74.          (action_tile "infolist" "(_addlist \"bloqlist\" (blokinf (strcat path \"1-DWG-\" $value \".TXT\")))")
  75.  
  76.          (action_tile "cancel" "(setq *screenpointE1* (done_dialog 1))")
  77.          (action_tile "accept" "(saveVars)(setq *screenpointE1* (done_dialog 2))")
  78.          (setq ddiag (start_dialog))
  79.          (unload_dialog dcl_id)
  80.          (setq *E1@ (list nil bloqlist$ infolist$))
  81.          (if (= ddiag 1) (prompt "\n**Cancel**"))
  82.          (princ)
  83.       )
  84.    )
  85. )
  86.  
  87. ;;----------------- Path-2DAMobBasico ------------------------------------
  88. ;; main route ---> "C:/Program Files/"
  89. ;;------------------------------------------------------------------------
  90.  
  91. (defun Path-2DAMobBasico () "C:/Program Files/")
  92.  
  93. ;;------------------------ GetDwgsMob ------------------------------------------------------------------
  94. ;; collects data from the specified directory  (setq folder (GetDwgsMob "AutoCAD 2008"))
  95. ;; return ---> "C:/Program Files/AutoCAD 2008/"
  96. ;;------------------------------------------------------------------------------------------------------
  97. (defun GetDwgsMob (sParentMob / ListaMob DirMobTipo)
  98.    (if (setq DirMobTipo (strcat (Path-2DAMobBasico) sParentMob))
  99.       (setq ListaMob (vl-directory-files (strcat DirMobTipo "\\") "*.txt" 1)
  100.             ListaMob (mapcar (function vl-filename-base) ListaMob))
  101.    ) ;c.if
  102.    ListaMob
  103. ) ;c.defun
  104.  
  105. (defun _addlist ( key lst )
  106.    (start_list key)
  107.    (foreach x lst (add_list x))
  108.    (end_list)
  109.    lst
  110. )
  111.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #2 on: March 28, 2016, 12:33:42 PM »
Hello

Thanks for your answer but I can not see the content in the list_box I associate .txt files  :cry2:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #3 on: March 28, 2016, 02:35:29 PM »
Hello

Thanks for your answer but I can not see the content in the list_box I associate .txt files  :cry2:

My apologies if this is a translation problem, but I am not really sure what you are attempting to do. I appears as though you have a set of text files in the path "C:/Program Files/AutoCAD 2008/" that are named "1-DWG-1.TXT, "1-DWG-2.TXT", etc. Ad you are trying to display the contents of one of these files when you select one from the popup_list. If I am interpreting this correctly - there are some problems with your approach to this.

Please give a better explanation of what you are trying to do. I will try to step through your code more and figure out what you are doing.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #4 on: March 28, 2016, 02:46:30 PM »
Yes you are correct  :wink:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #5 on: March 28, 2016, 04:13:50 PM »
OK - Here is a bit of a alteration to your code that I have tested and works. I have added commenting so hopefully you will be able to follow it and learn. This could be improved and made more efficient of course. However, since I do not know the final purpose and what you are doing with the rest of the code I'll leave it at this for now.

Code: [Select]
;;----------------- Path-2DAMobBasico ------------------------------------
;; main route ---> "C:/Program Files/"
;;------------------------------------------------------------------------

;; Set a Global variable for the Root path - this can be accessed anywhere.
(setq Path:2DAMobBasico "C:/Program Files/")

(setq *E1@ nil)

;;------------------------ GetDwgsMob ------------------------------------------------------------------
;; collects data from the specified directory  (setq folder (GetDwgsMob "AutoCAD 2008"))
;; return ---> "C:/Program Files/AutoCAD 2008/"
;;------------------------------------------------------------------------------------------------------
(defun GetDwgsMob (sParentMob / ListaMob DirMobTipo)
   (if (setq DirMobTipo (strcat Path:2DAMobBasico sParentMob))
      (setq ListaMob (vl-directory-files (strcat DirMobTipo "\\") "*.txt" 1)
            ListaMob (mapcar (function vl-filename-base) ListaMob))  ;; Strips off the file extension
   ) ;c.if
   ListaMob
) ;c.defun

;;;---------------------------------------- setvar --------------------------
(defun saveVars()
   (setq blkList (list))
   (setq ignlist (get_tile "bloqlist"))
   (setq count 1)
   (while (setq fila (read ignlist))
      (setq blkList (append blkList (list (nth fila bloList))))
      (while
         (and
           (/= " " (substr ignlist count 1))
           (/= ""  (substr ignlist count 1))
         )
         (setq count (1+ count))
      )
      (setq ignlist (substr ignlist count))
   )
)

;;;---------------------------------------- read file "1-DWG-TOMACORRIENTES.txt" for default --------------------------
;; Altered by PKenewell to work for any file - 3-28-2016
(defun blokinf (file / blolist pa ruta)
   (if (and (findfile file) (setq ruta (open file "r")))
      (progn
         (read-line ruta)
         (while (setq pa (read-line ruta))
            (setq bloList (append bloList (list pa)))
         )
         (close ruta)
      )
   )
   bloList
)

;;;---------------------------------------- main program --------------------------
;; Altered by PKenewell on 3-28-2016

(defun c:E1 ( / bloqlist$ infolist$ path f1 blolist dcl_id blonames ddiag)

   ;; I don't know how you are using this part on the return
   (if (not *E1@) (setq *E1@ (list nil "" "")))
   (setq bloqlist$ (nth 1 *E1@))
   (setq infolist$ (nth 2 *E1@))

   (setvar "cmdecho" 0)

   ;; Use your global variable and build the default path and filename.
   (setq path (strcat Path:2DAMobBasico "AutoCAD 2008/")
         f1 "1-DWG-TOMACORRIENTES"
   )
   ;; Read the list of default text notes.
   (setq bloList (blokinf (strcat path f1 ".txt")))

   ;; If the list exists, start the dialog.
   (if bloList
      (progn
         ;; DCL loading the dialog.
         (setq dcl_id (load_dialog "INSERT-1.dcl"))
         (if (not (new_dialog "INSERTA" dcl_id "" (cond (*screenpointE1*) ('(-1 -1)))))
            (progn
                  (princ "\n**ERROR**")
                  (exit)
            )
         )

         ;; This is unnecessary if Blonames is localized, and items are not needing to be double-listed
         ;;(setq bloNames (list))
         ;;(foreach pa bloList
         ;;   (setq bloNames (append bloNames (list (car pa))))
         ;;)

         ;; Gets the list of text files from the path
         (setq folder (GetDwgsMob "AutoCAD 2008")) ;;add version autocad to folder

         ;; Not needed - see above.
         ;;(_addlist "bloqlist" bloNames)

         ;; Adds the list of files into the popup_box.
         (_addlist "infolist" folder)

         ;; Adds the notes for the default
         (_addlist "bloqlist" bloList)

         ;; Sets the default values (which are "" - clears the list)
         (set_tile "bloqlist" bloqlist$)
         (set_tile "infolist" infolist$)

         ;; Action for slecting the value for the note in the file
         (action_tile "bloqlist" "(setq bloqlist$ $value)")

         ;; This wont work.
         ;;(action_tile "infolist" "(start_list \"bloqlist\") (mapcar 'add_list (eval (read (strcat \"1-DWG-\" $value \".TXT\")))) (end_list)")

         ;; Use the existing _addlist function to create your list in bloqlist based on the file correcponding to the item selected.
         (action_tile "infolist" "(_addlist \"bloqlist\" (setq bloList (blokinf (strcat path (nth (atoi $value) folder) \".txt\"))))")

         ;; Exit actions
         (action_tile "cancel" "(setq *screenpointE1* (done_dialog 1))")
         (action_tile "accept" "(saveVars)(setq *screenpointE1* (done_dialog 2))")

         ;; Display the Dialog and capture the exit code.
         (setq ddiag (start_dialog))

         ;; Unload the dialog
         (unload_dialog dcl_id)
         ;; Put the file and note values into a list
         (setq *E1@ (list nil bloqlist$ infolist$))

         ;; Display a cancel message if cancelled out - returning 1
         (if (= ddiag 1) (prompt "\n**Cancel**"))

         ;;exit quietly
         (princ)
      )
   )
)

;; ==============================================================================
;;  Function Name: (_addlist)

(defun _addlist ( key lst )
   (start_list key)
   (mapcar 'add_list lst)
   (end_list)
   lst
)
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #6 on: March 28, 2016, 05:35:33 PM »
Hi, thanks for your solution have modified the code specifically the set_tile the list_box and popup_list to default values to be saved but I get this error and what is not the problem

 _e1 ; error: bad argument type: listp "1-DWG-ALUMBRADO"


Code: [Select]
;; Set a Global variable for the Root path - this can be accessed anywhere.
(setq Path:2DAMobBasico "C:/Program Files/")

;;------------------------ GetDwgsMob ------------------------------------------------------------------
;; collects data from the specified directory  (setq folder (GetDwgsMob "AutoCAD 2008"))
;; return ---> "C:/Program Files/AutoCAD 2008/"
;;------------------------------------------------------------------------------------------------------
(defun GetDwgsMob (sParentMob / ListaMob DirMobTipo)
   (if (setq DirMobTipo (strcat Path:2DAMobBasico sParentMob))
      (setq ListaMob (vl-directory-files (strcat DirMobTipo "\\") "*.txt" 1)
            ListaMob (mapcar (function vl-filename-base) ListaMob))
   ) ;c.if
   ListaMob
) ;c.defun

;;--------------------------- saveVars1 -----------------------------------------
;;Establecemos la variable para la lista
;;Configurar una lista que contenga los elementos seleccionados (blkList1)
;;Guardar la configuración de lista (get_tile "bloqlist1") 
;;Ciclo a través de la lista de conseguir todos los elementos seleccionados
;;-------------------------------------------------------------------------------
(defun saveVars()
  (setq infolist$ (get_tile "infolist"))
   (setq blkList (list))
   (setq ignlist (get_tile "bloqlist"))
   (setq count 1)
   (while (setq fila (read ignlist))
      (setq blkList (append blkList (list (nth fila bloList))))
      (while
         (and
           (/= " " (substr ignlist count 1))
           (/= ""  (substr ignlist count 1)))
         (setq count (1+ count)))
      (setq ignlist (substr ignlist count))))

;;;---------------------------------------- read file "1-DWG-TOMACORRIENTES.txt" for default --------------------------
;; Altered by PKenewell to work for any file - 3-28-2016
(defun blokinf (file / blolist pa ruta)
   (if (and (findfile file) (setq ruta (open file "r")))
      (progn
         (read-line ruta)
         (while (setq pa (read-line ruta))
            (setq bloList (append bloList (list pa))))
         (close ruta)))
   bloList)

;;--------------------------- IMAGES -----------------------------------------
;;Configurar para inico de imagenes
;;-----------------------------------------------------------------------------


(defun c:E1 ( / bloqlist$ infolist$ key grr ip lastpt ent )
(setvar "cmdecho" 0)
(vl-load-com)

 ;;-----------------------------------------------------------------------------
(if (not *E1@) (setq *E1@ (list nil "" "")))
(setq infolist$ (nth 1 *E1@))
(setq bloqlist$ (nth 2 *E1@))

;; Use your global variable and build the default path and filename.
(setq path (strcat Path:2DAMobBasico "AutoCAD 2008/"))
(setq f1 "1-DWG-TOMACORRIENTES")
   
;; Read the list of default text notes.
(setq bloList (blokinf (strcat path f1 ".txt")))

(setq dcl_id (load_dialog "C:/Program Files/AutoCAD 2008/Support/CADMASTER 2008/RUTINAS/INSERT-1.dcl"))
(if (not (new_dialog "INSERTA" dcl_id "" (cond (*screenpointE1*) ('(-1 -1)))))
(progn (prompt "\n**Se produjo ERROR contactese con el Administrado de la aplicacion**")
(exit)))

;; Gets the list of text files from the path
;; add version autocad to folder
(setq folder (GetDwgsMob "AutoCAD 2008"))

;;--------------------------- Agregando Folders al Popup_list ----------------------------------------
;; Adds the list of files into the popup_box.
;; Use the existing _addlist function to create your list in bloqlist based on the file correcponding
;; to the item selected.
(_addlist "infolist" folder)

(set_tile "infolist" (itoa (cond ((vl-position bloList folder)) ((vl-position (setq bloList (car folder)) folder)))))
(action_tile "infolist" " (_addlist \"bloqlist\" (setq bloList (blokinf (strcat path (nth (atoi $value) folder) \".txt\"))))")

;; Adds the notes for the default
(_addlist "bloqlist" bloList)
(set_tile "bloqlist" (itoa (cond ((vl-position bloqxlist bloList)) ((vl-position (setq bloqxlist (car bloList)) blolist)))))
(action_tile "bloqlist" "(setq bloqxlist (nth (atoi $value) bloList))")

;;--------------------------- *AX:Escala1* ----------------------------------------
;; Variable para la escala del bloque a insertar por defecto "1.00"
;;---------------------------------------------------------------------------------
(if (= *AX:Escala1* nil) (set_tile "key_escala1" "1.00") (set_tile "key_escala1" (rtos *AX:Escala1* 2 2)))
(action_tile "key_escala1"  "(setq *AX:Escala1* (atof (get_tile \"key_escala1\")))")
(mode_tile "key_escala1" 2)

;;---------------------------------------------------------------------------------
(action_tile "cancel" "(setq *screenpointE1* (done_dialog 1))")
(action_tile "accept" "(saveVars)(setq *screenpointE1* (done_dialog 2))")
(action_tile "save" "(done_dialog 3)")
(action_tile "load" "(actualiza)")
(setq ddiag (start_dialog))
(unload_dialog dcl_id)
(setq *E1@ (list nil infolist$ bloqlist$))
(if (= ddiag 1) (prompt "\nPrograma Cancelado..."))
(if (= ddiag 2) (insertax))
(if (= ddiag 3) (carga))
(if (= ddiag 4) (actualiza))
(setvar "cmdecho" 1)
(princ))
             
(defun _addlist ( key lst )
   (start_list key)
   (mapcar 'add_list lst)
   (end_list)
   lst
)
« Last Edit: March 29, 2016, 01:38:57 PM by amc.dicsac »
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #7 on: March 30, 2016, 09:40:32 AM »
Hi amc,

I'm sorry, but I cannot determine what is wrong with your program without all the information. It looks as though you changed the DCL file, but you have not posted the DCL, data files, or the complete code so I cannot run it to determine what is going on. Please at least post the DCL and data files.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #8 on: March 30, 2016, 12:03:51 PM »
This program is a library of blocks. Its main database files are .txt, mainly bada in reading these .txt
For example these text files have to be prefixed word 1-DWG-then we'd have something like 1-DWG-TOMACORRIENTES so they can be read in the lisp. Besides these files must be located in the following path "C: \ Program Files \ AutoCAD 2008" (in my case I use autocad 2008). Within these text files must be the name of the CAD file to insert blocks (if my block is called PEOPLE.dwg within my .txt file to write open PEOPLE), never remembering that the blocks have to be in the path supports autocad.

Can you tell me how I can get default values in the DCL is if I select an item from a list_box I want this same may be recorded each time the DCL start again in an open drawing.


Code: [Select]
INSERTA : dialog {
          label = "Biblioteca Eléctrica version 2.1 Aplicación 2015";
          initial_focus="bloqlist";
          : column {
            spacer_1;
          : boxed_row { label = " Listado de Bloques  "; alignment = centered;
  spacer_1;
           : list_box { key = "bloqlist"; allow_accept = true; fixed_width_font = false; width=30; height=12; value = "1";}
          : column {
           : button { key = "accept";label = " >> Inse&rtar";is_default = true;mnemonic = "e";width =14;}
           : button { key = "cancel";label = "&Cancelar"; is_default = false; is_cancel = true; mnemonic = "C"; width =14;}
           : row {
           : image_button { key = "save"; width = 5.5; fixed_width = true; fixed_height = true; aspect_ratio = 1;}
           : text  {alignment = centered; label = ">> Guardar bloque";}
                 }
           : row {
           : image_button { key = "load"; width = 5.5; fixed_width = true; fixed_height = true; aspect_ratio = 1 ;}
           : text  {alignment = centered; label = ">> Actualizar listado";}
                 }     
               spacer_1;
           }
   spacer_0;
         }
          spacer_1;
         : edit_box { key = "key_escala1"; fixed_width = false; is_enabled = true;}
         : popup_list { width =40; key = "infolist"; value = "1"; is_enabled = true ; }
          }
         spacer_1;
: row {
    width = 5;
    fixed_width = true;
    alignment = left;
:text  {label = "Copyright (c) Aplicación 2015"; is_bold = true;}
      }
 }

Code: [Select]
;; Set a Global variable for the Root path - this can be accessed anywhere.
(setq Path:2DAMobBasico "C:/Program Files/")
(setq *E1@ nil)
;;------------------------ GetDwgsMob ------------------------------------------------------------------
;; collects data from the specified directory  (setq folder (GetDwgsMob "AutoCAD 2008"))
;; return ---> "C:/Program Files/AutoCAD 2008/"
;;------------------------------------------------------------------------------------------------------
(defun GetDwgsMob (sParentMob / ListaMob DirMobTipo)
   (if (setq DirMobTipo (strcat Path:2DAMobBasico sParentMob))
      (setq ListaMob (vl-directory-files (strcat DirMobTipo "\\") "*.txt" 1)
            ListaMob (mapcar (function vl-filename-base) ListaMob))
   ) ;c.if
   ListaMob
) ;c.defun

;;--------------------------- saveVars1 -----------------------------------------
;;Establecemos la variable para la lista
;;Configurar una lista que contenga los elementos seleccionados (blkList1)
;;Guardar la configuración de lista (get_tile "bloqlist1") 
;;Ciclo a través de la lista de conseguir todos los elementos seleccionados
;;-------------------------------------------------------------------------------
(defun saveVars()
(setq *opcion2* (get_tile "infolist"))

   (setq blkList (list)) 
   (setq ignlist (get_tile "bloqlist"))
   (setq count 1)
   (while (setq fila (read ignlist))
      (setq blkList (append blkList (list (nth fila bloList))))
      (while
         (and
           (/= " " (substr ignlist count 1))
           (/= ""  (substr ignlist count 1)))
         (setq count (1+ count)))
      (setq ignlist (substr ignlist count))))

;;;---------------------------------------- read file "1-DWG-TOMACORRIENTES.txt" for default --------------------------
;; Altered by PKenewell to work for any file - 3-28-2016
(defun blokinf (file / blolist pa ruta)
   (if (and (findfile file) (setq ruta (open file "r")))
      (progn
         (read-line ruta)
         (while (setq pa (read-line ruta))
            (setq bloList (append bloList (list pa))))
         (close ruta)))
   bloList)

;;--------------------------- IMAGES -----------------------------------------
;;Configurar para inico de imagenes
;;-----------------------------------------------------------------------------


(defun c:E1 ( / key grr ip lastpt ent )
(setvar "cmdecho" 0)

 ;;-----------------------------------------------------------------------------
(if (not *E1@) (setq *E1@ (list nil "" "")))
(setq *opcion2* (nth 1 *E1@))
(setq *opcion1* (nth 2 *E1@))

;; Use your global variable and build the default path and filename.
(setq path (strcat Path:2DAMobBasico "AutoCAD 2008/"))
(setq f1 "1-DWG-TOMACORRIENTES")
   
;; Read the list of default text notes.
(setq bloList (blokinf (strcat path f1 ".txt")))

(setq dcl_id (load_dialog "C:/Program Files/AutoCAD 2008/Support/CADMASTER 2008/RUTINAS/INSERT-1.dcl"))
(if (not (new_dialog "INSERTA" dcl_id "" (cond (*screenpointE1*) ('(-1 -1)))))
(progn (prompt "\n**Se produjo ERROR contactese con el Administrado de la aplicacion**")
(exit)))

;; Gets the list of text files from the path
;; add version autocad to folder
(setq folder (GetDwgsMob "AutoCAD 2008"))

;;--------------------------- Agregando Folders al Popup_list ----------------------------------------
;; Adds the list of files into the popup_box.
;; Use the existing _ax:start function to create your list in bloqlist based on the file correcponding
;; to the item selected.
(_ax:start "infolist" folder)
(set_tile "infolist" *opcion2*)
(action_tile "infolist" "(saveVars)(_ax:start \"bloqlist\" (setq bloList (blokinf (strcat path (nth (atoi $value) folder) \".txt\"))))")

;; Adds the notes for the default
(_ax:start "bloqlist" bloList)

(set_tile "bloqlist" *opcion1*)
(action_tile "bloqlist" "(setq *opcion1* (get_tile \"bloqlist\"))(setq bloqxlist (nth (atoi $value) bloList)) (saveVars) ")


;;--------------------------- *AX:Escala1* ----------------------------------------
;; Variable para la escala del bloque a insertar por defecto "1.00"
;;---------------------------------------------------------------------------------
(if (= *AX:Escala1* nil) (set_tile "key_escala1" "1.00") (set_tile "key_escala1" (rtos *AX:Escala1* 2 2)))
(action_tile "key_escala1"  "(setq *AX:Escala1* (atof (get_tile \"key_escala1\")))")
(mode_tile "key_escala1" 2)

;;---------------------------------------------------------------------------------
(action_tile "cancel" "(setq *screenpointE1* (done_dialog 1))")
(action_tile "accept" "(saveVars)(setq *screenpointE1* (done_dialog 2))")
(action_tile "save" "(done_dialog 3)")
(action_tile "load" "(actualiza)")
(setq ddiag (start_dialog))
(unload_dialog dcl_id)
(setq *E1@ (list nil *opcion2* *opcion1*))
(if (= ddiag 1) (prompt "\nPrograma Cancelado..."))
(if (= ddiag 2) (insertax))
(if (= ddiag 3) (carga))
(if (= ddiag 4) (actualiza))
(setvar "cmdecho" 1)
(princ))
             
;;---------------------------------------------------------------------------------       
(defun insertax ( )
(setvar "cmdecho" 0)
(setq unitblock (getvar "insunits"))
(setvar "insunits" 4)
      (setq mxb (strcat "\nGirar [I]zquierda / [D]erecha\n" "Activar [O]snap, Punto [B]ase: "))

        (while ;;;
          (cond
            ;;----------------------------------------------
            ;; keyboard input
            ((eq 2 (car (setq grr (grread t 7 0))))
             (setq key (cadr grr))
             (cond
            ;;-------------------------------------------
               ((= key 13)
                (and ent (entdel ent))
                (princ "\n**Cancel**.")
                nil
               )
     
               ;;-------------------------------------------
               ((member (chr key) '("H" "h"))
                 (vl-cmdf "_.insert" (car pa) )
                (while (= (logand (getvar "cmdactive") 1) 1)
                  (command pause)
                 )
                   t
                   )         
               ((member (chr key) '("O" "o"))
                (vl-cmdf "_.move" ent "" "_non" lastpt)
               (while (= (logand (getvar "cmdactive") 1) 1) (command pause))
                   nil         
               )
               ((member (chr key) '("I" "i"))
                 (vl-cmdf "_.rotate" ent "" "_non" ip 90.0)
  t
               )
               ((member (chr key) '("D" "d"))
                 (vl-cmdf "_.rotate" ent "" "_non" ip -90.0)
t
               )
               ((member (chr key) '("B" "b"))
                 (vl-cmdf "_.move" ent "" (getpoint "\n>> Especifica punto base: ") ip)

              (princ mxb)
                 t       
               )
               ;;-------------------------------------------
               ((princ "\nTecla Invalidada.") (princ mxb))
             )
            )
            ;;=====================================================
            ((eq 3 (car grr)) ; point picked, make final star
             (setq ip (cadr grr)) 
     
             nil
            )
            ;;=====================================================
            ((eq 5 (car grr)) ; point from mouse, update object
             (setq ip (cadr grr))
             (if (null lastpt) ; first time through
               (progn             
                (setq lastpt ip)
            (princ mxb)
                 (vl-cmdf "_.insert" bloqxlist "_S" *AX:Escala1* "_R" 0.0 "_non" ip)
                 (setq ent (entlast))
               )
             )
              (if (> (distance ip lastpt) 0.00001)
 
              (vl-cmdf "_.move" ent "" "_non" lastpt "_non" ip)

                )
             (setq lastpt ip)

            )

          )   ; end cond
            ;;=====================================================
        )     ; while
        (redraw)
(command "explode" ent "")
(setvar "insunits" unitblock)
(setvar "cmdecho" 1)
(princ)
(princ)) 


(defun carga (/ Conjunto Ubicacion)
(vl-load-com)
(defun AUX_SelectSaveFile (Extension / Directorio EntNombre EntNuevoName)
(setq Nombre (vla-get-Effectivename(vlax-ename->vla-object Conjunto )))
;;;(setq Blockname (substr Nombre 11))
;;;(setq Prefijo "1-DEU-DWG ")
(setq EntNombre (strcase Nombre))
(setq EntNuevoName (vl-filename-base (substr (vl-filename-mktemp (strcat EntNombre Extension)) 1 3)))
(setq Liga (strcat EntNombre EntNuevoName))
(setq Liga1 (strcat "C:/Program Files/AutoCAD 2008/Support/CADMASTER 2008/BLOCKS/TOMACORRIENTES-1/" Liga))
(cond
((setq Directorio (getfiled "Guardar Bloque version 1.3 A.E.CAD 2014" Liga1 Extension 1))
(setq EntNombre (strcat (vl-filename-directory Directorio) "\\"))))
          Directorio )
(if (setq Conjunto (car (entsel "\nSelecciona bloque a guardar: "))
                  EntPto  (cdr (assoc 10 (entget Conjunto))))     
(cond
((setq Ubicacion (AUX_SelectSaveFile "dwg"))
(setvar "cmdecho" 0)
(command "_undo" "_begin")
(if (findfile Ubicacion)
(vl-cmdf "_.-WBLOCK" Ubicacion "_Y" "" EntPto Conjunto "")
(vl-cmdf "_.-WBLOCK" Ubicacion "" '(0 0 0) Conjunto "")
)
(startapp "explorer" (strcat "/n,/e," Ubicacion))
(command "_undo" "_end")
(setvar "cmdecho" 1))))
(alert "\nMueva el bloque al eje 0,0,0 ")
(princ))
(princ)

(defun actualiza (/ Conjunto Ubicacion)
(defun AUX_SelectSaveFile (Extension / Directorio EntNombre EntNuevoName)
(setq EntNombre "C:/Program Files/AutoCAD 2008/1-DWG-TOMACORRIENTES.txt")
(setq EntNuevoName (vl-filename-base (substr (vl-filename-mktemp (strcat EntNombre Extension)) 1 3)))
(cond
((setq Directorio (getfiled "Abrir Bloque version 1.3 A.E.CAD 2014" (strcat EntNombre EntNuevoName) Extension 4))
(setq EntNombre (strcat (vl-filename-directory Directorio) "\\"))))
      Directorio)
(cond
((setq Ubicacion (AUX_SelectSaveFile "txt"))
(setvar "cmdecho" 0)
(findfile Ubicacion)
(startapp "explorer" (strcat "/n,/e," Ubicacion))
(setvar "cmdecho" 1)))
(princ))
(princ)

(defun _ax:start ( key lst )
   (start_list key)
   (mapcar 'add_list lst)
   (end_list)
   lst
)
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #9 on: March 30, 2016, 05:24:39 PM »
Hi amc,

I did not experience the error you are getting. On what part of the code are you getting the error?

On reviewing your updated code I have a couple things I don't exactly understand what you trying to do:

1) Your (savevars) function doesn't make sense to me. It looks as though you are trying save multiple selected items in your "bloqlist" list box, but you do not have "multiple_select" set to "true", so the return is just going to be a single integer string. do you wish to select multiple blocks for insertion? Otherwise all you have to do to save the option is to set the global variable *opicon1* in the action tile for "bloqlist", then do a set_tile with the value of the globally saved *opcion1* variable at the next load. You are doing this now and it is working for me, but (savevars) appears to be useless.

2) In your (insertax) function, I think your grread loop is not necessary. If you are trying to pre-set the scale preview prior to final insertion - consider using the undocumented "PS" or "PX" and "PY" options of the INSERT command to pre-set the scale preview. Example:
Code: [Select]
(command "._insert" bloqxlist "_ps" *AX:Escala1*)This will pre-set the preview scale and still allow the user to change the scale and rotation on insertion.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #10 on: March 30, 2016, 05:51:36 PM »
Hi, how are you:
You are right the variable (save vars) it is useless and so eliminate the other hand
If you want the chosen option left for another session recorded in the same drawing, you only have to record it in a global variable; Example (setq * option * (get_tile "bloqlist")), and will return "0" "1" "2" ................... "15" etc, the instead of the option we have chosen, then to put a line to tell us (set_tile "bloqlist" * option *) will always remain the popup_list chosen that position.
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #11 on: March 30, 2016, 05:57:28 PM »
Another suggestion: You don't need to use "get_tile" within the "action_tile" call just set the $value return to your variable. Consider the following change:

Code: [Select]
(action_tile "bloqlist" "(setq bloqxlist (nth (atoi (setq *opcion1* $value)) bloList)) (saveVars) ")
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #12 on: March 31, 2016, 12:16:18 PM »
Hello such you think a solution would create global variables, I still is not clear how to create a global variable

Deputy complete files, the .dlc file is already incorporated in the .lsp
https://www.dropbox.com/sh/usm2frlax2dq9xy/AABjEAzOWbpLRgJlbN-En-fBa?dl=0

(The folder blocks must be tracked by the autocad)


and .txt files have to be in the next root "C: \ Program Files \ AutoCAD 2008"

« Last Edit: March 31, 2016, 01:15:25 PM by amc.dicsac »
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #13 on: March 31, 2016, 02:16:19 PM »
Hi amc,

Still not understanding what you are asking for. Global variables are any variable that is not localized in the code (i.e. listed in "(defun ( / <local variables here>)..."). Global variables will persist only in the current drawing session (if they are not set to nil).

Are you asking for a method to save the settings between drawing sessions? If that is what you are asking - then there are a couple ways to do it, depending on what you want.

1) write the values to a text file on exit from the program, then read them back in and set to variables when running the program again. This is what I recommend for you.

2) Save the values to the registry using the "vl-registry..." functions. I would only attempt this if you are very familiar with how the registry works!
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #14 on: March 31, 2016, 02:35:12 PM »
P.S. After looking at your code in dropbox, I believe I know what your error is coming from:

Code: [Select]
(if (null *opcion2*) (setq *opcion2* "C:\\Program Files\\AutoCAD 2008\\1-DWG-ALUMBRADO.txt"))
(if (null *opcion1*) (setq *opcion1* "BRAQUETE"))

You are trying to save the path and name of the file, rather than just the List Box return from $value or get_tile, which does not return the name of the list item, only a string with the integer value of the selected item (i.e. "0", "1", "2", etc.)

You have to save and set the integer of the selected item using "set_tile" - not the name of the listed value. This should instead be:

Code: [Select]
(if (null *opcion2*) (setq *opcion2* "0")) ;; If not saved - reset to the first item in the list box.
(if (null *opcion1*) (setq *opcion1* "0")) ;; If not saved - reset to the first item in the list box.

If you want to save the name of the actual names, for something other than setting the selected item in the list box. You need to save the list item to the variable in the manner you are saving the variable "bloqxlist":
Code: [Select]
"(setq bloqxlist (nth (atoi $value) bloList))" In the action tile, this saves the actual item name listed in the box. However you cannot use this value to set the selected item again you would have to determine the index number on the list and convert it to a string, then use that value to do the set_tile call. This is not necessary - all you have to do is save the integer string returned by $value or get_tile.

"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #15 on: March 31, 2016, 03:38:09 PM »
Attached is a modified version of your code. I have corrected the issues and removed unneeded code.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #16 on: March 31, 2016, 03:40:59 PM »
It would be interesting find out more about (VL-REGISTRY) USED AS THE ADDITION quisera NEVER KNOW ABOUT THE FUNCTION (vlax-ldata-put)
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: help fast!!! Popup_list and List_box
« Reply #17 on: April 05, 2016, 07:17:06 PM »
Hi, how are you:

After much achieved what I wanted to thank you for your support, now I have another problem eh added a toggle and boot me this error; error: bad argument type:
fixnump: nil

Could you help me please

https://www.dropbox.com/sh/nzeyisvcy0pgn95/AADEUejcdwFIu7ChiRh_yxFra?dl=0
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #18 on: April 08, 2016, 12:22:15 PM »
Hi amc.dicsac,

I think your main problem in the code it that your attempting to do the (unload_dialog) and delete the dcl file while you are still in your "(while" loop. You need to move those outside the while loop. You can leave the dialog loaded if you are re-entering it, and just call (new_dialog) again to re-display it. See the following snippet of your code:

Code - Auto/Visual Lisp: [Select]
  1. (setq ddiag (start_dialog))
  2. ;; Remove this code and move outside of while loop
  3. ;; (unload_dialog dch)
  4. ;; (if (and dcl (findfile dcl))
  5. ;;      (vl-file-delete dcl))
  6. ;;     (if (< 0 dch)
  7. ;;         (unload_dialog dch)
  8. ;;     )
  9.     (princ)
  10. (if (= ddiag 1) (prompt "\nPrograma Cancelado..."))
  11. (if (= ddiag 2) (insertax))
  12. ;;(if (= ddiag 3) (open_dwg))
  13.   ) ;; fin de while del toggle
  14.  
  15. ;; Put unload DCL code here
  16. ;; ====================
  17. (if (and dcl (findfile dcl))
  18.      (vl-file-delete dcl))
  19.     (if (< 0 dch)
  20.         (unload_dialog dch)
  21.     )
  22. ;; ===================
  23. (setvar "cmdecho" 1)
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #19 on: April 08, 2016, 12:30:33 PM »
P.S. I think you would get allot more help here if you give proper credit in your comments to the author of code snippets you borrow from other people here such as Lee Mac (the "NumInc:GetSavePath" function for example).
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: help fast!!! Popup_list and List_box
« Reply #20 on: April 08, 2016, 01:18:26 PM »
Attached is another rewrite of your program, just correcting the parts that are broken. I have not touched your code that is still in development. Please see my comments in your code to see what I have done.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt