See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Dynamic Block Selection

  1. #1
    Login to Give a bone
    0

    Default Dynamic Block Selection

    Forum Members,

    How would I write an AutoLISP command to get a selection set of all dynamic blocks who's name starts with "MyBlock"? Note the drawing has blocks of "MyBlock1", "MyBlock2", etc. etc. I would like to building a selection set that would contain all of these.

    Christmas May

  2. #2
    Member
    Join Date
    2015-12
    Posts
    48
    Login to Give a bone
    1

    Default Re: Dynamic Block Selection

    As they are dynamic blocks, any block references (inserts) where a dynamic property has be activated will be anonymous i.e. the block name will be something like *U????, and it is not possible to filter using the blocks effective name (real name). IMHO it is best to select all blocks and then filter out only those blocks you require whilst processing as non dynamic blocks with attributes can also be anonymous.

    Basic concept is

    Code:
    (setq blockfilter "MYBLOCK*"); this filter set for any block whose effective name starts with MYBLOCK (upper case as wcmatch is case sensitive)
    (setq ss (ssget "_X" '((0 . "INSERT"))))
    (cond (ss
            (repeat (setq cnt (sslength ss))
              (setq obj (vlax-ename->vla-object (setq ent (ssname ss (setq cnt (1- cnt))))))
              (cond ( (wcmatch (strcase (valx-get obj 'effectivename)) blockfilter) ;filter out only those blocks that match the filter
                      ;option 1 do your stuff here, or convert to list for further processing
                    )
                    ;option 2 to remove non matching blocks from selection set result in a selection set (ss) of matching blocks
                    ;(t
                    ;  (ssdel ent ss)
                    ;)
              )
            )
          )
    )
    You have two options

    option 1 process only those blocks that match. Best as you only iterate the selection set once
    option 2 remove non matching blocks from selection set. You will then need to process the resultant selection set again

  3. #3
    Login to Give a bone
    0

    Default Re: Dynamic Block Selection

    Assuming "Option 1" what line( s ) of code would be required to change the blocks color?
    What line( s ) of code would be required to delete the blocks.

  4. #4
    Member
    Join Date
    2015-12
    Posts
    48
    Login to Give a bone
    1

    Default Re: Dynamic Block Selection

    Quote Originally Posted by Christmas050873782348 View Post
    Assuming "Option 1" what line( s ) of code would be required to change the blocks color?
    What line( s ) of code would be required to delete the blocks.
    Option 1

    COLOR - That would depend on the type of color ACI/RGB/Color Book. You could pop up the color dialog to pick a color. The return from this can be used to entmod the entity directly as it returns all the required dotted pairs. Otherwise ACI (integer color) is
    straight forward single line of code RBG/Color book would require a truecolor object or some manipulation to convert to a truecolor (Lee Mac's color conversion routines).

    examples if "int_val" is the integer (ACI) or calculated integer value (RGB) then

    ACI (integer 0 => 256) 0 is byblock 256 is bylayer 1 is red etc (vlax-put obj 'color "int_val")
    RGB (vlax-put-property obj 'truecolor "int_val")

    I did some of these 6-12 Months ago, I'll see if I can find the code


    DELETE- replace "do your stuff here" with (vla-delete obj). This will delete all blocks matching the "MYBLOCK*" filter

Similar Threads

  1. Replies: 8
    Last Post: 2018-11-19, 06:05 AM
  2. Replies: 2
    Last Post: 2013-06-04, 02:59 AM
  3. Replies: 1
    Last Post: 2012-02-16, 06:58 PM
  4. Dynamic Block in a Dynamic Block
    By jjanis in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2008-06-06, 01:33 PM
  5. Dynamic Block within a dynamic block?
    By pbrumberg in forum Dynamic Blocks - Technical
    Replies: 13
    Last Post: 2006-02-16, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •