0 Members and 1 Guest are viewing this topic.
Actually block named like *D is dimensional blocks. Do you want to explode dimention?
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 ?
Quote from: Tharwat on October 21, 2010, 05:28:34 PMI 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.
(vl-load-com)(setq blk (car (entsel "\n Select Block:")))(setq e (vlax-ename->vla-object blk))(setq obj (vla-ConvertToAnonymousBlock e))
I have a block named "*D". How do I programmatically find that block and explode it?
(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")
(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))
From dwg.ru. If you block anonymous (name starts with * U) and column and row = 1Use command UX (Unnamed eXplode) or U2B - convert anonymous block to namedCode: [Select](defun C:UX (/ adoc blks u1 n obj objlist uname bname *error*)
(defun C:UX (/ adoc blks u1 n obj objlist uname bname *error*)
(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) )