View Full Version : Blocks
vipin_nair
2008-02-27, 10:45 AM
Hi All,
Does Anyone Knows how to insert any predefined block or door in drawing through a dialogue box . I have a routine that inserts door in drawing but only one block through one routine. Is it possible that user can select any block from a list of blocks. How can I change my routine to work like this. Thank you.
rkmcswain
2008-02-27, 02:45 PM
Yes, it's possible, but what you are asking is not trivial. Are you wanting to write this on your own, or are you looking for something pre-built?
vipin_nair
2008-02-28, 08:08 AM
Hi,
It will not make any difference if it is a prebuilt or not. Thank you.
irneb
2008-02-28, 01:31 PM
If you want to do this yourself, you'll have to look at the DCL in help. Probably have a listbox:BlockSelect : dialog {
label = "Select block to insert";
: list_box {
key = "list";
height = 10;
width = 40;
}
ok_cancel;
}
Then you'll require a function in Lisp which loads this dialog, then populates the list with the block names, then returns the block name selected if OK clicked:(defun ChooseBlk (lst / dcl result)
;; Function to get selected name from listbox
(defun OKClicked (/ )
(setq result (get_tile "list"));Get the index of the listbox selection
;; Check if user has selected
(if (or (not result) (= result ""))
(done_dialog 0);Return a 0 to show that nothing selected
(progn
(setq result (nth (atoi result) lst));Get the name from the selected index of the list
(done_dialog 1);Return a 1 to show that OK was clicked
)
)
)
;; Load DCL file
(setq dcl (load_dialog "blksel.dcl"))
;; Start a new dialog
(new_dialog "BlockSelect" dcl)
;; Setup the listbox as per lst passed to this function
(start_list "list" 3);Start editing the listbox from scratch
(mapcar 'add_list lst) ;Pass each name in lst to add to the list box
(end_list);Close the listbox for editing
;; Set the actions for the buttons
(action_tile "accept" "(OKClicked)")
(action_tile "cancel" "(done_dialog 0)")
;; Start the dialog and check if user canceled / not selected
(if (= 1 (start_dialog))
result;If OK return the selected name
nil;If cancel or none selected return nil
)
)
You can then use this name in the rest of your code to know which block to insert. You simply have a line like: (setq blkname (chooseblk '("TEst1" "Test2" "Test3")))
(if blkname
(progn
;.... perform the insert
)
(princ "Canceled by user")
)
Obviously the list would be different for your scenario.
Terry Cadd
2008-03-01, 02:02 AM
Here’s a Block Library utility that I’ve written. You are welcome to use it and test it out.
It’s written in AutoLISP with dialogs and is a utility for managing blocks by storing blocks and block slides images in Block Libraries. The block slide images can be quickly viewed in the Block Libraries before inserting them into a drawing.
http://web2.airmail.net/terrycad/LISP/Blk_Lib.lsp
http://web2.airmail.net/terrycad/LISP/Blk_Lib.dcl
http://web2.airmail.net/terrycad/LISP/Blk_Lib.doc
GetIcon.lsp is required for Block Library.
http://web2.airmail.net/terrycad/LISP/GetIcon.lsp
'gile'
2008-03-01, 06:22 PM
Hi,
Here's a 'single file dialog box' wich allows the uer to specify a valid block name by:
- selecting on screen
- browsing
- inputing
- choosing in a popup list
;;; Getblock (gile) 03/11/07
;;; Returns a valid block name inputed or choosen by the user
;;;
;;; Argument : the dialog box label (string) or nil (default : "Choose a block")
;;;
;;; Using examples:
;;; (getblock "Specify the block to be changed")
;;; (getblock nil)
(defun getblock (titre / bloc n lst tmp file what_next dcl_id nom)
(while (setq bloc (tblnext "BLOCK" (not bloc)))
(setq lst (cons (cdr (assoc 2 bloc)) lst)
)
)
(setq lst (acad_strlsort
(vl-remove-if
(function (lambda (n) (= (substr n 1 1) "*")))
lst
)
)
tmp (vl-filename-mktemp "Tmp.dcl")
file (open tmp "w")
)
(write-line
(strcat
"getblock:dialog{label="
(cond (titre (vl-prin1-to-string titre))
("\"Choose a block\"")
)
";initial_focus=\"bl\";:boxed_column{
:row{:text{label=\"Select\";alignment=left;}
:button{label=\">>\";key=\"sel\";alignment=right;fixed_width=true;}}
spacer;
:column{:button{label=\"Browse...\";key=\"wbl\";alignment=right;fixed_width=true;}}
:column{:text{label=\"Name :\";alignment=left;}}
:edit_box{key=\"tp\";edit_width=25;}
:popup_list{key=\"bl\";edit_width=25;}spacer;}
spacer;
ok_cancel;}"
)
file
)
(close file)
(setq dcl_id (load_dialog tmp))
(setq what_next 2)
(while (>= what_next 2)
(if (not (new_dialog "getblock" dcl_id))
(exit)
)
(start_list "bl")
(mapcar 'add_list lst)
(end_list)
(if (setq n (vl-position
(strcase (getvar "INSNAME"))
(mapcar 'strcase lst)
)
)
(setq nom (nth n lst))
(setq nom (car lst)
n 0
)
)
(set_tile "bl" (itoa n))
(action_tile "sel" "(done_dialog 5)")
(action_tile "bl" "(setq nom (nth (atoi $value) lst))")
(action_tile "wbl" "(done_dialog 3)")
(action_tile "tp" "(setq nom $value) (done_dialog 4)")
(action_tile
"accept"
"(setq nom (nth (atoi (get_tile \"bl\")) lst)) (done_dialog 1)"
)
(setq what_next (start_dialog))
(cond
((= what_next 3)
(if (setq nom (getfiled "Select a file" "" "dwg" 0))
(setq what_next 1)
(setq what_next 2)
)
)
((= what_next 4)
(cond
((not (read nom))
(setq what_next 2)
)
((tblsearch "BLOCK" nom)
(setq what_next 1)
)
((findfile (setq nom (strcat nom ".dwg")))
(setq what_next 1)
)
(T
(alert (strcat "The file \"" nom "\" cannot be found."))
(setq nom nil
what_next 2
)
)
)
)
((= what_next 5)
(if (and (setq ent (car (entsel)))
(= "INSERT" (cdr (assoc 0 (entget ent))))
)
(setq nom (cdr (assoc 2 (entget ent)))
what_next 1
)
(setq what_next 2)
)
)
((= what_next 0)
(setq nom nil)
)
)
)
(unload_dialog dcl_id)
(vl-file-delete tmp)
nom
)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.