request to create resetblockbyname.lsp

request to create resetblockbyname.lsp

jtm2020hyo
Collaborator Collaborator
1,667 Views
18 Replies
Message 1 of 19

request to create resetblockbyname.lsp

jtm2020hyo
Collaborator
Collaborator

I need reset a dynamic block in the entire drawing. (regular block, dynamic block, nested blocks) by selecting the block and typing their name.

0 Likes
Accepted solutions (2)
1,668 Views
18 Replies
Replies (18)
Message 2 of 19

Moshe-A
Mentor
Mentor

@jtm2020hyo hi,

 

Can you elaborate on that and provide sample dwg?!

 

moshe

Message 3 of 19

jtoverka
Advocate
Advocate

There is little information within your post. I am confused when you say "by selecting the block and typing their name." Why do you need to do both to reset the block in the drawing? Unless you mean that you can do either to achieve the same result? However, I assume that you want to reset the properties of dynamic blocks to their original values.

 

Lee Mac has a great library of programs that works with dynamic blocks.
http://www.lee-mac.com/dynamicblockfunctions.html

Message 4 of 19

jtm2020hyo
Collaborator
Collaborator

@Moshe-A wrote:

@jtm2020hyo hi,

 

Can you elaborate on that and provide sample dwg?!

 

moshe





In my attached file I need to reset the block named "#cables" in the whole drawing. such dynamic block need be reset in all kind of blocks (regular blocks, dynamic blocks, nested blocks).
why I need reset all copies of the selected blocks? I modified such block but when use ATTSYNC blocks just update ATTRIBUTES. RESETBLOCK do what I need. but are like 1000 blocks to use it inside.

 

so I need a batch lisp alternative to reset all copies of selected block or named block.

 

 

 

 

 

image.png

 

 

 

 

0 Likes
Message 5 of 19

jtm2020hyo
Collaborator
Collaborator

@jtoverka wrote:

There is little information within your post. I am confused when you say "by selecting the block and typing their name." Why do you need to do both to reset the block in the drawing? Unless you mean that you can do either to achieve the same result? However, I assume that you want to reset the properties of dynamic blocks to their original values.

 

Lee Mac has a great library of programs that works with dynamic blocks.
http://www.lee-mac.com/dynamicblockfunctions.html


 

sorry for my bad English
I mean "by selecting the block OR typing their name"

0 Likes
Message 6 of 19

Moshe-A
Mentor
Mentor

@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
Message 7 of 19

Moshe-A
Mentor
Mentor

@jtm2020hyo hi,

 

if the help you got does solved your problem? than mark this as your solution.

 

thanks

moshe

Message 8 of 19

jtm2020hyo
Collaborator
Collaborator

@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.

 

 

0 Likes
Message 9 of 19

DannyNL
Advisor
Advisor

Change (acad-object) to (vlax-get-acad-object).

(vlax-for AcDbBlockTableRecord (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
0 Likes
Message 10 of 19

Moshe-A
Mentor
Mentor
Accepted solution

sorry, my mistake, here is the fix

 

 

(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 (vlax-get-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
0 Likes
Message 11 of 19

jtm2020hyo
Collaborator
Collaborator

@Moshe-A wrote:

sorry, my mistake, here is the fix

 

 

(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 (vlax-get-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

 

work perfect for me.

thanks a lot.

A question: How can I modify your lisp code to use typing a command, something like this "c:resetblocksbyname"

0 Likes
Message 12 of 19

Moshe-A
Mentor
Mentor

change  "ma:globally_reset_dynamic_block" to "c:resetblocksbyname"

0 Likes
Message 13 of 19

jtm2020hyo
Collaborator
Collaborator

@Moshe-A wrote:

change  "ma:globally_reset_dynamic_block" to "c:resetblocksbyname"


 

I tried to change as you said, but I have not luck.

attached file lisp is what I tried modify.

0 Likes
Message 14 of 19

Moshe-A
Mentor
Mentor

your change is good but the question is what did you do after?

it should be load in order to work - yes?!

 

Message 15 of 19

Moshe-A
Mentor
Mentor

@jtm2020hyo ,

 

sorry here is the fix:

 

(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 (vlax-get-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


(defun c:resetblocksbyname ()
 (ma:globally_reset_dynamic_block "#cables")
 (princ)
)
Message 16 of 19

jtm2020hyo
Collaborator
Collaborator

@Moshe-A wrote:

@jtm2020hyo ,

 

sorry here is the fix:

 

(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 (vlax-get-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


(defun c:resetblocksbyname ()
 (ma:globally_reset_dynamic_block "#cables")
 (princ)
)

 

thanks for your reply.

I noticed that "c:resetblocksbyname" command line reset just the block with name "#cables"

 

...but is possible to type ANY block name after input "c:resetblocksbyname" command line?

 

 

 

 

0 Likes
Message 17 of 19

Moshe-A
Mentor
Mentor

something like this?

 

(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 (vlax-get-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)
	     (wcmatch (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

(defun c:resetblocksbyname ()
 (ma:globally_reset_dynamic_block "*")
 (princ)
)
0 Likes
Message 18 of 19

jtm2020hyo
Collaborator
Collaborator

@Moshe-A wrote:

something like this?

 

(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 (vlax-get-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)
	     (wcmatch (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

(defun c:resetblocksbyname ()
 (ma:globally_reset_dynamic_block "*")
 (princ)
)

 

I mean more like: enter command "resetblocksbyname", then write the block name "#tableros" or "*" (using '*' like wildcard), then press ENTER, then all block with the same name are reset.

 

 

 

0 Likes
Message 19 of 19

Moshe-A
Mentor
Mentor
Accepted solution

@jtm2020hyo ,

 

here it is ... and you can reply to the prompt with one block name or multiple block names separate with commas:

 

Enter a block name: BLOCK1

or

Enter a block name: BLOCK1,BLOCK2,BLOCK2

or

Enter a block name: *   ; one asterisk means reset all dynamic blocks

 

 

(defun c:resetblocksbyname (/ bname)
 (if (/= (setq bname (getstring "\nEnter block name(s): ")) "")
  (ma:globally_reset_dynamic_block bname)
 )
  
 (princ)
)