Author Topic: Explode all anonymous blocks in a file  (Read 12408 times)

0 Members and 1 Guest are viewing this topic.

barc

  • Guest
Explode all anonymous blocks in a file
« on: February 25, 2011, 09:09:50 AM »
Okay, I know next to nothing about lisp and I'm attempting to explode all the anonymous blocks in a file (long story PDS conversion to AutoCAD - ugly ugly ugly)

I know that
Code: [Select]
(ssget "X" (list '(0 . "INSERT") '(2 . "`**")))Will select the blocks starting with "*"
But
Code: [Select]
(command ".explode" (ssget "X" (list '(0 . "INSERT") '(2 . "`*u*"))) "")fails for some reason

Any help will be appreciated.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Explode all anonymous blocks in a file
« Reply #1 on: February 25, 2011, 11:03:17 AM »
The undocumented QAFLAGS System Variable can sometimes play a part when calling the Explode command from a LISP:

Code: [Select]
(defun c:test ( / ss qaf )
 
  (setq qaf (getvar 'QAFLAGS))
  (setvar 'QAFLAGS 5)

  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "`*U*")))) (command "_.explode" ss ""))
 
  (setvar 'QAFLAGS qaf)
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Explode all anonymous blocks in a file
« Reply #2 on: February 25, 2011, 11:06:05 AM »
The blocks could be set to not be not explodable?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Explode all anonymous blocks in a file
« Reply #3 on: February 25, 2011, 11:11:07 AM »
Or that ^^  :wink:

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Explode all anonymous blocks in a file
« Reply #4 on: February 25, 2011, 11:21:59 AM »
Got a bit carried away with this one...

Code: [Select]
(defun c:ExplAnon ( / *error* _StartUndo _EndUndo _UnlockLayers _RelockLayers _isExplodable _GetBlockName acblk acdoc locked name ss )
  (vl-load-com)
  ;; © Lee Mac 2011

  (defun *error* ( msg )
    (if locked (_RelockLayers locked))
    (if acdoc  (_EndUndo acdoc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun _StartUndo ( doc ) (_EndUndo doc)
    (vla-StartUndoMark doc)
  )

  (defun _EndUndo ( doc )
    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
      (vla-EndUndoMark doc)
    )
  )

  (defun _UnlockLayers ( doc / l )
    (vlax-for layer (vla-get-layers doc)
      (if (eq :vlax-true (vla-get-lock layer))
        (vla-put-lock (car (setq l (cons layer l))) :vlax-false)
      )
    )
    l
  )

  (defun _RelockLayers ( lst )
    (mapcar '(lambda ( l ) (vla-put-lock l :vlax-true)) lst)
  )

  (defun _isExplodable ( blockdef )
    (or
      (not (vlax-property-available-p blockdef 'explodable))
      (eq :vlax-true (vla-get-explodable blockdef))
    )
  )

  (defun _GetBlockName ( obj )
    (if (vlax-property-available-p obj 'effectivename)
      (vla-get-effectivename obj)
      (vla-get-name obj)
    )
  )

  (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
        acblk (vla-get-blocks acdoc)
  )       

  (if (ssget "_X" '((0 . "INSERT") (2 . "`*U*")))
    (progn
      (_StartUndo acdoc) (setq locked (_UnlockLayers acdoc))
     
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet acdoc))
       
        (if (_isExplodable (vla-item acblk (setq name (_GetBlockName obj))))
          (progn
            (vla-explode obj) (vla-delete obj)
          )
          (princ (strcat "\nBlock: " name " is not explodable."))
        )
      )
      (vla-delete ss) (_RelockLayers locked) (_EndUndo acdoc)
    )
  )

  (princ)
)

 :|

barc

  • Guest
Re: Explode all anonymous blocks in a file
« Reply #5 on: February 25, 2011, 01:23:01 PM »
ewwkayyyy....

What the heck is QAFLAGS and why would it make a difference with the explode command in lisp??  Setting it to 5 made everything all better.

Oh and thanks loads, appreciate the help

barc

  • Guest
Re: Explode all anonymous blocks in a file
« Reply #6 on: February 25, 2011, 01:49:35 PM »
From jtbworld:
http://www.jtbworld.com/autocadtips.htm
Quote
What is QAFLAGS?
QAFLAGS been used a long time (<r12) by developers and autodesk themself too.

QAFLAGS acceps a value between 0 and 32767
bit 0 (1) : ^C in menu macro cancels grips (acts like keyboard <Esc>).
bit 1 (2) : no pause during text screen listings.
bit 2 (4) : no "alert" dialogs (text display instead).
bit 7 (128) : accepts "screen picks" (point lists) via (command) function.

Normally QAFLAGS should be set to 0. Because it might be set to other values it is a good idea to put (setvar "QAFLAGS" 0) in acaddoc.lsp or any other of your lisp files that you use for startup.

When exploding multiple objects you can set QAFLAGS to 1 as in this AutoLISP example:
(setvar "qaflags" 1)
(command "._explode" (ssget) "")
(setvar "qaflags" 0)

So I guess setting it to 5 combines 1 and 4.   Why does that affect EXPLODE???

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Explode all anonymous blocks in a file
« Reply #7 on: February 25, 2011, 05:31:24 PM »
So I guess setting it to 5 combines 1 and 4.   Why does that affect EXPLODE???

*shrug* just does

danallen

  • Guest
Re: Explode all anonymous blocks in a file
« Reply #8 on: February 25, 2011, 06:07:20 PM »
Does anyone know what "bit 7 (128) : accepts "screen picks" (point lists) via (command) function" would be used for?

Thanks,

Dan

barc

  • Guest
Re: Explode all anonymous blocks in a file
« Reply #9 on: February 25, 2011, 06:45:01 PM »
Apparently I knew about it back in R13 because I set it to 2 back then and haven't loooked at it since.  (found it in my stuff)

Also, I've just discovered that setting it above two does weird things with dialog boxes in lisp for older commands.  Set at 2, (command ".array" ......) will function at the command line like it did prior to dialog box version.  Setting QAFLAGS to 3 or 5 and (command ".array" ......) will call the dialog box.  I've repaired the older lisp functions to now include the dash, but with QAFLAGS set to 2 they worked just fine for a couple of decades. 

"velly interestink  ...  but silly"

Crank

  • Water Moccasin
  • Posts: 1503
Re: Explode all anonymous blocks in a file
« Reply #10 on: February 26, 2011, 04:06:58 AM »
From here:
Quote
What is QAFLAGS?
QAFLAGS been used a long time (<r12) by developers and autodesk themself too.

QAFLAGS acceps a value between 0 and 32767
bit 0 (1) : ^C in menu macro cancels grips (acts like keyboard <Esc>).
bit 1 (2) : no pause during text screen listings.
bit 2 (4) : no "alert" dialogs (text display instead).
bit 7 (128) : accepts "screen picks" (point lists) via (command) function.

Normally QAFLAGS should be set to 0. Because it might be set to other values it is a good idea to put (setvar "QAFLAGS" 0) in acaddoc.lsp or any other of your lisp files that you use for startup.

When exploding multiple objects you can set QAFLAGS to 1 as in this AutoLISP example:
(setvar "qaflags" 1)
(command "._explode" (ssget) "")
(setvar "qaflags" 0)
Also:
bit 9 (512) : sets Bind type to insert in R14
Vault Professional 2023     +     AEC Collection