Hello,
I am trying to select all blocks of a certian name. I am using the following:
(setq ss1bk (ssget "_X" (list (cons 2 blkname))))
My issue is that this will not select any dynamic or attribute blocks that are not at the default insert state.
Does anyone know how to select all of a block by name including reguardless of current state?
Thanks.
@pbejse wrote:@ tharwat.
Perhaps it would be better to include (cons 2 (strcat bname ",`*U*"))) on your ssget filter to reduce the number of blocks for iteration on "global mode" and "Window" mode.
Better yet combine the two options like i had in mine.
Cheers Tharwat
Correct pbejse
I tried to modify the code but it gave me a message that I ran put of time to rectify the post . so it is okay for now .
Thank you for the correction mate .
Cheers
@dortega4226 wrote:
Tharwat,
Your code works beautifully for me also, thank you. Is there a possibility of adding a layer selection option as well? Currently it asks the user to 'Enter/Select' a block, I would like to have another option added after the 'Enter/Select' option, All on specific 'Layer/Name' then proceed to 'Window/Global'.
This option, 'Layer/Name' would use the selected block and either find all on specific Layer or with a specific Name.
Is this possible to have added?
David
Hi David .
I am really happy that you liked my routine and thank you for the Kudos .
Are you familiar with command call select Similar ?
If that doesn't work as you looking for , then I would write another routine for you .
Regards.
Here it goes , try it and let me know .
(defun c:GetBlocks (/ *error* D f id run go sel layers blocks s lst ss i sn bn go BlockTable LayerTable) ;; Author: Tharwat Al Shoufi ;; ;; GetBlocks Program ;; ;; Date : 04. August. 2014 ;; (defun *error* (msg) (if (and D (setq D (findfile D))) (vl-file-delete D) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ msg) (princ (strcat "\n ** Error : " msg " **")) ) ) ;; ;; (defun BlockTable (/ i a l nm) (while (setq i (tblnext "BLOCK" (not i))) (if (not (wcmatch (setq nm (cdr (assoc 2 i))) "`**")) (setq l (cons nm l)) ) ) (setq l (acad_strlsort l)) ) ;; ;; (defun LayerTable (/ i a nm l) (while (setq i (tblnext "LAYER" (not i))) (if (not (wcmatch (setq nm (cdr (assoc 2 i))) "*|*")) (setq l (cons (cdr (assoc 2 i)) l)) ) ) (setq l (acad_strlsort l)) ) ;; ;; (if (ssget "_X" '((0 . "INSERT"))) (setq run t) (alert "No blocks found in this drawing !!") ) (if (and run (setq D (vl-filename-mktemp nil nil ".dcl")) (setq f (open D "w"))) (progn (write-line (strcat "test : dialog { label = \"Highlight Blocks\"; width = 36;" "spacer;" ": boxed_column { label = \"Options\";" ": button { label = \"Select >>\"; key = \"sbk\";}" "spacer;" ": popup_list { label = \"Block:\"; key = \"bl\"; width = 32;}" "spacer;" ": popup_list { label = \"Layer:\"; key = \"lay\"; width = 32;}}" "spacer;" ": boxed_radio_column { label = \"Selection Way:\";" ": radio_button { label = \"Global\"; key = \"g\"; value = \"1\";}" ": radio_button { label = \"Window\";key = \"w\";}}" "spacer;" ": boxed_row { label = \"Action\"; fixed_width = true; alignment = centered;" ": button { label = \"Okay\"; key = \"oki\"; is_default = true; height = 1.75; width = 12;}" ": button { label = \"Exit\"; key = \"esc\"; is_cancel = true; height = 1.75; width = 12;}}}" ) f ) (close f) ) ) (if (or (not D) (not (new_dialog "test" (setq id (load_dialog D))))) (progn (if (> id 0) (unload_dialog id) ) (if (and D (setq D (findfile D))) (vl-file-delete D) ) ) (progn (setq layers (append (list "-- On Any Layer --") (LayerTable)) blocks (BlockTable) ) (mapcar '(lambda (k l) (start_list k) (mapcar 'add_list l) (end_list)) (list "bl" "lay") (list blocks layers) ) (if (and *GetBlockName* (tblsearch "BLOCK" *GetBlockName*)) (set_tile "bl" (itoa (vl-position *GetBlockName* blocks))) ) (action_tile "sbk" "(setq sel t)(done_dialog)") (action_tile "oki" "(setq lst (mapcar 'get_tile (list \"bl\" \"lay\" \"g\" \"w\")) bn (nth (atoi (car lst)) blocks) go t *GetBlockName* nil) (done_dialog)" ) (action_tile "esc" "(setq go nil) (done_dialog)") (start_dialog) (unload_dialog id) (vl-file-delete D) ) ) (if (and sel (princ "\n Pick Block :") (setq s (ssget "_+.:S:E" '((0 . "INSERT"))))) (progn (setq *GetBlockName* (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))) (c:GetBlocks) ) ) (if (and bn go (setq ss (ssget (if (eq (caddr lst) "1") "_X" "_:L" ) (list '(0 . "INSERT") (cons 8 (if (eq (cadr lst) "0") "*" (nth (atoi (cadr lst)) layers) ) ) (cons 2 (strcat "`*U*," bn)) ) ) ) ) (progn (repeat (setq i (sslength ss)) (if (not (eq (vla-get-effectivename (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))))) bn)) (ssdel sn ss) ) ) (sssetfirst nil ss) ) ) (princ) )
Tharwat,
This routine is amazing, far beond what I expected... Thank you very much.
The only thing I can think to alter is the Layer option would only show the layers found within the block selected.
Example:
Getblocks
Select a block on a layer named CW-30-UC, which is a Casework block
All Casework Blocks found would report their Layers in the Layers popup_list (see image)
-->Note: All other layers in the drawing would not be listed to condense the layer list
Again, I appreciate your help with this. If you were not half a world away I would shake your hand with great gratitude.
You are very welcome David , I am really happy that you liked the idea and the program itself .
Now let me explain what I got from your new request to modify the routine accordingly :
You want to select the fore-said block and when the routine bring you back to its dialog , you want to list the layers that all similar blocks with the same name to be listed in the popup_list ?
If so , what to do after you have that list of layers in the popup_list ?
I need to know what you want to do with the layers after all .
The more you are clear on your aim of the routine, the best routine and codes would be written for you .
Regards
@~Opie wrote:
I maybe speaking out of term, but I took it as the layer list drop down needs to be updated to only include layers that are included within the selected block.
Yeah , I have thought of that too , and the question still hanging , what to do with these layers that would be listed in the drop_list after that ?
Tharwat,
~Opie is correct. I simply want to minimize the layer list to the layers applied to the selected block.
Example:
If I selected the Casework block, all Casework blocks would be found and the layer drop_list would only show the layers applied to those Casework blocks.
All right , so you want to select a block with select button first then the routine should find all similar blocks with the same name then return back to the dialog with the layers that all the found blocks lay on .
The question is , what to do after that ? it seems that you are not in need of the selection modes (Global , Window) anymore .
I need to get things clear in mind before going to modify the routine so many times . that 's it .
Regards
Tharwat
Tharwat,
I guess that is a correct assumption. I would no longer need the global or window selection modes for the layer selection. If it makes it more challanging, they can be omitted, but if it's all the same they can stay. I can't think of a need for them now, but that doesn't mean I won't in the furture...
@dortega4226 wrote:Tharwat,
I guess that is a correct assumption. I would no longer need the global or window selection modes for the layer selection. If it makes it more challanging, they can be omitted, but if it's all the same they can stay. I can't think of a need for them now, but that doesn't mean I won't in the furture...
It is all up to you and I have no problem to keep them if you may be in need of them in the future if you intend to use the routine the same way that imagined and designed the routine accordingly .
You still did reply to my question about layers , and what to do after returning back to dialog when a user select a block and have the layers in that drop list ?
Tharwat,
Sorry for the confusion, I guess it comes from not designing something like this before.
For the layers...
I hope this is more clear and concise, I actually tried to answer you this time.
@dortega4226 wrote:
Run 'GetBlocks' routine:
- Once I have selected a block
- Received a filtered layer lists based on what is being used by selected blocks
- I would make a choice of using the --On Any Layer-- feature or pick a Specific Layer being used
- -->If I opt to use the --On Any Layer-- feature, then all blocks would be selected based on the name
- -->If I opt to use a Specific Layer (CW-30-UC B3) feature, then all blocks using the layer I selected would be found (similar to Quick Select tool)
- After this process I would add hyperlinks to the item based on documentation
- Finally I would run the PutURL routine to add the Layer Description to the Hyperlink name
Can anyone help me with this task, creating a filtered layer list from the list of blocks selected using the routine found in the following link:http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Selection-Set-by-block-name/m-p/51928...I'm dead in the water trying to find a solution to this...
Hope this would meet your needs
(defun c:GetBlocks (/ *error* D f id run go sel blocks s lst ss i layer sn bn go BlockTable ) ;; Author: Tharwat Al Shoufi ;; ;; GetBlocks Program ;; ;; Date : 04. August. 2014 ;; (defun *error* (msg) (if (and D (setq D (findfile D))) (vl-file-delete D) ) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*") (princ msg) (princ (strcat "\n ** Error : " msg " **")) ) ) ;; ;; (defun BlockTable (/ i a l nm) (while (setq i (tblnext "BLOCK" (not i))) (if (not (wcmatch (setq nm (cdr (assoc 2 i))) "`**")) (setq l (cons nm l)) ) ) (setq l (acad_strlsort l)) ) ;; ;; (if (ssget "_X" '((0 . "INSERT"))) (setq run t) (alert "No blocks found in this drawing !!") ) (if (and run (setq D (vl-filename-mktemp nil nil ".dcl")) (setq f (open D "w")) ) (progn (write-line (strcat "test : dialog { label = \"Highlight Blocks\"; width = 36;" "spacer;" ": boxed_column { label = \"Options\";" ": button { label = \"Select >>\"; key = \"sbk\";}" "spacer;" ": popup_list { label = \"Block:\"; key = \"bl\"; width = 32;}" "spacer;" ": popup_list { label = \"Layer:\"; key = \"lay\"; width = 32;}}" "spacer;" ": boxed_radio_column { label = \"Selection Way:\";" ": radio_button { label = \"Global\"; key = \"g\"; value = \"1\";}" ": radio_button { label = \"Window\";key = \"w\";}}" "spacer;" ": boxed_row { label = \"Action\"; fixed_width = true; alignment = centered;" ": button { label = \"Okay\"; key = \"oki\"; is_default = true; height = 1.75; width = 12;}" ": button { label = \"Exit\"; key = \"esc\"; is_cancel = true; height = 1.75; width = 12;}}}" ) f ) (close f) ) ) (if (or (not D) (not (new_dialog "test" (setq id (load_dialog D)))) ) (progn (if (> id 0) (unload_dialog id) ) (if (and D (setq D (findfile D))) (vl-file-delete D) ) ) (progn (setq blocks (BlockTable)) (start_list "bl") (mapcar 'add_list blocks) (end_list) (if *layers* (progn (start_list "lay") (mapcar 'add_list (acad_strlsort *layers*)) (end_list) ) ) (if (and *GetBlockName* (tblsearch "BLOCK" *GetBlockName*)) (set_tile "bl" (itoa (vl-position *GetBlockName* blocks))) ) (action_tile "sbk" "(setq sel t *layers* nil)(done_dialog)") (action_tile "oki" "(setq lst (mapcar 'get_tile (list \"bl\" \"lay\" \"g\" \"w\")) bn (nth (atoi (car lst)) blocks) go t *GetBlockName* nil *layers* nil) (done_dialog)" ) (action_tile "esc" "(setq go nil) (done_dialog)") (start_dialog) (unload_dialog id) (vl-file-delete D) ) ) (if (and sel (princ "\n Pick Block :") (setq s (ssget "_+.:S:E" '((0 . "INSERT")))) (setq *GetBlockName* (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)) ) ) (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 *GetBlockName*))) ) ) (progn (repeat (setq i (sslength ss)) (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))) ) ) *layers* ) ) (setq *layers* (cons layer *layers*)) ) ) (c:GetBlocks) ) ) (if (and bn go (setq ss (ssget (if (eq (caddr lst) "1") "_X" "_:L" ) (list '(0 . "INSERT") (cons 8 (if (eq (cadr lst) "0") "*" (nth (atoi (cadr lst)) layers) ) ) (cons 2 (strcat "`*U*," bn)) ) ) ) ) (progn (repeat (setq i (sslength ss)) (if (not (eq (vla-get-effectivename (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))) ) ) bn ) ) (ssdel sn ss) ) ) (sssetfirst nil ss) ) ) (princ) )