Results 1 to 3 of 3

Thread: Only allow user to select certain blocks.

  1. #1
    Member
    Join Date
    2015-11
    Posts
    2
    Login to Give a bone
    0

    Default Only allow user to select certain blocks.

    Hiya all
    First time posting here so go easy on me.

    I have numerous blocks that all contain a nested block, plus an attribute. So 2 items inside a block.
    Block and nested block names are different, but the attribute has the same name "MX_ATT" which is in many blocks.

    Im looking for a way for the user to only be able to select blocks that contain the "MX_ATT" attribute and put the main block into a selection set.

    Anyone know a way ?

    Cheers

    Steve.

  2. #2
    Member
    Join Date
    2005-01
    Posts
    42
    Login to Give a bone
    0

    Default Re: Only allow user to select certain blocks.

    Hi Steve, welcome to the forum

    Try this...
    The routine will print out the number of objects in the selection set based on your attribute name. I wasn't sure if the name of your attribute is the tag string or the text string so the program will look for both. I'm guessing that your blocks are in model space, but if they are in different layout tabs too the code can be modified to work with that. You can remove the (princ) line and add you code to modify the selection set.

    Code:
    (defun c:test ( / ss)
    (vl-load-com)
    
    ; CREATE AN EMPTY SELECTION SET
    (setq ss (ssadd))
    
    ; ITERATE THROUGH THE OBJECTS IN MODEL SPACE
    (vlax-for blks (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
     (if (and
          (= (vla-get-ObjectName blks) "AcDbBlockReference")
          (vlax-property-available-p blks 'Hasattributes)
         )
      (foreach att (append (vlax-invoke blks 'GetAttributes)(vlax-invoke blks 'GetConstantAttributes))
       (if (or
            (= (vla-get-TagString att) "MX_ATT")
            (= (vla-get-TextString att) "MX_ATT")
           )
        (ssadd (vlax-vla-object->ename blks) ss)	; <<< ADD OBJECTS TO THE SELECTION SET
       )
      )
     )
    )
    
    ; PUT YOUR CODE HERE...
    
    (princ (strcat "\nNumber of objects in the selection set: " (itoa (sslength ss))))
    )

  3. #3
    Member
    Join Date
    2015-11
    Posts
    2
    Login to Give a bone
    0

    Default Re: Only allow user to select certain blocks.

    Thank you so much for the reply but Im not sure I made the question make sense lol.

    Imagine having 2 Blocks on screen. RANDOM_BLOCK_NAME and MX_ATT. (They can contain anything, Attrib, lines etc as long as they are blocks).
    Create a NEW block called ANOTHER_RANDOM_BLOCK_NAME which contains RANDOM_BLOCK_NAME and MX_ATT.

    Assuming you only know the block name "MX_ATT" and none of the other Block names, I need a way to select all blocks on the page that contain the "MX_ATT" block.

    So you could have 100+ Blocks on the page but only say 50 contain the MX_ATT block. How do I single out the blocks that contain MX_ATT block.

    Any further help is appreciated.

Similar Threads

  1. 2014: Is there a way to prompt the user, upon opening a project, to select a workset?
    By rbelfiore337841 in forum Revit MEP - General
    Replies: 1
    Last Post: 2014-02-06, 12:24 AM
  2. Select Blocks when using BLOCKREPLACE
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2008-10-11, 08:48 PM
  3. Select all Blocks between two Polylines
    By ccowgill in forum AutoLISP
    Replies: 11
    Last Post: 2007-05-29, 05:36 PM
  4. Select blocks by name and insertion point?
    By keelay711 in forum AutoLISP
    Replies: 17
    Last Post: 2006-10-17, 12:03 PM
  5. Select all Blocks then delete them
    By nickeshaffer in forum AutoCAD General
    Replies: 2
    Last Post: 2006-02-24, 02:36 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
  •