+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    May 2013
    Posts
    6

    Default Select blocks by name without selecting any groups associated with them

    Registered forum members do not see this ad.

    Hello all,

    I need to select two blocks and delete them automatically, their names are: FA_DEVICE_INIT_BASE_STANDARD and FA_DEVICE_INIT_SMOKE_DUCT_HOUSING

    I usually use the quick select tool to delete these because they're always grouped with the actual device block. For example, we would have a smoke detector block and then it would have a "base" block underneath of it grouped with it so when we did exports they would be on the counts. When using quick select, if I say select block by name "FA_DEVICE_INIT_BASE_STANDARD" it actually only selects that block and not the "FA_DEVICE_INIT_SMOKE" block that is grouped with it. Is there any way to replicate what quick select does with autolisp? Here is what I have so far, it currently selects the blocks but it also selects any associated groups and deletes them too:

    Code:
    (defun c:AutoBlkRepPrepare ()
    (if (setq ss1 (ssget "_x" '((0 . "INSERT")(2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))))
    (progn
    (command "_.erase" ss1)
    )
    (alert "No preparation necessary!")
    )
    (princ)
    )
    Any help with this is greatly appreciated! Thanks!

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,815

    Default

    You will need to check somehow if its a group, something I dont use very often. An idea may be get all the groups check for your blocks in group make a list of all objects, ungroup delete blocks then regroup remainder. Then run what you have to get rid of individuals. Really need a sample dwg.

    Some one other than me may have some GROUP code that would be usefull.
    A man who never made mistakes never made anything

  3. #3
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    555

    Default

    You can temporarily change the PICKSTYLE.
    BricsCAD 16

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,815

    Default

    Cool Roy_043 tried it out.
    A man who never made mistakes never made anything

  5. #5
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    May 2013
    Posts
    6

    Default

    Quote Originally Posted by Roy_043 View Post
    You can temporarily change the PICKSTYLE.
    Thanks Roy, I added a pickstyle change to the code and it works now.

    The only thing that happens is it says "; error: Function cancelled". It doesn't affect the process and all and everything still works, but it is just annoying that it won't print the text I want it to. Here is the updated code:
    Code:
    (defun c:AutoBlkRepPrepare ()
    (command "pickstyle" "0")
    (if (setq ss1 (ssget "_x" '((0 . "INSERT")(2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))))
    (progn
    (command "_.erase" ss1)
    )
    (alert "No preparation necessary!")
    )
    (command "pickstyle" "1")
    (princ "Preparation complete!")
    (princ)
    )
    Anyone have any suggestions on how to get rid of that error? Thanks!

  6. #6
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    528

    Default

    Try this .. removed command calls.
    Code:
    (defun c:foo (/ ps s)			;<- Localize variables
      (setq ps (getvar 'pickstyle))
      (setvar 'pickstyle 0)
      (if (setq s (ssget "_x" '((0 . "INSERT"))))
        (mapcar 'entdel (mapcar 'cadr (ssnamex s)))
        (alert "No preparation necessary!")
      )
      (setvar 'pickstyle ps)
      (princ)
    )
    Last edited by ronjonp; 9th Nov 2017 at 08:10 pm.

  7. #7
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    May 2013
    Posts
    6

    Default

    Quote Originally Posted by ronjonp View Post
    Try this .. removed command calls.
    Code:
    (defun c:autoblkrepprepare (/ ps s)    ;<- Localize variables
      (setq ps (getvar 'pickstyle))
      (setvar 'pickstyle 0)
      (if (setq
        s (ssget
            "_x"
            '((0 . "INSERT") (2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))
          )
          )
        (mapcar 'entdel (mapcar 'cadr (ssnamex s)))
        (alert "No preparation necessary!")
      )
      (setvar 'pickstyle ps)
      (princ)
    )
    Ron, this is awesome, works like a charm! Now to look up and learn what all you did so I can make my code not so basic. Thank you very much!

  8. #8
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    528

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by ecustis View Post
    Ron, this is awesome, works like a charm! Now to look up and learn what all you did so I can make my code not so basic. Thank you very much!
    Glad to help

Similar Threads

  1. Change multiple groups to blocks
    By vimcruz in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 2nd Jul 2014, 05:10 am
  2. Replies: 6
    Last Post: 3rd Oct 2012, 11:15 pm
  3. Selecting Blocks
    By samp17 in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 12th Oct 2010, 06:22 pm
  4. Speed selecting different ribbon groups
    By rocneasta in forum AutoCAD General
    Replies: 0
    Last Post: 30th Mar 2010, 10:23 am
  5. Problem de-selecting groups
    By Jomi in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 29th Jan 2008, 12:57 pm

Bookmarks

Posting Permissions

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