I wrote this function which I consider very useful for renaming and/or rotating nested blocks. It is not written "very effectively" but for my use it is sufficient, it would be interesting to enhance it in order to be able to rename all the blocks above the selected nested block at the same time, does anyone have any suggestions?
(needs Doslib)
(defun C:ALE_Block_Cmd_Rename ( / InfLst EntDat FthEnt FthNam BlkObj BlkNam BlkEfN NewNam AngRot NewRot DclInf BlkDef DclStr FlgUpd DclLst Countr LevLst TmpDat Countr)
(if
(and
(setq InfLst (ALE_Block_Cmd_NentselBlock "Select main or nested block to rename and/or rotate"))
(setq BlkObj (vlax-ename->vla-object (caddr InfLst)) BlkNam (car InfLst) EntDat (cadr InfLst))
(vlax-property-available-p BlkObj 'Name)
)
(progn
(setq
BlkEfN (ALE_Block_Name BlkObj)
AngRot (DXF 50 EntDat)
DclLst (list (cons "Name" BlkEfN) (cons "Rotation" (RAG AngRot)))
)
(and (cadddr InfLst) (setq FthEnt (cadddr InfLst) FthNam (DXF 2 (entget FthEnt))))
(if (or (null FthNam) (= FthNam BlkNam))
(setq DclStr (strcat "Rename and/or rotate selected block: " BlkEfN) FthEnt nil)
(progn
(setq
DclStr (strcat "Nested block: " BlkEfN " of block at first level: " FthNam)
LevLst (cdr (last (last InfLst)))
Countr (1+ (length LevLst))
)
(foreach ForElm LevLst
(setq
DclLst (cons (cons (strcat "Level " (itoa Countr) " -------------------------------------------") "-------------------------------------------") DclLst)
TmpDat (entget ForElm)
DclLst (cons (cons "Name" (DXF 2 TmpDat)) (cons (cons "Rotation" (RAG (DXF 50 TmpDat))) DclLst))
Countr (1- Countr)
)
)
(setq DclLst (cons '("Level 1 -------------------------------------------" . "-------------------------------------------") DclLst))
)
)
(setq
DclInf (reverse (DOS_PROPLIST DclStr "" DclLst))
NewNam (cdadr DclInf)
)
(while (and NewNam (/= (strcase BlkEfN) (strcase NewNam)) (tblsearch "BLOCK" NewNam))
(setq
DclInf (DOS_PROPLIST DclStr (strcat "Block: " NewNam " already exist!") (list (cons "Name" NewNam) (cons "Rotation" (RAG AngRot))))
NewNam (cdar DclInf)
)
)
(cond
( (null NewNam) )
( (not (numberp (setq NewRot (distof (cdar DclInf))))) (alert "Rotation angle not valid! ") )
( (equal (setq NewRot (GAR NewRot)) AngRot 0.001) )
( T (vla-put-Rotation BlkObj NewRot) (setq FlgUpd T) )
)
(and
NewNam
(/= (strcase BlkEfN) (strcase NewNam))
(and (setq BlkDef (ALE_Utl_GetItem *AcBlcks* BlkEfN)) (progn (vla-put-Name BlkDef NewNam) (setq FlgUpd T)))
)
(and
FlgUpd
(progn (entupd (caddr InfLst)) (and FthEnt (vla-regen *AcAcDwg* acActiveViewport)))
)
);progn
(princ "\nNo block selected, command cancelled. ")
)
(princ)
)
(defun ALE_Block_Cmd_NentselBlock (PrmStr / EntDat EntNam BlkNam EntLst UpdNam)
(if (setq EntLst (nentsel (strcat "\n" PrmStr ": ")))
(progn
(if (= (length EntLst) 4)
(progn
(if (and (= "DIMENSION" (DXF 0 (entget (car (last EntLst))))) (cdr (last EntLst)))
(setq EntLst (list (car EntLst) (cdr (last EntLst))))
);if
(setq
UpdNam (DXF -1 (entget (last (last EntLst))))
EntNam (car (last EntLst))
)
(if (setq EntDat (entget EntNam)) (setq BlkNam (DXF 2 EntDat)));if
);progn
(progn
(setq EntNam (car EntLst))
(if (= "ATTRIB" (DXF 0 (entget EntNam)))
(progn
(setq EntNam (ssname (ssget (cadr EntLst)) 0))
(if (setq EntDat (entget EntNam)) (setq BlkNam (DXF 2 EntDat)));if
);progn
);if
);progn
);if
);progn
(princ "\nNothing selected, command cancelled. ")
);if
(if (and BlkNam (= "INSERT" (DXF 0 EntDat)))
(list BlkNam EntDat EntNam UpdNam EntLst)
)
)
(defun Dxf (DxfCod EntDat) (cdr (assoc DxfCod EntDat)))
(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
(vl-catch-all-apply
'(lambda ( )
(setq VlaObj (vla-item VlaCol KeyNam))
)
)
VlaObj
)
(defun ALE_Block_Name (BlkObj)
(if (vlax-property-available-p BlkObj 'effectivename)
(vla-get-effectivename BlkObj)
(vla-get-name BlkObj)
)
)