Author Topic: Explode anonymous block  (Read 5545 times)

0 Members and 1 Guest are viewing this topic.

A_LOTA_NOTA

  • Guest
Explode anonymous block
« on: October 20, 2010, 01:01:00 PM »
I have a block named "*D". How do I programmatically find that block and explode it?

kpblc

  • Bull Frog
  • Posts: 396
Re: Explode anonymous block
« Reply #1 on: October 20, 2010, 01:14:05 PM »
Actually block named like *D is dimensional blocks. Do you want to explode dimention?
Sorry for my English.

A_LOTA_NOTA

  • Guest
Re: Explode anonymous block
« Reply #2 on: October 20, 2010, 01:17:36 PM »
Actually block named like *D is dimensional blocks. Do you want to explode dimention?

Sorry, I had never seen the *D name before and someone I work with told me it's anonymous. It's a BOM with the block name "*D".

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Explode anonymous block
« Reply #3 on: October 21, 2010, 05:28:34 PM »
I think you can't name a block with astresk or slashes ,comma, points...... so on.

So the name of your block is must be a Dynamic Block or so, I mean it's not normal block isn't it ?


alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Explode anonymous block
« Reply #4 on: October 21, 2010, 05:29:51 PM »
I think you can't name a block with astresk or slashes ,comma, points...... so on.

So the name of your block is must be a Dynamic Block or so, I mean it's not normal block isn't it ?


Convert a block with vla-ConvertToAnonymousBlock and look at the name.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Explode anonymous block
« Reply #5 on: October 21, 2010, 05:38:50 PM »
I think you can't name a block with astresk or slashes ,comma, points...... so on.
So the name of your block is must be a Dynamic Block or so, I mean it's not normal block isn't it ?
Convert a block with vla-ConvertToAnonymousBlock and look at the name.

OK, Name of the Block become as a Dynamic Block (2 . "*U4").  :lol:

Here are the codes that used ....
Code: [Select]
(vl-load-com)
(setq blk (car (entsel "\n Select Block:")))
(setq e (vlax-ename->vla-object blk))
(setq obj (vla-ConvertToAnonymousBlock e))

waw a very strange function .  ;-)

ScottBolton

  • Guest
Re: Explode anonymous block
« Reply #6 on: October 22, 2010, 10:34:09 AM »
I have a block named "*D". How do I programmatically find that block and explode it?

(ssget "X" (list '(0 . "INSERT") '(2 . "`**"))) selects all anonymouse blocks - loop through them 'til you find what your after.

S

PS Try (ssget "X" (list '(0 . "INSERT") '(2 . "`*D")))
« Last Edit: October 22, 2010, 11:14:43 AM by ScottBolton »

VVA

  • Newt
  • Posts: 166
Re: Explode anonymous block
« Reply #7 on: October 25, 2010, 04:54:21 AM »
From dwg.ru. If you block anonymous (name starts with * U) and column and row = 1
Use command UX (Unnamed eXplode) or U2B - convert anonymous block to named
Code: [Select]
(defun C:UX (/ adoc blks u1 n obj objlist uname bname *error*)
;;;Взорвать (расчленить) МН-БЛОК
;;; Explode Minsert block whith column and row = 1
;;; Posted Vladimir Azarko (VVA)
;;;http://dwg.ru/f/showthread.php?t=11502
  (defun *error* (msg)
    (princ msg)
    (mip:layer-status-restore)
    (vla-endundomark adoc)
    (princ)
  ) ;_ end of defun
  (vl-load-com)
  (mip:layer-status-save)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object))
        blks (vla-get-blocks adoc)
  ) ;_ end of setq
  (vla-startundomark adoc)
  (if
    (and (setq uname (car (entsel "\nSelect block")))
         (wcmatch (setq bname (cdr (assoc 2 (entget uname)))) "`*U*")
         (setq obj (vlax-ename->vla-object uname))
         (or (and (vlax-property-available-p obj "columns")
                  (vlax-property-available-p obj "rows")
                  (= (vla-get-columns (vlax-ename->vla-object uname)) 1)
                  (= (vla-get-rows (vlax-ename->vla-object uname)) 1)
             ) ;_ end of and
             (and (not (vlax-property-available-p obj "columns"))
                  (not (vlax-property-available-p obj "rows"))
             ) ;_ end of and
         ) ;_ end of or
    ) ;_ end of and
     (progn
       (setq u1 (vla-item blks bname)
             n  1
       ) ;_ end of setq
       (vlax-for obj u1
         (grtext -1 (strcat "Working ... item " (itoa n)))
         (setq objlist (cons obj objlist))
         (setq n (1+ n))
       ) ;_ end of vlax-for
       (setq n (vla-get-insertionpoint (vlax-ename->vla-object uname)))
       (grtext -1 "Coping items. Begin")
       (mapcar '(lambda (item)
                  (vla-move item (vlax-3d-point '(0 0 0)) n)
                ) ;_ end of lambda
               (vlax-safearray->list
                 (vlax-variant-value
                   (vla-copyobjects
                     (vla-get-activedocument (vlax-get-acad-object))
                     (vlax-make-variant
                       (vlax-safearray-fill
                         (vlax-make-safearray
                           vlax-vbobject
                           (cons 0 (1- (length objlist)))
                         ) ;_ end of vlax-make-safearray
                         objlist
                       ) ;_ end of vlax-safearray-fill
                     ) ;_ end of vlax-make-variant
                                                  ;(vla-get-ModelSpace adoc)
                     (vla-get-block
                       (vla-get-activelayout
                         (vla-get-activedocument (vlax-get-acad-object))
                       ) ;_ end of vla-get-ActiveLayout
                     ) ;_ end of vla-get-block
                   ) ;_ end of vla-copyobjects
                 ) ;_ end of vlax-variant-value
               ) ;_ end of vlax-safearray->list

       ) ;_ end of mapcar
       (grtext -1 "Coping items. End ")
       (entdel uname)
     ) ;_ end of progn
  ) ;_ end of if
  (mip:layer-status-restore)
  (vla-endundomark adoc)
  (princ)
) ;_ end of defun
(defun mip:layer-status-restore ()
  (foreach item *MIP_LAYER_LST*
    (if (not (vlax-erased-p (car item)))
      (vl-catch-all-apply
        '(lambda ()
           (vla-put-lock
             (car item)
             (cdr (assoc "lock" (cdr item)))
           ) ;_ end of vla-put-lock
           (vla-put-freeze
             (car item)
             (cdr (assoc "freeze" (cdr item)))
           ) ;_ end of vla-put-freeze
         ) ;_ end of lambda
      ) ;_ end of vl-catch-all-apply
    ) ;_ end of if
  ) ;_ end of foreach
  (setq *MIP_LAYER_LST* nil)
) ;_ end of defun

(defun mip:layer-status-save ()
  (setq *MIP_LAYER_LST* nil)
  (vlax-for item
                 (vla-get-layers
                   (vla-get-activedocument (vlax-get-acad-object))
                 ) ;_ end of vla-get-layers
    (setq *MIP_LAYER_LST*
           (cons (list item
                       (cons "freeze" (vla-get-freeze item))
                       (cons "lock" (vla-get-lock item))
                 ) ;_ end of cons
                 *MIP_LAYER_LST*
           ) ;_ end of cons
    ) ;_ end of setq
    (vla-put-lock item :vlax-false)
    (if (= (vla-get-freeze item) :vlax-true)
      (vl-catch-all-apply
        '(lambda () (vla-put-freeze item :vlax-false))
      ) ;_ end of vl-catch-all-apply
    ) ;_ end of if
  ) ;_ end of vlax-for
) ;_ end of defun
(defun C:U2B (/        adoc     blks     u1       n        obj
              objlist  uname    bname    *error*  bnameNew tmp_blk
             )
  (defun *error* (msg)
    (princ msg)
    (mip:layer-status-restore)
    (vla-endundomark adoc)
    (princ)
  ) ;_ end of defun
  (vl-load-com)
  (mip:layer-status-save)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object))
        blks (vla-get-blocks adoc)
  ) ;_ end of setq
  (vla-startundomark adoc)
  (if
    (and (setq uname (car (entsel "\nSelect block")))
         (wcmatch (setq bname (cdr (assoc 2 (entget uname)))) "`*U*")
         (setq obj (vlax-ename->vla-object uname))
         (or (and (vlax-property-available-p obj "columns")
                  (vlax-property-available-p obj "rows")
                  (= (vla-get-columns (vlax-ename->vla-object uname)) 1)
                  (= (vla-get-rows (vlax-ename->vla-object uname)) 1)
             ) ;_ end of and
             (and (not (vlax-property-available-p obj "columns"))
                  (not (vlax-property-available-p obj "rows"))
             ) ;_ end of and
         ) ;_ end of or
         (setq bnameNew (getstring "\nNew block name: "))
         (or
         (while (or (not (snvalid bnameNew))
                    (member (strcase bnameNew) (tablelist "BLOCK"))
                ) ;_ end of or
           (alert "Incorrect block name")
           (setq bnameNew (getstring "\nNew block name: "))
         ) ;_ end of while
         t)
    ) ;_ end of and
     (progn
       (setq unnamed_block
              (vla-add (vla-get-blocks adoc)
                       (vlax-3d-point '(0 0 0))
                       bnameNew
              ) ;_ end of vla-add
       ) ;_ end of setq
       (setq u1 (vla-item blks bname)
             n  1
       ) ;_ end of setq
       (vlax-for item u1
         (grtext -1 (strcat "Working ... item " (itoa n)))
         (setq objlist (cons item objlist))
         (setq n (1+ n))
       ) ;_ end of vlax-for
       (setq n (vla-get-insertionpoint (vlax-ename->vla-object uname)))
       (grtext -1 "Coping item. Begin ")
       (vla-copyobjects
                     adoc
                     (vlax-make-variant
                       (vlax-safearray-fill
                         (vlax-make-safearray
                           vlax-vbobject
                           (cons 0 (1- (length objlist)))
                         ) ;_ end of vlax-make-safearray
                         objlist
                       ) ;_ end of vlax-safearray-fill
                     ) ;_ end of vlax-make-variant
                                                  ;(vla-get-ModelSpace adoc)
                     unnamed_block
                   ) ;_ end of
       (grtext -1 "Coping item. End ")
       (setq
         tmp_blk (vla-insertblock
                   (vla-objectidtoobject adoc (vla-get-ownerid obj))
                                                  ;(vla-get-InsertionPoint obj)
                   n
                   (vla-get-name unnamed_block)
                   (vla-get-xscalefactor obj)
                   (vla-get-yscalefactor obj)
                   (vla-get-zscalefactor obj)
                   (vla-get-rotation obj)
                 ) ;_ end of vla-insertblock
       ) ;_ end of setq
(mapcar
   '(lambda (x y) (vlax-put-property tmp_blk x y))
   '(Linetype LineWeight Color Layer)
   (mapcar
     '(lambda (x)
(vlax-get-property obj x))
     '(Linetype LineWeight Color Layer)))       
       (entdel uname)
     ) ;_ end of progn
  ) ;_ end of if
  (mip:layer-status-restore)
  (vla-endundomark adoc)
  (princ)
) ;_ end of defun
;;;================================================================================
;;;Written By Michael Puckett.
;;;Список элементов символьных таблиц АвтоКАДа
;;; - s- имя таблицы
;;;Пример - список всех слоев - (setq all_layers (tablelist "LAYER"))
;;;(setq all_layers (tablelist "LAYER"))
;;;
;;;AutoLisp should return something like this :
;;;Start Coding Here
(defun tablelist (s / d r)
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  );_while
);_defun
(princ "\nType UX or U2B in command line")
If you have classic Minsert block (whith column or row > 1) type M2B to convert minsert block in the usual anonymous
Code: [Select]
(defun C:M2B ( / adoc blks u1 n obj objlist uname bname unnamed_block cpo tmp_blk ss lst)
;;;Convert Minsert block To Block
;;; Posted Vladimir Azarko (VVA)
;;; http://forum.dwg.ru/showthread.php?t=11502&page=3(vl-load-com)
(setq adoc (vla-get-activedocument (vlax-get-acad-object))
        blks (vla-get-blocks adoc)
        ) ;_ end of setq
  (vla-AuditInfo adoc :vlax-true)
  (vla-startundomark adoc)
  (if (setq ss (ssget "_:L" '((0 . "INSERT")
      (-4 . "<OR")
      (-4 . ">")(70 . 1)
      (-4 . ">")(71 . 1)
      (-4 . "OR>")
      )))
(progn
  (repeat (setq n (sslength ss)) ;_ end setq
         (setq lst (cons (ssname ss (setq n (1- n))) lst))
         ) ;_ end
  (setq ss nil n 0)
  (foreach uname lst
    (grtext -1 (strcat "Working " (itoa (setq n (1+ n)))))
  (setq bname (cdr(assoc 2 (entget uname)))) 
  (setq u1 (vla-item blks bname))
  (setq obj (vlax-ename->vla-object uname) objlist nil) 
  (vlax-for item u1 (setq objlist (cons item objlist)))
 (setq unnamed_block (vla-add (vla-get-blocks adoc)(vlax-3d-point '(0 0 0)) "*U"))
 (setq cpo (vla-copyobjects adoc
                 (vlax-make-variant
                   (vlax-safearray-fill
                     (vlax-make-safearray
                       vlax-vbobject
                       (cons 0 (1- (length objlist)))
                     ) ;_ end of vlax-make-safearray
                     objlist
                   ) ;_ end of vlax-safearray-fill
                 ) ;_ end of vlax-make-variant
                ;(vla-get-ModelSpace adoc)
unnamed_block
               )
      )
  (setq tmp_blk (vla-insertblock
  (vla-objectidtoobject adoc (vla-get-ownerid obj))
  (vla-get-InsertionPoint obj)
  (vla-get-name unnamed_block)
  (vla-get-xscalefactor obj)(vla-get-yscalefactor obj)
       (vla-get-zscalefactor obj)
  ;(vla-get-rotation obj)
  0
  )
)
  (setq cpo (vla-ArrayRectangular tmp_blk (vla-get-rows obj)(vla-get-columns obj) 1 (vla-get-RowSpacing obj)(vla-get-ColumnSpacing obj) 0))
  (setq cpo (vlax-safearray->list(vlax-variant-value cpo)))
  (setq cpo (cons tmp_blk cpo))
(foreach item cpo
(vla-rotate item (vla-get-InsertionPoint obj) (vla-get-rotation obj))
)
  (entdel uname)
    )
  (princ "Converting ")(princ n)(princ " minsert blocks")
  )
  )
  (vla-endundomark adoc)
(vl-cmdf "_.Redraw")
(princ)
)

Nibster

  • Guest
Re: Explode anonymous block
« Reply #8 on: April 07, 2011, 12:28:49 PM »
From dwg.ru. If you block anonymous (name starts with * U) and column and row = 1
Use command UX (Unnamed eXplode) or U2B - convert anonymous block to named
Code: [Select]
(defun C:UX (/ adoc blks u1 n obj objlist uname bname *error*)

this is exactly what i've been looking for.... mostly.

is there a way to get "U2B" to work so it doesn't wipe out the contents of the attributes AND select all similar anon-blocks, not just the selected instance?
« Last Edit: April 07, 2011, 11:44:00 PM by CAB »

pBe

  • Bull Frog
  • Posts: 402
Re: Explode anonymous block
« Reply #9 on: April 08, 2011, 09:14:43 AM »
A quick one <Not thouroguhly tested >

Code: [Select]
(defun RenAno ( NName / chk_nm blks el1 bnm)
  (vl-load-com)
  (defun chk_nm (nme)
    (if (tblsearch "BLOCK" nme)
      (chk_nm (strcat nme "x"))
      nme
      )
    )
  (setq blks
     (vla-get-blocks
       (vla-get-activedocument (vlax-get-acad-object))
       )
    )
  (while (setq el1 (tblnext "BLOCK" (not el1)))
    (setq bnm (cdr (assoc 2 el1)))
    (if (wcmatch (strcase bnm) "`*U*")
      (vla-put-name
        (vla-item blks bnm)
        (chk_nm (strcat NName (substr bnm 3)))
        )
      )
    )
  (princ)
  )