Jump to content

Recommended Posts

Posted

Hi,

 

I am looking for some help with regards to a lisp routine.

I have a scenario where I need to select multiple blocks (all named 'Service Connection') and then explode them. I currently do this using Qselect and then manually explode but wonder there is a way to do all of this in one lisp routine to speed up the process?

 

Thank you!

Posted

Try this

 

(defun c:myExplode (/ conj n ent lstent nmBlq para)
  (while (not para)
    (if (setq ent (car (entsel "\nSelect a sample of blocks to explode...")))
      (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "INSERT")
	(setq nmBlq (cdr (assoc 2 lstent))
	      para    T
	)
	(princ
	  "\n*** SELECTED OBJECT IS NOT A BLOCK ***\Please, try again..."
	)
      )
      (princ
	"\n*** NOTHING SELECTED ***\Please, try again..."
      )
    )
  )
  (setq n 0)
  (if nmBlq
    (if (setq conj (ssget "x" (list (cons 0 "INSERT") (cons 2 nmBlq))))
      (WHILE (SETQ ent (SSNAME conj n))
	(setq lstent (entget ent)
	      n	     (+ n 1)
	)
	(vla-explode (vlax-ename->vla-object ent))
      )
    )
  )
  (princ)
)

 

Posted
13 minutes ago, GLAVCVS said:

Try this

 

(defun c:myExplode (/ conj n ent lstent nmBlq para)
  (while (not para)
    (if (setq ent (car (entsel "\nSelect a sample of blocks to explode...")))
      (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "INSERT")
	(setq nmBlq (cdr (assoc 2 lstent))
	      para    T
	)
	(princ
	  "\n*** SELECTED OBJECT IS NOT A BLOCK ***\Please, try again..."
	)
      )
      (princ
	"\n*** NOTHING SELECTED ***\Please, try again..."
      )
    )
  )
  (setq n 0)
  (if nmBlq
    (if (setq conj (ssget "x" (list (cons 0 "INSERT") (cons 2 nmBlq))))
      (WHILE (SETQ ent (SSNAME conj n))
	(setq lstent (entget ent)
	      n	     (+ n 1)
	)
	(vla-explode (vlax-ename->vla-object ent))
      )
    )
  )
  (princ)
)

 

That is perfect, thank you so much!

Posted

I have been testing this and it works great for a standard block but I also have a scenario where I have some dynamic blocks and it doesn't seem to work for those. Is there a way to include dynamic blocks as well?

Posted
(defun c:myExplode (/ conj n ent lstent nmBlq para)
  (while (not para)
    (if (setq ent (car (entsel "\nSelect a sample of blocks to explode...")))
      (if (= (cdr (assoc 0 (setq lstent (entget ent)))) "INSERT")
	(setq v (vlax-ename->vla-object ent)
       ;; nmBlq (cdr (assoc 2 lstent))
	      nmBlq (vla-get-effectivename v)
	      para    T
	)
	(princ
	  "\n*** SELECTED OBJECT IS NOT A BLOCK ***\Please, try again..."
	)
      )
      (princ
	"\n*** NOTHING SELECTED ***\Please, try again..."
      )
    )
  )(print (strcat nmBlq ",`*U*"))
  (setq n 0)
  (if nmBlq
    (if (setq conj (ssget "x" (list (cons 0 "INSERT") (cons 2 (strcat nmBlq ",`*U*")))))
      (WHILE (SETQ ent (SSNAME conj n))
	(setq v (vlax-ename->vla-object ent)
	      lstent (entget ent)
	      n	     (+ n 1)
	)
	(if (eq (vla-get-effectivename v) nmBlq)
	(vla-explode v)
	  )
      )
    )
  )
  (princ)
)

Hi Andy, check the above code, few edits from GLAV's original code.

Posted

Note that (vla-explode) creates an exploded copy, the original reference will still exist.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...