Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selection Set by block name

59 REPLIES 59
Reply
Message 1 of 60
spm5
9699 Views, 59 Replies

Selection Set by block name

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.

59 REPLIES 59
Message 21 of 60
_Tharwat
in reply to: pbejse


@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 Smiley Happy

 

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

Message 22 of 60
miquan
in reply to: pbejse

Dear pbejse,

 

Thanks you very much. It works perfectly.

 

Miquan

Message 23 of 60
miquan
in reply to: _Tharwat

Dear Tharwat,

 

Now it works fine.

Thank you very much.

 

Miquan

Message 24 of 60
pbejse
in reply to: miquan


@miquan wrote:

Dear pbejse,

 

Thanks you very much. It works perfectly.

 

Miquan


You are welcome.. Happy to help.

 

And welcome to the forum Miquan Smiley Happy

Message 25 of 60
_Tharwat
in reply to: miquan


@miquan wrote:

Dear Tharwat,

 

Now it works fine.

Thank you very much.

 

Miquan


Excellent , You're welcome . Smiley Happy

Message 26 of 60
dortega4226
in reply to: spm5

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
David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 27 of 60
_Tharwat
in reply to: dortega4226


@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.

Message 28 of 60
dortega4226
in reply to: _Tharwat

Tharwat,
I am familiar with said command, however, if it were possible to incorporate it within the command you've created as an option it would be most beneficial to me.
I'm using two routines together, the one you've created and another I requested through AUGI, CadTutor & The Swamp, here is the code I received on The Swamp (http://www.theswamp.org/index.php?topic=47538.msg525377#msg525377).
If I could incorporate your selection routine, along with the 'LAYER' option I requested it would help me run the 'PutURL' routine. What I'm doing is a bit confusing, however, i'll try and explain it anyways...

I insert blocks into a drawing and place them on several layers.
Each layer has been given a layer description providing me with all of my research spanning several months
I typical use the Quick Select tool to select each block on a specific layer, however, with 300 plus layers it's quite time consuming.
Your routine 'GetBlocks' works perfectly to select any block without a menu, GetBlocks is faster and easier than the Quick Select tool.
Lastly, using all that have been selected by GetBlocks, I run the PutURL routine to apply all of the Layer Descriptions to the Hyperlink Name for visibility when hovering over the block. Reference the link above for a better understanding of that scenario.

Again, anything you have to offer will be greatly appreciated. As it stands, GetBlocks works for me, I meerly wanted to add the layer option to make it more versitile like the Quick Select tool.
David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 29 of 60
_Tharwat
in reply to: dortega4226

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)
)

 

Message 30 of 60
dortega4226
in reply to: _Tharwat

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.

David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 31 of 60
_Tharwat
in reply to: dortega4226

You are very welcome David , I am really happy that you liked the idea and the program itself . Smiley Happy

 

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

Message 32 of 60
~Opie
in reply to: _Tharwat

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.
Message 33 of 60
_Tharwat
in reply to: ~Opie


@~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 ?

Message 34 of 60
dortega4226
in reply to: _Tharwat

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.

David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 35 of 60
_Tharwat
in reply to: dortega4226

 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

Message 36 of 60
dortega4226
in reply to: _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...

David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 37 of 60
_Tharwat
in reply to: dortega4226


@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 . Smiley Happy

 

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 ?

Message 38 of 60
dortega4226
in reply to: _Tharwat

Tharwat,

Sorry for the confusion, I guess it comes from not designing something like this before.Smiley Wink

 

For the layers...

  • 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

I hope this is more clear and concise, I actually tried to answer you this time.Smiley LOL

 

David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 39 of 60
dortega4226
in reply to: dortega4226


@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...


David J. Ortega
____________________________________________________________________________________
AutoCAD 2015 | AutoCAD Architecture 2015 | Revit Architecture 2015 | NavisWorks Manage 2015
Autodesk | TheSwamp | CadTutor | AUGI
Message 40 of 60
_Tharwat
in reply to: dortega4226

Hope this would meet your needs Smiley Wink

 

(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)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost