Code Red > AutoLISP (Vanilla / Visual)

Lisp to allow exploding for all blocks

(1/2) > >>

HasanCAD:
How to make make this lisp for selection set

--- Code: ---(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)
)
--- End code ---

Lee Mac:
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: ---(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))        )    ))
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:
Gives error

--- Code: ---error: bad argument type: VLA-object collection: ("Grid-100")
--- End code ---


--- Code: ---(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)
)
--- End code ---

pBe:
this

--- Code - Auto/Visual Lisp: ---(vlax-for bl lst (vla-put-explodable bl ans))
to


--- Code - Auto/Visual Lisp: ---(foreach bn lst  (vla-put-explodable (vla-item doc bn) ans))

oops  :-D

HasanCAD:

--- Quote from: pBe on June 14, 2012, 04:08:01 am ---this
...
to
...

--- End quote ---
Working perfect
Thanks pBe

Navigation

[0] Message Index

[#] Next page

Go to full version