@Moshe-A wrote:
@jtm2020hyo hi,
here is a function (ma:globally_reset_dynamic_block) to reset any dynamic block by name.
usage:
(ma:globally_reset_dynamic_block "YourBlockNme")
if "YourBlockNme" is not exist, an error message is prompt and nil is return. if block is exist then at end a integer number will return which is the number of reset blocks made.
the function will skip xrefs and dependent xref blocks.
your challage is to add error checking to (vla-resetblock) method plus handle lock layers.
enjoy
moshe
(vl-load-com); load activex
(defun ma:globally_reset_dynamic_block (bname / ctr AcDbBlockTableRecord AcDbEntity)
(if (null (tblsearch "block" bname))
(prompt (strcat "\nblock " bname " is not exist.\n"))
(progn
(setq ctr 0)
; allocating memory
(vlax-for AcDbBlockTableRecord (vla-get-blocks (vla-get-activedocument (acad-object)))
(if (and
(eq (vlax-get-property AcDbBlockTableRecord 'isXref) :vlax-false) ; skip xref
(not (vl-string-search "|" (vla-get-name AcDbBlockTableRecord))) ; skip xref dependent blocks
)
(progn
; allocating memory
(vlax-for AcDbEntity AcDbBlockTableRecord
(if (and
(eq (vla-get-objectName AcDbEntity) "AcDbBlockReference")
(eq (vla-get-isDynamicBlock AcDbEntity) :vlax-true)
(eq (strcase (vla-get-effectiveName AcDbEntity)) (strcase bname))
)
(progn
(setq ctr (1+ ctr))
(vla-resetBlock AcDbEntity)
); progn
); if
; dispose memory
(vlax-release-object AcDbEntity)
); vlax-for
); progn
); if
(vlax-release-object AcDbBlockTableRecord); dispose memory
); vlax-for
ctr
); progn
); if
); ma:globally_reset_dynamic_block
I was testing your code, does not work for me.
Command:
PASTECLIP
Specify insertion point: *Cancel*
Command: *Cancel*
Command: *Cancel*
Command: *Cancel*
Command: *Cancel*
Command: (ma:(ma:globally_reset_dynamic_block "YourBlockNme"))
block YourBlockNme is not exist.
; error: no function definition: MA:
Command:
PASTECLIP
Specify insertion point: *Cancel*
Command: (ma:globally_reset_dynamic_block "#cables")
; error: no function definition: ACAD-OBJECT
Command: (ma:globally_reset_dynamic_block "#Cables")
; error: no function definition: ACAD-OBJECT
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: RENAME
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: (ma:globally_reset_dynamic_block "#Cables")
; error: no function definition: ACAD-OBJECT
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: RENAME
1 Block renamed
Command: (ma:globally_reset_dynamic_block "cables")
; error: no function definition: ACAD-OBJECT
Command: RENAME
1 Block renamed
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: RENAME
Command: (ma:globally_reset_dynamic_block "cables")
block cables is not exist.
nil
Command: (ma:globally_reset_dynamic_block "#cables")
; error: no function definition: ACAD-OBJECT
Command:
Command:
Command: _ai_selall Selecting objects...done.
I need to reset block with name #cables.
I tried rename #cables to cables and cables to #cables.
I just received this message "; error: no function definition: ACAD-OBJECT "
ATTACHED tested file.