I use this old function to explode all blocks with attributes, transform visible attributes into text, and modify layer, color, linetype of resulting entities.
I would need to speed up this process that needs to be executed on hundreds of blocks and it is very slow and I would need some advice on the path I must follow.
Question1: before exploding the block it is better to change its definition for change the layer, color, and line type of entities that it is composed so that already get the correct entities after the explosion of each INSERT of that block definition?
Question2: A) is it possible to have a second function that does the same while maintaining the block definition?
B) to do this is better to explode and rebuild or modify the block definition?
(defun Ale_CleanAtt ( / SelSet TxtDat EntDat EntNam BlkDat SSIndx BlkENm Dxf__1 BlkLyr)
(if (setq SelSet (ssget "_X" '((0 . "INSERT") (66 . 1)(67 . 0))));con attributi spazio modello
(progn
(setq SSIndx 0)
(repeat (sslength SelSet)
(setq
BlkENm (ssname SelSet SSIndx) SSIndx (1+ SSIndx) BlkDat (entget BlkENm) BlkLyr (DXF 8 BlkDat)
EntNam (entnext BlkENm) EntDat (entget EntNam)
)
(while (= (DXF 0 EntDat) "ATTRIB")
(if
(and
(/= 1 (logand 1 (DXF 70 EntDat))) ;; ignora attributi invisibili
(not (wcmatch (setq Dxf__1 (DXF 1 EntDat)) " ,,")) ;; ignora testi nulli
)
(progn
(setq
TxtDat
(list
(assoc 1 EntDat) ;valore testo
(assoc 8 EntDat) ;layer
(assoc 10 EntDat) ;punto di insert
(assoc 40 EntDat) ;altezza testo
(assoc 50 EntDat) ;rotazione
(assoc 41 EntDat) ;fattore di larghezza
(assoc 51 EntDat) ;angolo inclinazione
(assoc 7 EntDat) ;nome stile di testo
(assoc 71 EntDat) ;flags generazione
)
)
(if (assoc 6 EntDat) (setq TxtDat (cons (assoc 6 EntDat) TxtDat)));tipolinea
(if (assoc 62 EntDat) (setq TxtDat (cons (assoc 62 EntDat) TxtDat)));colore
(if (assoc 11 EntDat) (setq TxtDat (cons (assoc 11 EntDat) TxtDat)));punto di all.
(if (assoc 72 EntDat) (setq TxtDat (cons (assoc 72 EntDat) TxtDat)));all. orr.
(if (assoc 74 EntDat) (setq TxtDat (cons (cons 73 (DXF 74 EntDat)) TxtDat)));al.ver.
(setq TxtDat (cons '(0 . "TEXT") TxtDat))
(if (not (entmake TxtDat)) (alert "Text ENTMAKE Error."))
)
)
(setq EntNam (entnext EntNam) EntDat (entget EntNam))
)
(command "_.EXPLODE" BlkENm "")
)
)
)
)
(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
(vl-catch-all-apply
'(lambda ( )
(setq VlaObj (vla-item VlaCol KeyNam))
)
)
VlaObj
)
(defun C:Ale_CleanChange ( / SelSet)
(setq
*AcadApp* (vlax-get-Acad-Object)
*AcAcDwg* (vla-get-ActiveDocument *AcadApp*)
*AcLayrs* (vla-get-Layers *AcAcDwg*)
)
(or (ALE_Utl_GetItem *AcLayrs* "HD") (vla-add *AcLayrs* "HD")); this is only a sample
(or (ALE_Utl_GetItem *AcLayrs* "CE") (vla-add *AcLayrs* "CE")); I have many
(or (ALE_Utl_GetItem *AcLayrs* "TH") (vla-add *AcLayrs* "TH")); Layers to change
(repeat 3 ; for nested blocks
(Ale_CleanAtt)
)
(and (setq SelSet (ssget "_X" '((0 . "ATTDEF") (67 . 0)))) (command "_.ERASE" SelSet ""))
(and (setq SelSet (ssget "_X" '((62 . 0) (67 . 0)))) (command "_.CHPROP" SelSet "" "_COLOR" "_BYLAYER" ""))
(and (setq SelSet (ssget "_X" '((6 . "BYBLOCK" ) (67 . 0)))) (command "_.CHPROP" SelSet "" "_LTYPE" "_BYLAYER" ""))
(and (setq SelSet (ssget "_X" '((8 . "*HIDDEN*") (67 . 0)))) (command "_.CHPROP" SelSet "" "_LAYER" "HD" ""))
(and (setq SelSet (ssget "_X" '((8 . "*CENTER*") (67 . 0)))) (command "_.CHPROP" SelSet "" "_LAYER" "CE" ""))
(and (setq SelSet (ssget "_X" '((8 . "*THIN*" ) (67 . 0)))) (command "_.CHPROP" SelSet "" "_LAYER" "TH" ""))
)