Author Topic: Lisp to allow exploding for all blocks  (Read 12187 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Lisp to allow exploding for all blocks
« on: June 12, 2012, 10:00:46 AM »
How to make make this lisp for selection set
Code: [Select]
(defun c:AllowExplode (/ blocks)
  (vl-load-com)
  ;(prompt "\nSelect Blocks to Allow exploding")
  ;(setq Blk (ssget "_X" '(0 "BLOCK")))         
  (setq blocks (vla-get-Blocks
(vla-get-ActiveDocument (vlax-get-acad-object))))
 
  (initget 0 "Yes No")
  (setq ans (cond ((getkword "\nYou want to aloow wxploding for blocks?  [Yes/No] <Yes>: ")) ("Yes") ) )
  (if (= ans "Yes")
    (setq ans :vlax-true)
    (setq ans :vlax-false))
 
  (setq blocks (vla-get-Blocks
(vla-get-ActiveDocument (vlax-get-acad-object))))
 
  (vlax-for bl blocks (vla-put-explodable bl ans))
  (princ)
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Lisp to allow exploding for all blocks
« Reply #1 on: June 12, 2012, 10:05:21 AM »
Iterate over the selection set of blocks to be processed and collect a list of block names of selected blocks, then, when iterating over the block collection, only process those blocks whose name appears in the list.

Example to obtain such a list:

Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel (ssget '((0 . "INSERT"))))
  2.     (repeat (setq inc (sslength sel))
  3.         (setq blk (cdr (assoc 2 (entget (ssname sel (setq inc (1- inc)))))))
  4.         (if (not (member blk lst))
  5.             (setq lst (cons blk lst))
  6.         )
  7.     )
  8. )

The above is sufficient for standard blocks; if Dynamic Blocks are used, you will need to retrieve the Effective Block Name instead of the name (which will be anonymous for some Dynamic Blocks).

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Lisp to allow exploding for all blocks
« Reply #2 on: June 14, 2012, 04:47:16 AM »
Gives error
Code: [Select]
error: bad argument type: VLA-object collection: ("Grid-100")
Code: [Select]
(defun c:AllowExplode (/ doc sel inc blk lst ans bl)
  (vl-load-com)
  (setq doc (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))

  (prompt "\nSelect Blocks to Allow exploding")
  (if (setq sel (ssget '((0 . "INSERT"))))
    (repeat (setq inc (sslength sel))
        (setq blk (cdr (assoc 2 (entget (ssname sel (setq inc (1- inc)))))))
        (if (not (member blk lst))
            (setq lst (cons blk lst)))))
    (initget 0 "Yes No")
    (setq ans (cond ((getkword "\nDo you want to allow exploding for blocks?  [Yes/No] <Yes>: ")) ("Yes") ) )
    (if (= ans "Yes")
    (setq ans :vlax-true)
    (setq ans :vlax-false))
  (vlax-for bl lst (vla-put-explodable bl ans))
  (princ)
)


pBe

  • Bull Frog
  • Posts: 402
Re: Lisp to allow exploding for all blocks
« Reply #3 on: June 14, 2012, 05:08:01 AM »
this
Code - Auto/Visual Lisp: [Select]
  1. (vlax-for bl lst (vla-put-explodable bl ans))

to

Code - Auto/Visual Lisp: [Select]
  1. (foreach bn lst  (vla-put-explodable (vla-item doc bn) ans))


oops  :-D
« Last Edit: June 14, 2012, 05:11:51 AM by pBe »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Lisp to allow exploding for all blocks
« Reply #4 on: June 14, 2012, 05:34:13 AM »
this
...
to
...
Working perfect
Thanks pBe

pBe

  • Bull Frog
  • Posts: 402
Re: Lisp to allow exploding for all blocks
« Reply #5 on: June 14, 2012, 05:51:35 AM »
Good For you HasanCAD

As Lee pointed out:
Quote
if Dynamic Blocks are used, you will need to retrieve the Effective Block Name instead of the name (which will be anonymous for some Dynamic Blocks).

consider
Code - Auto/Visual Lisp: [Select]
  1. (setq blk (vla-get-EffectiveName (vlax-ename->vla-object (ssname sel (setq inc (1- inc))))))


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Lisp to allow exploding for all blocks
« Reply #6 on: June 14, 2012, 07:06:47 AM »
Gives error
Code: [Select]
error: bad argument type: VLA-object collection: ("Grid-100")

The 'lst' variable in my code is a list data type, not a VLA Collection Object.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Lisp to allow exploding for all blocks
« Reply #7 on: June 14, 2012, 07:34:44 AM »
The 'lst' variable in my code
....
In fact your reply guided me to finish the code.
I tried LM:ss->vla but not working.
But when pBe told me about foreach I found the mistake.
My dealing was with the list as a one group but in fact I have to deal with one object each time.
this is my analysis of this error.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Lisp to allow exploding for all blocks
« Reply #8 on: June 14, 2012, 07:39:46 AM »
The 'lst' variable in my code
....
In fact your reply guided me to finish the code.
I tried LM:ss->vla but not working.

LM:ss->vla requires a Selection Set argument, not a list of strings.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Lisp to allow exploding for all blocks
« Reply #9 on: June 14, 2012, 09:23:18 AM »
HasanCAD, see if this thread from AUGI can help you...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube