See the top rated post in this thread. Click here

Page 4 of 4 FirstFirst 1234
Results 31 to 36 of 36

Thread: LISP to Explode Dynamic Blocks Doesn't Work

  1. #31
    I could stop if I wanted to
    Join Date
    2015-10
    Location
    Colorado Springs, CO
    Posts
    369
    Login to Give a bone
    0

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Attached is what I've (used loosely as I've essentially used LM's code and edited a piece of sample code from his website) come up with. It works exactly as expected, but I'd like to figure out how to simply cancel the burst command if no blocks are found. I tried adding it to the if statement, but that makes autocad return an error for too many arguments. I'm probably putting it in the wrong spot. I also decided to use visiblity states instead of multiple blocks, simplifying my search parameter.

    Code:
    (defun c:ComboBreak (/ blk)
      (setq flag (getvar "qaflags"))
      (setvar "qaflags" 1)
      (setq blk "recep_combo")
      (if (tblsearch "BLOCK" blk)
        (sssetfirst nil (GetBlockSelection blk))
        (princ (strcat "\n" blk " doesn't exist."))
      )
      (command "explode")
      (setvar "qaflags" flag)
      (princ)
    )
    
    (defun GetBlockSelection (name)
      (ssget "_X"
    	 (list
    	   '(0 . "INSERT")
    	   (cons 2
    		 (apply	'strcat
    			(cons name
    			      (mapcar
    				(function (lambda (x) (strcat ",`" x)))
    				(LM:GetAnonymousReferences name)
    			      )
    			)
    		 )
    	   )
    	 )
      )
    )
    
    
    ;;--------------=={ Get Anonymous References }==--------------;;
    ;;                                                            ;;
    ;;  Returns the names of all anonymous references of a block. ;;
    ;;------------------------------------------------------------;;
    ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
    ;;------------------------------------------------------------;;
    ;;  Arguments:                                                ;;
    ;;  name - block name for which to return anon. references    ;;
    ;;------------------------------------------------------------;;
    ;;  Returns:  List of Anonymous Block names, else nil if none ;;
    ;;------------------------------------------------------------;;
    
    (defun LM:GetAnonymousReferences (name / ano def lst rec ref)
      (setq name (strcase name))
      (while (setq def (tblnext "BLOCK" (null def)))
        (if
          (and
    	(= 1 (logand 1 (cdr (assoc 70 def))))
    	(setq rec
    	       (entget
    		 (cdr
    		   (assoc 330
    			  (entget
    			    (tblobjname
    			      "BLOCK"
    			      (setq ano (cdr (assoc 2 def)))
    			    )
    			  )
    		   )
    		 )
    	       )
    	)
          )
           (while
    	 (and
    	   (not (member ano lst))
    	   (setq ref (assoc 331 rec))
    	 )
    	  (if
    	    (and
    	      (entget (cdr ref))
    	      (eq name (strcase (LM:EffectiveName (cdr ref))))
    	    )
    	     (setq lst (cons ano lst))
    	  )
    	  (setq rec (cdr (member (assoc 331 rec) rec)))
           )
        )
      )
      (reverse lst)
    )
    
    ;;----------------=={ Effective Block Name }==----------------;;
    ;;                                                            ;;
    ;;  Returns the effective name of a block.                    ;;
    ;;------------------------------------------------------------;;
    ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
    ;;------------------------------------------------------------;;
    ;;  Arguments:                                                ;;
    ;;  blockentity - Block Reference Entity name                 ;;
    ;;------------------------------------------------------------;;
    ;;  Returns:  True block name as per the block definition     ;;
    ;;------------------------------------------------------------;;
    
    (defun LM:EffectiveName	(blockentity / name repbtag)
      (if (wcmatch (setq name (cdr (assoc 2 (entget blockentity))))
    	       "`**"
          )
        (if
          (and
    	(setq repbtag
    	       (cdadr
    		 (assoc	-3
    			(entget
    			  (cdr
    			    (assoc 330
    				   (entget (tblobjname "BLOCK" name))
    			    )
    			  )
    			  '("AcDbBlockRepBTag")
    			)
    		 )
    	       )
    	)
    	(setq repbtag (handent (cdr (assoc 1005 repbtag))))
          )
           (setq name (cdr (assoc 2 (entget repbtag))))
        )
      )
      name
    )

  2. #32
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,806
    Login to Give a bone
    0

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Based on the 'combobursttest.dwg' posted previously....

    This will EXPLODE all instances of your Dynamic Block ("RECEP_DATA_DEMO_COMBO"):

    Code:
    (vl-load-com)
    
    (defun c:ComboBreak (/ *error* _GetDynamicBlocks acDoc blocks)
    
      (defun *error* (msg)
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (defun _GetDynamicBlocks (doc match / oBlocks blockName blocks)
        ;; Example:
        ;; (_GetDynamicBlocks acDoc "*MyBlockName*")
        (if (and (setq oBlocks (vla-get-blocks doc))
                 (setq match (strcase match))
            )
          (foreach space
                   (list (vla-get-modelspace doc) (vla-get-paperspace doc))
            (vlax-for x space
              (if
                (and
                  (= "AcDbBlockReference" (vla-get-objectname x))
                  (wcmatch
                    (strcase (setq blockName (vla-get-effectivename x))
                    )
                    match
                  )
                  (= :vlax-true
                     (vla-get-isdynamicblock
                       (vla-item oBlocks blockName)
                     )
                  )
                )
                 (setq blocks (cons x blocks))
              )
            )
          )
        )
        blocks
      )
    
      (if (setq blocks
                 (_GetDynamicBlocks
                   (setq acDoc (vla-get-activedocument (vlax-get-acad-object))
                   )
                   (strcase "RECEP_DATA_DEMO_COMBO")
                 )
          )
        (progn
          (vla-startundomark acDoc)
          (foreach block blocks
            (vla-explode block)
            (vla-delete block)
          )
        )
      )
      (*error* nil)
    )


    This will first EXPLODE all instances of your Dynamic Block ("RECEP_DATA_DEMO_COMBO"), and then BURST the resultant Dynamic Blocks ("RECEPTACAL-WALL", "DATA"):

    Code:
    (vl-load-com)
    
    (defun c:ExplodeThenBurst (/ *error* _GetDynamicBlocks acDoc blocks ss)
    
      (defun *error* (msg)
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (defun _GetDynamicBlocks (doc match / oBlocks blockName blocks)
        ;; Example:
        ;; (_GetDynamicBlocks acDoc "*MyBlockName*")
        (if (and (setq oBlocks (vla-get-blocks doc))
                 (setq match (strcase match))
            )
          (foreach space
                   (list (vla-get-modelspace doc) (vla-get-paperspace doc))
            (vlax-for x space
              (if
                (and
                  (= "AcDbBlockReference" (vla-get-objectname x))
                  (wcmatch
                    (strcase (setq blockName (vla-get-effectivename x))
                    )
                    match
                  )
                  (= :vlax-true
                     (vla-get-isdynamicblock
                       (vla-item oBlocks blockName)
                     )
                  )
                )
                 (setq blocks (cons x blocks))
              )
            )
          )
        )
        blocks
      )
    
      (if (setq blocks
                 (_GetDynamicBlocks
                   (setq acDoc (vla-get-activedocument (vlax-get-acad-object))
                   )
                   (strcase "RECEP_DATA_DEMO_COMBO")
                 )
          )
        (progn
          (vla-startundomark acDoc)
          (setq ss (ssadd))
          (foreach block blocks
            (foreach obj (vlax-invoke block 'explode)
              (setq ss (ssadd (vlax-vla-object->ename obj) ss))
            )
            (vla-delete block)
          )
          (sssetfirst nil ss)
          (c:burst)
        )
      )
      (*error* nil)
    )
    ** Code assumes that BURST Express Tool is loaded.
    Last edited by BlackBox; 2013-06-26 at 07:22 PM. Reason: Added vla-Delete calls
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 5860, Xeon W7-2495X, 128GB RAM, Dual PCIe 4.0 M.2 SSD (RAID 0), 20GB NVIDIA RTX 4000 ADA

  3. #33
    I could stop if I wanted to
    Join Date
    2015-10
    Location
    Colorado Springs, CO
    Posts
    369
    Login to Give a bone
    0

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Thanks Blackbox!

    The first code (the one I would use) is doing something weird... I get an exploded block, but the dynamic 'container' block is still in it's place (kind of like it's copying the selection set and then exploding just the copy). So I have 3 blocks instead of 2 for each instance, with one being the original 'container' block and the other two being receptacle-wall and data. If I run it again I have 5 objects, and so on... Not sure what could be causing that. Over my head for sure!

  4. #34
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,806
    Login to Give a bone
    1

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Quote Originally Posted by Coloradomrg View Post
    Thanks Blackbox!
    You're welcome.

    Quote Originally Posted by Coloradomrg View Post
    The first code (the one I would use) is doing something weird... I get an exploded block, but the dynamic 'container' block is still in it's place (kind of like it's copying the selection set and then exploding just the copy). So I have 3 blocks instead of 2 for each instance, with one being the original 'container' block and the other two being receptacle-wall and data. If I run it again I have 5 objects, and so on... Not sure what could be causing that. Over my head for sure!
    Hrrrmm... I wrote that code from memory, so perhaps I overlooked a behavior of calling the Explode Method... I know it returns a list/variant of the resultant Objects from an Explode, but now I'm recalling the need to still Delete the originating Object which might explain the observed behavior you note.

    I've revised the code above accordingly... Give those two routines another go, and let me know what you find.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 5860, Xeon W7-2495X, 128GB RAM, Dual PCIe 4.0 M.2 SSD (RAID 0), 20GB NVIDIA RTX 4000 ADA

  5. #35
    I could stop if I wanted to
    Join Date
    2015-10
    Location
    Colorado Springs, CO
    Posts
    369
    Login to Give a bone
    0

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Awesome! Works perfectly Thanks again.

  6. #36
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,806
    Login to Give a bone
    0

    Default Re: LISP to Explode Dynamic Blocks Doesn't Work

    Quote Originally Posted by Coloradomrg View Post
    Awesome! Works perfectly Thanks again.
    I couldn't ask for a better response... That is kind of you to say, and you're welcome; I'm happy to help.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 5860, Xeon W7-2495X, 128GB RAM, Dual PCIe 4.0 M.2 SSD (RAID 0), 20GB NVIDIA RTX 4000 ADA

Page 4 of 4 FirstFirst 1234

Similar Threads

  1. Explode certain blocks with Lisp
    By jgardner.79905 in forum AutoLISP
    Replies: 3
    Last Post: 2017-08-01, 06:16 PM
  2. Lisp routine doesn't work
    By boyerd492098 in forum AutoLISP
    Replies: 16
    Last Post: 2015-01-27, 10:13 PM
  3. why doesn't this lisp work in a macro?
    By chuh in forum AutoLISP
    Replies: 12
    Last Post: 2014-09-09, 05:56 PM
  4. lisp worked in 07 doesn't work in 09?
    By Hammer.John.J in forum AutoLISP
    Replies: 9
    Last Post: 2009-08-07, 04:22 PM
  5. Can't Explode Dynamic Blocks
    By Chris Matira in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2006-05-06, 02:24 AM

Posting Permissions

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