+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Junior Member
    Computer Details
    Razoo's Computer Details
    Operating System:
    XP
    Monitor:
    Samsung SyncMaster 245a
    Using
    AutoCAD 2008
    Join Date
    Nov 2009
    Location
    Berkshire, UK
    Posts
    21

    Default Checking if a Block can be Purged

    Registered forum members do not see this ad.

    Hi, this is my first post, having only just discovered this forum.

    I use AutoCAD 2008 at work and AutoCAD 14 at home.

    Can anyone tell me how to establish whether a block (in AutoCAD14) is available for purging using AutoLisp?

    I use 'tblsearch' to check that the block exists in the drawing database, and I use 'ssget' to establish if the block is inserted directly into the drawing.

    (if (and (tblsearch "BLOCK" bname)
    (not (ssget "X" (cons '(0 . "INSERT") (list (cons 2 bname)))))
    )
    (command "PURGE" "B" bname)
    )

    Unfortunately the lisp routine error reporting fails if the block is inserted into the drawing as a nested (embedded) block because 'ssget' doesn't find it. The routine thinks the block can be purged, but in fact it can't be purged because it is nested.

    Basically, I would like to know whether the block is inserted into the drawing either directly, or indirectly as a nested (embedded) block. Is there an entity code or similar that will tell me this so I don't issue a pointless purge command?

    TIA,
    --
    Razoo

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Hi Razoo,

    Assuming you need compatibility with R14, this means that the use of Visual LISP is out.

    So, using Vanilla AutoLISP,

    You could cycle through the block definitions in the drawing using:

    Code:
    (defun GetObj  (bObj)
      (if (setq bObj (entnext bObj))
        (cons bObj (GetObj bObj))))
    
    (GetObj (tblobjname "BLOCK" "Block_Name"))
    And see if there are any references to the block in question within the other block definitions.

    But, for all this trouble, surely the purge call just returns "No unreferenced blocks found." does it not?

    Hope this helps,

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Junior Member
    Computer Details
    Razoo's Computer Details
    Operating System:
    XP
    Monitor:
    Samsung SyncMaster 245a
    Using
    AutoCAD 2008
    Join Date
    Nov 2009
    Location
    Berkshire, UK
    Posts
    21

    Default

    Hi Lee,

    Thanks for the quick response.

    I had considered stepping through the blocks in the drawing but as you say, it is a lot of trouble.

    The purge command does indeed return "No unreferenced blocks found", but I can't find a way of picking up this information to use within the lisp routine.

    I can use tblsearch again to see whether the block is still there or not, and if it is, I can conclude it didn't purge :-)

    I was hoping to issue an error message indicating why the block had failed to purge (e.g. because it is nested).

    I guess if ssget doesn't find the block, and then it fails to purge, I can conclude it is inserted as a nested block. I was hoping there would be a simple entity code or similar that I could look for to indicate that a block is inserted as a nested block.

    Razoo

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    I wrote part of this code a while back, and it should do what you require - although it does use Visual LISP, and so is not compatible with R14, but it will work on 2008.

    Returns T if block can be purged:

    Code:
    ;; Check Purge  --  by Lee McDonnell (Lee Mac) ~ 27.11.2009
    
    ;; Returns T if Block can be Purged.
    ;; Arguments:  bNme - Block Name [String]
    
    (defun CheckPurge (bNme)
      
      (defun BlkCount (Blk / GetNest i j ss *blk)
      ;; Block Counter by Lee McDonnell (Lee Mac) ~ 22.08.2009
      ;; Copyright © August 2009
      ;; Will Count all instances of a block, including nested.
        
        (vl-load-com)
        (setq i 0 Blk (strcase Blk) j -1
              *blk (vla-get-Blocks
                     (vla-get-ActiveDocument
                       (vlax-get-acad-object))))
    
        (defun GetNest (Obj Nme)
          (and (eq (strcase (vla-get-Name Obj)) Nme) (setq i (1+ i)))
          (vlax-for Sub Obj
            (if (eq "AcDbBlockReference" (vla-get-ObjectName Sub))
              (GetNest (vla-item *blk (vla-get-EffectiveName Sub)) Nme))))
    
        (if (setq ss (ssget "_X" '((0 . "INSERT"))))
          (while (setq ent (ssname ss (setq j (1+ j))))
            (GetNest
              (vla-item *blk
                (vla-get-EffectiveName
                  (vlax-ename->vla-object ent))) Blk)))
        
        i)
    
      (zerop (BlkCount bNme)))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Junior Member
    Computer Details
    Razoo's Computer Details
    Operating System:
    XP
    Monitor:
    Samsung SyncMaster 245a
    Using
    AutoCAD 2008
    Join Date
    Nov 2009
    Location
    Berkshire, UK
    Posts
    21

    Default

    Quote Originally Posted by Lee Mac View Post
    I wrote part of this code a while back, and it should do what you require - although it does use Visual LISP, and so is not compatible with R14, but it will work on 2008.

    Returns T if block can be purged: <snip code>
    Thanks Lee,

    I'll try it on A2008 at work on Monday.

    Razoo

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    You're welcome Razoo - but I will warn you that the code iterates through the whole block collection and furthermore recursively iterates through each object in each block - therefore its not a quick process for this kind of check.

    I would be inclined to set NOMUTT to 1, and try the purge (hence no messages will appear), then check the block collection.

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    also, if checking is not necessary:

    Code:
    (if (tblsearch "BLOCK" bname)
        (vl-catch-all-apply
            '(lambda ()
                 (command "PURGE" "B" bname)
             ) 
        ) 
    )

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Nice idea Wizman - but purge will not throw an error if it fails to purge, just a message.

    You could also rewrite yours to:

    Code:
    (if (tblsearch "BLOCK" bname)
        (vl-catch-all-apply 'vl-cmdf (list "_.-purge" "_b" bname "_n")))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  9. #9
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    You can check the 64 bit of the group 70 flag BLOCK table definition. It should show if the block is referenced. -David
    R12 (Dos) - A2K

  10. #10
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    Registered forum members do not see this ad.

    I got your point lee that purge only returns a message on error, I tried also vla-delete for purge or (member '(102 . "{BLKREFS") EntData) but not able to find link for nested blocks. I had a quick try on david's idea but maybe i did it wrong or is it only for xrefs david?.

Similar Threads

  1. How do I delete blocks from insert that cannot be purged?
    By barker in forum AutoCAD Beginners' Area
    Replies: 9
    Last Post: 3rd Dec 2008, 08:09 pm
  2. Region checking
    By AcmeMan in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 12th Dec 2006, 10:40 am
  3. checking breaks iin polylines
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 29th Sep 2006, 02:01 am
  4. checking the polylines
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 21st Sep 2006, 05:12 am

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