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.
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;}
}
}
;; 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
)