Help with dcl button, block dwg

Help with dcl button, block dwg

Anonymous
Not applicable
2,422 Views
17 Replies
Message 1 of 18

Help with dcl button, block dwg

Anonymous
Not applicable
insert block.pngHello, I have created a DCL but I still can not create the lisp because 
I get tangled with the button opcoon and the list,
I need the buttons to work and insert the blocks according to the selection and also
those from the list called others, each key must to send to a defun like this:
(defun rb1 ( / Nme FName1) (vl-load-com)
  (prompt "\nInsert BLOCK 01.")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "BLOCK01" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "zoom" "e" "")
  (prompt "\n")
  (princ)
)
The dcl code that I am still developing is this:
test1 : dialog {				
      label = "Insercion de bloques DWG" ;		
       : row {					
       :boxed_column {			
       label = "Block 01" ;				
        : button {			
     	  key = "C1" ;				
     	  label = "TYPE 1" ;			
     	  value = "0" ;	
        }					
     	: button {			
     	  key = "C2" ;				
     	  label = "TYPE 2" ;	
     	  value = "0" ;			
     	}					
     	: button {			
     	  key = "C3" ;				
     	  label = "TYPE 3" ;	
     	  value = "0" ;	
     	  }					
     	: button {			
     	  key = "C4" ;				
     	  label = "TYPE 4" ;	
     	  value = "0" ;	
     	}			
     	: button {	
     	  key = "C5" ;		
     	  label = "TYPE 5" ;	
     	  value = "0" ;	
     	  }					
     	: button {			
     	  key = "C6" ;				
     	  label = "TYPE 6" ;	
     	  value = "0" ;	
     	  }				
     	: button {		
     	  key = "C7" ;			
     	  label = "TYPE 7" ;	
     	  value = "0" ;	
     	  }					
     	: button {			
     	  key = "C8" ;				
     	  label = "TYPE 8" ;	
     	  value = "0" ;	
     	}					
        }					
         : row {				
         :boxed_column {			
         label = "Block 02" ;			
          : button {			
     	    key = "C9" ;			
     	    label = "TYPE 1" ;	
     	    value = "0" ;	
          }					
     	  : button {			
     	    key = "C10" ;			
     	    label = "TYPE 2" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C11" ;			
     	    label = "TYPE 3" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C12" ;			
     	    label = "TYPE 4" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C13" ;			
     	    label = "TYPE 5" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C14" ;			
     	    label = "TYPE 6" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C15" ;			
     	    label = "TYPE 7" ;
     	    value = "0" ;		
     	  }					
     	  : button {			
     	    key = "C16" ;			
     	    label = "TYPE 8" ;
     	    value = "0" ;		
     	  }					
         }
        }					
        : boxed_column {			
        label = "Other";			
     	: popup_list {				
        key = "selections";			
        value = "0" ;				
        }					
       }					
       }					
     ok_cancel ;				
     }		
I hope you can help me, thank you very much.

 

0 Likes
Accepted solutions (1)
2,423 Views
17 Replies
Replies (17)
Message 2 of 18

dbroad
Mentor
Mentor

This tutorial series might be of some help to you:

https://www.afralisp.net/dialog-control-language/

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 18

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

here is my version:

note the changes i made to dcl...a button tile has no value attribute

what is the purpose of "selections" tile? it looks like it duplicates the typeX buttons - no?

 

in lisp why the zoom is need?

 

enjoy

moshe

 

 

 

 

dcl_settings : default_dcl_settings { audit_level = 0; }

test1 : dialog {				
 label = "Insercion de bloques DWG" ;		
 : row {					
   : boxed_column {			
     label = "Block 01" ;				
     : button {			
       key = "C01" ;				
       label = "TYPE 1" ;			
    // value = "0" ;	
     }					
     : button {			
       key = "C02" ;				
       label = "TYPE 2" ;	
   //  value = "0" ;			
     }					
     : button {			
       key = "C03" ;				
       label = "TYPE 3" ;	
   //  value = "0" ;	
     }					
     : button {			
       key = "C04" ;				
       label = "TYPE 4" ;	
   //  value = "0" ;	
     }			
     : button {	
       key = "C05" ;		
       label = "TYPE 5" ;	
   //  value = "0" ;	
     }					
     : button {			
       key = "C06" ;				
       label = "TYPE 6" ;	
   //  value = "0" ;	
     }				
     : button {		
       key = "C07" ;			
       label = "TYPE 7" ;	
   //  value = "0" ;	
     }					
     : button {			
       key = "C08" ;				
       label = "TYPE 8" ;	
   //  value = "0" ;	
     }					
    }
    
    : row {				
     : boxed_column {			
       label = "Block 02" ;			
       : button {			
         key = "C09" ;			
         label = "TYPE 1" ;	
     //  value = "0" ;	
       }					
       : button {			
         key = "C10" ;			
         label = "TYPE 2" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C11" ;			
         label = "TYPE 3" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C12" ;			
         label = "TYPE 4" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C13" ;			
         label = "TYPE 5" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C14" ;			
         label = "TYPE 6" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C15" ;			
         label = "TYPE 7" ;
     //  value = "0" ;		
       }					
       : button {			
         key = "C16" ;			
         label = "TYPE 8" ;
     //  value = "0" ;		
       }					
      }
    }
     
    : boxed_column {			
       label = "Other";			
       : popup_list {				
         key = "selections";			
     //  value = "0" ;
       }					
    }					
  }
    
  ok_cancel ;				
 }		

 

(defun c:test1 (/ format_number init_tiles ctrl_insert install_action_tiles insert_block ; local functions
		  BLOCK-ITEMS dcl_id what_next bname)

 (defun format_number (n)
  (cond
   ((< n 10)
    (strcat "0" (itoa n))
   ) 
   ( t
    (itoa n)
   )
  ); cond  
 ); format_number

  
 (defun init_tiles (/ i)
  (start_list "selections" )
   
  (setq i 0) 
  (repeat BLOCK-ITEMS
   (add_list (strcat "BLK"  (format_number (setq i (1+ i)))))
  )

  (end_list)
 ); init_tiles

  
 ; call back 
 (defun ctrl_insert (key)
  (setq bname (strcat "BLOCK" (substr key 2)))
  (done_dialog 2)
 ); ctrl_insert_block
  

 (defun install_action_tiles (/ i)
  (setq i 0)
  (repeat BLOCK-ITEMS
   (action_tile (strcat "C" (format_number (setq i (1+ i)))) "(ctrl_insert $key)")
  )
 ); install_action_tiles


 (defun insert_block ()
  (prompt (strcat "\nInsert " bname))
   
  (if (or
        (tblsearch "block" bname)
        (findfile bname)
      )
   (progn 
    (command "._insert" bname "0,0" 1 1 0)
    (command "._zoom" "e")
   ); progn
   (prompt (strcat "\nblock " bname " is not found."))
  ); if
 ); insert_block

  
 ; here start command 
 (setvar "cmdecho" 1)
 (command "._undo" "begin")
  
 (setvar "insunits" 4)
 (setq BLOCK-ITEMS 16) ; global
  
 ; here start c:cbt
 (if (setq dcl_id (load_dialog "test1"))
  (progn

   (setq what_next 2)
       
   (while (> what_next 1)
    (if (not (new_dialog "test1" dcl_id "" '(-1 -1))); open dialog at center
     (exit)
    )
     
    (init_tiles)
    (install_action_tiles)
     
    (setq what_next (start_dialog)); start dialog

    (cond
     ((= what_next 0)
      ; Cancel - do some cleaning here, if there is a need
      nil
     )
     ((= what_next 1)
      ; OK - do some cleaning here, , if there is a need
      nil
     )
     ((= what_next 2)
      (insert_block)
     ); case
    ); cond
   ); while

   (unload_dialog dcl_id)
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)

 

0 Likes
Message 4 of 18

Anonymous
Not applicable

thank you very much Moshe-A, there is much that I do not understand yet, my purpose is to run several defun, each button goes to a defun that has already loaded a routine like the one I put at the beginning something like that, even the list to insert another type of blocks, I appreciate your help, thank you very much for the interest in helping me, only if you could adjust it for several defun one per button and for each of the list would be great, once again thank you very much for the help, waiting for your answer, greetings.

0 Likes
Message 5 of 18

Moshe-A
Mentor
Mentor

@Anonymous hi,

 

what you do not understand? (i here to explain)

 

the (install_action_tiles) function creates (action_tile) for each button (still not for the popup_list)

so when any button is pushed the (ctrl_insert) is fired and accept an argument 'key' which holds the the key of the buttons. if your goal is the same (e.g insert a block) then there is not need to define a separate function for each button. another type of block? from autocad point of view there is one type of block ... the difference could be the graphics, attributes, block name but it still one type. 

 

to understand better what are the types can you post the blocks?

 

Moshe

 

0 Likes
Message 6 of 18

Sea-Haven
Mentor
Mentor

One of the old fashioned things in acad is if using a pull down menu you can have image tiles of your blocks behind each image is what you want to do with it insert and attributes or not.

 

 

0 Likes
Message 7 of 18

Moshe-A
Mentor
Mentor

@Anonymous 

 

to help you understand what's is going, i expanded some parts and disable the previous (but did not test it)

look at (insert_block) function, you can handle each 'block type' separately thus you do not need a separate functions.

 

enjoy

moshe

 

 

(defun c:test1 (/ format_number init_tiles ctrl_insert install_action_tiles insert_block ; local functions
		  BLOCK-ITEMS dcl_id what_next bname)

 (defun format_number (n)
  (cond
   ((< n 10)
    (strcat "0" (itoa n))
   ) 
   ( t
    (itoa n)
   )
  ); cond  
 ); format_number

  
 (defun init_tiles (/ i)
  (start_list "selections" )
   
;|  (setq i 0) 
  (repeat BLOCK-ITEMS
   (add_list (strcat "BLK"  (format_number (setq i (1+ i)))))
  ) |;

  (foreach list-item (list "BLK01" "BLK02" "BLK03" "BLK04" "BLK05" "BLK06" "BLK07" "BLK08"
		           "BLK09" "BLK10" "BLK11" "BLK12" "BLK13" "BLK14" "BLK15" "BLK16")
   (add_list list-item)
  )
   
  (end_list)
 ); init_tiles

  
 ; call back 
 (defun ctrl_insert (key)
  (setq bname (strcat "BLOCK" (substr key 2)))
  (done_dialog 2)
 ); ctrl_insert_block
  

 (defun install_action_tiles (/ i)
;|  (setq i 0)
  (repeat BLOCK-ITEMS
   (action_tile (strcat "C" (format_number (setq i (1+ i)))) "(ctrl_insert $key)")
  ) |;

  (foreach key-button (list "C01" "C02" "C03" "C04" "C05" "C06" "C07" "C08"
			 "C09" "C10" "C11" "C12" "C13" "C14" "C15" "C16")
   (action_tile key-button "(ctrl_insert $key)")
  )
 ); install_action_tiles


 (defun insert_block ()
  (prompt (strcat "\nInsert " bname))
   
  (if (or
        (tblsearch "block" bname)
        (findfile bname)
      )
  ;| (progn 
    (command "._insert" bname "0,0" 1 1 0)
    (command "._zoom" "e")
   ); progn |;
   (cond 
    ((eq bname "BLOCK01")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK02")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK03")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK04")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK05")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK06")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK07")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK08")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK09")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK10")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK12")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ) 
    ((eq bname "BLOCK13")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK14")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK15")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
    ((eq bname "BLOCK16")
     (command "._insert" bname "0,0" 1 1 0)
     (command "._zoom" "e")
    ); case 
   ); cond
   (prompt (strcat "\nblock " bname " is not found."))
  ); if
 ); insert_block

  
 ; here start command 
 (setvar "cmdecho" 1)
 (command "._undo" "begin")
  
 (setvar "insunits" 4)
 (setq BLOCK-ITEMS 16) ; global
  
 ; here start c:cbt
 (if (setq dcl_id (load_dialog "test1"))
  (progn

   (setq what_next 2)
       
   (while (> what_next 1)
    (if (not (new_dialog "test1" dcl_id "" '(-1 -1))); open dialog at center
     (exit)
    )
     
    (init_tiles)
    (install_action_tiles)
     
    (setq what_next (start_dialog)); start dialog

    (cond
     ((= what_next 0)
      ; Cancel - do some cleaning here, if there is a need
      nil
     )
     ((= what_next 1)
      ; OK - do some cleaning here, , if there is a need
      nil
     )
     ((= what_next 2)
      (insert_block)
     ); case
    ); cond
   ); while

   (unload_dialog dcl_id)
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)

 

0 Likes
Message 8 of 18

Moshe-A
Mentor
Mentor

@Anonymous ,

 

please mark this as your solution

 

thank you

moshe

 

0 Likes
Message 9 of 18

Anonymous
Not applicable
Hello, this is how the routine would work, what I need is to complete with the POPUP_LIST that works executing a defun like in the buttons, it could help me in this part that until there no longer I can, I add the DWG to see how it works with the buttons.
dcl_settings : default_dcl_settings { audit_level = 0; }

Test2 : dialog {				
 label = "Insertion of DWG blocks" ;		
 : row {					
   : boxed_column {			
     label = "Block 01" ;				
     : button {			
       key = "C1" ;				
       label = "TYPE 1" ;			
     }					
     : button {			
       key = "C2" ;				
       label = "TYPE 2" ;	
     }					
     : button {			
       key = "C3" ;				
       label = "TYPE 3" ;	
     }					
     : button {			
       key = "C4" ;				
       label = "TYPE 4" ;	
     }			
     : button {	
       key = "C5" ;		
       label = "TYPE 5" ;	
     }					
     : button {			
       key = "C6" ;				
       label = "TYPE 6" ;	
     }				
     : button {		
       key = "C7" ;			
       label = "TYPE 7" ;	
     }					
     : button {			
       key = "C8" ;				
       label = "TYPE 8" ;	
     }					
    }
    
    : row {				
     : boxed_column {			
       label = "Block 02" ;			
       : button {			
         key = "C09" ;			
         label = "TYPE 1" ;	
       }					
       : button {			
         key = "C10" ;			
         label = "TYPE 2" ;
       }					
       : button {			
         key = "C11" ;			
         label = "TYPE 3" ;
       }					
       : button {			
         key = "C12" ;			
         label = "TYPE 4" ;
       }					
       : button {			
         key = "C13" ;			
         label = "TYPE 5" ;
       }					
       : button {			
         key = "C14" ;			
         label = "TYPE 6" ;
       }					
       : button {			
         key = "C15" ;			
         label = "TYPE 7" ;
       }					
       : button {			
         key = "C16" ;			
         label = "TYPE 8" ;
       }					
      }
    }
     
    : boxed_column {			
       label = "Other";			
       : popup_list {				
         key = "selections";			
       }					
    }					
  }
    
  ok_cancel ;				
 }		
(defun c:test2 (/)
   (setq dcl_id (load_dialog "Test2.dcl"))
   (if (not (new_dialog "Test2" dcl_id))
      (progn (alert " Error in loading the dialog (Test2.dcl) ")
             (exit)
      )
   )
   (action_tile
      "C1"
      "(setq dwg1 t)(done_dialog)"
   )
   (action_tile
      "C2"
      "(setq dwg2 t)(done_dialog)"
   )
   (action_tile "cancel" "(done_dialog)")
   (start_dialog)
   (unload_dialog dcl_id)
   (cond
      (dwg1 (DD1))
      (dwg2 (DD2))
   )
   (princ)
)

(defun DD1 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block01 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block01" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD2 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block02 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block02" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

 https://cp.sync.com/file/654869280/view/doc

0 Likes
Message 10 of 18

Moshe-A
Mentor
Mentor

@Anonymous ,

 

here is my remarks:

 

1) the popup_list must be initialize with items, as you present it here it's empty and you will have noting to select see my code for (init_tiles) function.

2) (done_dialog) function may accept an integer argument (a status) which is return by (start_dialog) function. you are calling (done_dialog) without passing any status and by default it will return 0 which means Cancel

3)  there are rules on how dialog should be handled and it look like you are not following my example.

4) you insist to do it as you think how it should be work but it is wrong.

5) i do not see any difference between (DD1) and (DD2)? block name is not a difference cause it can be pass to  function as an argument and the function should react to it accordingly - see (insert_block) function in my code.

6) to react to list item (coming from popup_list) add this code line before (start_dialog)

 

(action_tile "selections" "(ctrl_popup_list $value)") ; first you need to populate the list

 

the $value is a string, the selected index item (it's zero base) the first item is 0.

and define a callback function (ctrl_popup_list) something like this:

 

(defun ctrl_popup_list (value)

 (setq index (atoi value)) 

 

  (cond

   ((= index 0)

     ; this is the first list item selected

   )

   ((= index 1)

     ; this is the second list item selected

   )

   ((= index 2)

     ; this is the third list item selected

   )

   ((= index 4)

     ; ..... and on and on

   )

  ); cond

)

  

0 Likes
Message 11 of 18

Anonymous
Not applicable
Well, the DD2 is an example to insert another block, the part of the buttons is ready, the detail is that I want to add more blocks in the popup list, or if there is another way to visualize more blocks that add over time without needing create more buttons, or there is some other more practical option, sorry for using your time, thank you very much
0 Likes
Message 12 of 18

Moshe-A
Mentor
Mentor

@Anonymous 

 

popup_list tile (or list tile) is the best way to handle list of items. if in future you want to add more items you will need to modify the code in dcl or/and lsp depending on how you populate the popup_list like i did in (init_tiles) or use list attribute in dcl (see documentation)

 

i fully understands what DD2 is and do, remember that we are talking about function and function can accept arguments so having one function can cover a lot of states (you called it block type). by passing the function block name (plus others arguments needed) the function will handle the different states at one spot. lets say for a moment that i accept your method and you defined functions (DDx) for each block - OK?!  after a while you decide to change functionality, set a layer, or scale isn't it more easy to do all that in one function then in many?  Smiley LOL

 

moshe

 

 

0 Likes
Message 13 of 18

Anonymous
Not applicable
Hello Moshe-A, sorry but I've been trying to finish with the project, 
now I've been able to run the list box and run the defun
I want but now I do not know how to integrate them with the buttons,
that each button works like a defun,
when you chop the button or in the list is executed a defun that is in the routine,
I will not insist more friend, if it is no longer peude, normal,
anyway thank you so much I have understood many things that I had not seen,
waiting for your quick answer , regards.
this is the code that I've been compiling
(DEFUN MK_LIST(l68j& / l680@ l68@& l68Q&)
(SETQ l680@ 1)(WHILE(SETQ l68@&(READ l68j&))
(SETQ l68Q&(CONS(NTH l68@& l68%)l68Q&))
(WHILE(AND(/=" "(SUBSTR l68j& l680@ 1))(/=""(SUBSTR l68j& l680@ 1)))
(SETQ l680@(1+ l680@)))(SETQ l68j&(SUBSTR l68j& l680@)))(REVERSE l68Q&))

(DEFUN c:test2 (/ l680 ER SELECT l68% l68?j)
(SETQ l680 *ERROR* *ERROR* l68j)
(>=(SETQ l68?j(LOAD_DIALOG"Test2.dcl"))0)
(NEW_DIALOG"Test2"l68?j)
(SETQ SELECT"0"l68%
	(LIST"  "" DWG1
		"" DWG2
		"" DWG3
		"" DWG4"
	)
)
(SET_TILE"title"" Insert DWG")
(SET_TILE"list_box""0")(ACTION_TILE"list_box""(setq SELECT $value)")
(ACTION_TILE"accept""(done_dialog 2)")
(ACTION_TILE"cancel""(setq SELECT nil)
(done_dialog 0)")(START_LIST"list_box")
(MAPCAR(quote ADD_LIST)l68%)(END_LIST)(START_DIALOG)(UNLOAD_DIALOG l68?j)
(IF SELECT(PROGN(SETQ ER(MK_LIST SELECT)ER(READ(CAR ER)))
(COND
((= ER(quote DWG1))(DD1))
((= ER(quote DWG2))(DD2))
((= ER(quote DWG3))(DD3))
((= ER(quote DWG4))(DD4)))))
(SETQ *ERROR* l680)(PRINC))

(defun DD1 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block01 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block01" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD2 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block02 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block02" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD3 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block03 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block03" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD4 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block04 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block04" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)
dcl_settings : default_dcl_settings { audit_level = 0; }
Test2 : dialog {				
 label = "Insertion of DWG blocks" ;		
 : row {					
   : boxed_column {			
     label = "Block 01" ;				
     : button {			
       key = "C1" ;				
       label = "TYPE 1" ;			
     }					
     : button {			
       key = "C2" ;				
       label = "TYPE 2" ;	
     }					
     : button {			
       key = "C3" ;				
       label = "TYPE 3" ;	
     }					
     : button {			
       key = "C4" ;				
       label = "TYPE 4" ;	
     }			
     : button {	
       key = "C5" ;		
       label = "TYPE 5" ;	
     }					
     : button {			
       key = "C6" ;				
       label = "TYPE 6" ;	
     }				
     : button {		
       key = "C7" ;			
       label = "TYPE 7" ;	
     }					
     : button {			
       key = "C8" ;				
       label = "TYPE 8" ;	
     }					
    }
    
    : row {				
     : boxed_column {			
       label = "Block 02" ;			
       : button {			
         key = "C09" ;			
         label = "TYPE 1" ;	
       }					
       : button {			
         key = "C10" ;			
         label = "TYPE 2" ;
       }					
       : button {			
         key = "C11" ;			
         label = "TYPE 3" ;
       }					
       : button {			
         key = "C12" ;			
         label = "TYPE 4" ;
       }					
       : button {			
         key = "C13" ;			
         label = "TYPE 5" ;
       }					
       : button {			
         key = "C14" ;			
         label = "TYPE 6" ;
       }					
       : button {			
         key = "C15" ;			
         label = "TYPE 7" ;
       }					
       : button {			
         key = "C16" ;			
         label = "TYPE 8" ;
       }					
      }
    }
    : boxed_column {			
      label = "&Size";			
       : list_box {			
         key = "list_box";		
         height = 15.00;
         fixed_height = true;
         width = 8.00;
         fixed_width = true;
       }					
    }					
  }
  ok_cancel ;				
 }		
0 Likes
Message 14 of 18

Anonymous
Not applicable

Hi Moshe-A, sorry once again, this is the last time I bothered about this issue, I have already solved how I want the LIST BOX to work, now the problem is how I integrate the buttons and that they work like the list boxes run a defun at the time of chopping the button, this is the code of how the list box works, I hope you can help me one more time, thanks, waiting for your response, greetings.

 

(DEFUN MK_LIST(l68j& / l680@ l68@& l68Q&)
(SETQ l680@ 1)(WHILE(SETQ l68@&(READ l68j&))
(SETQ l68Q&(CONS(NTH l68@& l68%)l68Q&))
(WHILE(AND(/=" "(SUBSTR l68j& l680@ 1))(/=""(SUBSTR l68j& l680@ 1)))
(SETQ l680@(1+ l680@)))(SETQ l68j&(SUBSTR l68j& l680@)))(REVERSE l68Q&))

(DEFUN c:test2 (/ l680 ER SELECT l68% l68?j)
(SETQ l680 *ERROR* *ERROR* l68j)
(>=(SETQ l68?j(LOAD_DIALOG"Test2.dcl"))0)
(NEW_DIALOG"Test2"l68?j)
(SETQ SELECT"0"l68%
	(LIST"  "" DWG1
		"" DWG2
		"" DWG3
		"" DWG4"
	)
)
(SET_TILE"title"" Insert DWG")
(SET_TILE"list_box""0")(ACTION_TILE"list_box""(setq SELECT $value)")
(ACTION_TILE"accept""(done_dialog 2)")
(ACTION_TILE"cancel""(setq SELECT nil)
(done_dialog 0)")(START_LIST"list_box")
(MAPCAR(quote ADD_LIST)l68%)(END_LIST)(START_DIALOG)(UNLOAD_DIALOG l68?j)
(IF SELECT(PROGN(SETQ ER(MK_LIST SELECT)ER(READ(CAR ER)))
(COND
((= ER(quote DWG1))(DD1))
((= ER(quote DWG2))(DD2))
((= ER(quote DWG3))(DD3))
((= ER(quote DWG4))(DD4)))))
(SETQ *ERROR* l680)(PRINC))

(defun DD1 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block01 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block01" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD2 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block02 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block02" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD3 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block03 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block03" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD4 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block04 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block04" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)
dcl_settings : default_dcl_settings { audit_level = 0; }
Test2 : dialog {				
 label = "Insertion of DWG blocks" ;		
 : row {					
   : boxed_column {			
     label = "Block 01" ;				
     : button {			
       key = "C1" ;				
       label = "TYPE 1" ;			
     }					
     : button {			
       key = "C2" ;				
       label = "TYPE 2" ;	
     }					
     : button {			
       key = "C3" ;				
       label = "TYPE 3" ;	
     }					
     : button {			
       key = "C4" ;				
       label = "TYPE 4" ;	
     }			
     : button {	
       key = "C5" ;		
       label = "TYPE 5" ;	
     }					
     : button {			
       key = "C6" ;				
       label = "TYPE 6" ;	
     }				
     : button {		
       key = "C7" ;			
       label = "TYPE 7" ;	
     }					
     : button {			
       key = "C8" ;				
       label = "TYPE 8" ;	
     }					
    }
    
    : row {				
     : boxed_column {			
       label = "Block 02" ;			
       : button {			
         key = "C09" ;			
         label = "TYPE 1" ;	
       }					
       : button {			
         key = "C10" ;			
         label = "TYPE 2" ;
       }					
       : button {			
         key = "C11" ;			
         label = "TYPE 3" ;
       }					
       : button {			
         key = "C12" ;			
         label = "TYPE 4" ;
       }					
       : button {			
         key = "C13" ;			
         label = "TYPE 5" ;
       }					
       : button {			
         key = "C14" ;			
         label = "TYPE 6" ;
       }					
       : button {			
         key = "C15" ;			
         label = "TYPE 7" ;
       }					
       : button {			
         key = "C16" ;			
         label = "TYPE 8" ;
       }					
      }
    }
    : boxed_column {			
      label = "&Size";			
       : list_box {			
         key = "list_box";		
         height = 15.00;
         fixed_height = true;
         width = 8.00;
         fixed_width = true;
       }					
    }					
  }
  ok_cancel ;				
 }		

Regarding the routine with the buttons, I thought to integrate it with this, but I do not know how.

(defun c:test2 (/)
   (setq dcl_id (load_dialog "Test2.dcl"))
   (if (not (new_dialog "Test2" dcl_id))
      (progn (alert " Error in loading the dialog (Test2.dcl) ")
             (exit)
      )
   )
   (action_tile
      "C1"
      "(setq dwg1 t)(done_dialog)"
   )
   (action_tile
      "C2"
      "(setq dwg2 t)(done_dialog)"
   )
   (action_tile "cancel" "(done_dialog)")
   (start_dialog)
   (unload_dialog dcl_id)
   (cond
      (dwg1 (DD1))
      (dwg2 (DD2))
   )
   (princ)
)

(defun DD1 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block01 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block01" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)

(defun DD2 ( / Nme FName1) (vl-load-com)
  (prompt "\nInserting block Block02 in your file")
  (setvar "cmdecho" 1)
  (setvar "insunits" 4)
  (setq FName1 (strcat "Block02" ".dwg"))
  (vl-cmdf "_.-insert" FName1 "0,0" "" "" "")
  (command "explode" "last")
  (command "zoom" "e" "")
  (command "layout" "t" FName1 "A01")
  (command "layout" "t" FName1 "A02")
  (command "layout" "t" FName1 "A03")
  (command "layout" "d" "layout1")
  (command "layout" "d" "layout2")
  (prompt "\n")
  (princ)
)
0 Likes
Message 15 of 18

Moshe-A
Mentor
Mentor
Accepted solution

@Anonymous  hi,

 

sorry i did not reply, it seems that i did not got the emails on this thread.

i review your work very seriously as you can see i reorder the code so i can start understand what is going on.

all the functions and variables in your code were uppercase, it is so noisy, very crowded so i convert it to lowercase and reorganize it in a structural programming so i can start read it.

 

see my remarks inside the code

 

 

; do not use meaningless variable cause it is hard to follow them and debug. all variables here
; looks the same. this function does not work???


(defun mk_list (l68j& / l680@ l68@& l68Q&) (setq l680@ 1) (while (setq l68@& (read l68j&)) ; instead of using (read) use (atoi) (setq l68Q& (cons (nth l68@& l68%) l68Q&)) (while (and (/= " " (substr l68j& l680@ 1)) (/= "" (substr l68j& l680@ 1)) ) (setq l680@ (1+ l680@)) ) (setq l68j& (substr l68j& l680@)) ); while (reverse l68Q&) ) (defun c:test2 (/ l680 er select l68% l68?j) ; again meaningless variable (setq l680 *error* *error* l68j) ; 168j should be error handler function? where is exist? (>= (setq l68?j (load_dialog "test2.dcl")) 0) ; although this code line works the
; arithmetic '>=' does noting, redundant! (new_dialog "test2" l68?j) ; if (new_dialog) fails it return nil and your program
; breaks. in message #3 i gave you an example how
; this should be done, why don't you accept my example? (setq select "0" ; the next code lines causes the dialog to break l68% (list "" DWG1 ; cause DWG1-DWG4 are unknown variable and not set "" DWG2 "" DWG3 "" DWG4 ) ) (set_tile "title" "Insert DWG") ; there is not key by the name "title" in dcl, this line does noting.
(set_tile "list_box" "0") ; although this line works, list_box is a preserved name for
; list_box tile and it's confusing to use it as key name specific
; for list_box (action_tile "list_box" "(setq select $value)") ; this is ok (action_tile "accept" "(done_dialog 2)") ; this line is wrong it should be (done_dialog 1) (action_tile "cancel" "(setq select nil) (done_dialog 0)") ; this is ok (start_list "list_box") ; this is ok (mapcar (quote add_list) l68%) ; this more common to be (mapcar 'add_list 168%)
; but the list is not constructed well (end_list) ; this is ok (start_dialog) ; this is ok (unload_dialog l68?j) ; this is ok
(if select (progn (setq er (mk_list select) ; (mk_list) function is meant to buld a list of item for the list_box er (read (car er))) ; what's is doing here? (cond ((= er (quote DWG1)) ; (quote DWG1) does what? (DD1) ) ((= er (quote DWG2)) (DD2) ) ((= er (quote DWG3)) (DD3) ) ((= er (quote DWG4)) (DD4) ) ); cond ); progn ); if (setq *error* l680) (princ) ); c:test2

 

 

on message #3 and on message #7 i gave you a beautiful examples on how a dialog program should be handle. why aren't you following my examples? if you do not understand what i did, then tell me what you don't understand. going the wrong way does not helps you.

 

moshe

 

 

 

0 Likes
Message 16 of 18

Anonymous
Not applicable

Thanks Moshe-A. Sorry to bring up an old post. This works almost perfectly for what I need but do I need to rename all my blocks to “BLOCK01 BLOCK02” and so on? Or is there a way to use existing names?

0 Likes
Message 17 of 18

Sea-Haven
Mentor
Mentor

If you want selection by image have a look at my post its so easy no dcl's just uses a menu and autocads built in dcl's. All blocks your user name. Can help some shortcuts to make menu. Think about tool palettes as well.

0 Likes
Message 18 of 18

Anonymous
Not applicable

Thanks. Tool pallets won't work for me. Using autocad with mechanical desktop and insert block doesn't work the same as autocad. Menus may work. Going to look at that today. Have to use the MDT equivalent. A command called AMCOPYIN to insert MDT parts.

0 Likes