Jump to content

edit attribute value of a block massively


cyberactive

Recommended Posts

Hello, I have a routine that edits the value of a block, what happens is that I have several of these blocks that are repeated in each plane, with this routine I can edit only one and the others change at the same time, what I want is add a DCL so that it can be edited from a DCL so I'm not calling one by one since I would have it in the values to edit.
The operation of the routine is simple, call the command and ask for the name of the block then the new value and edit it in all that are equal, the blocks that have to be called are: TITULAR, CONYUGE, PUEBLO, MZ, MUNI1, MUNI2

 

(defun c:editag ( / tagname newv ss1 len count bn en el found)
 (setq tagname (getstring T "Block Name: ")
       newv (getstring T "New value:  "))
   (setq ss1 (ssget "x" '((0 . "insert") (66 . 1)))
         len (sslength ss1)
         count 0)
 (repeat len
   (setq bn (ssname ss1 count)             
         en (entnext bn)                   
         el (entget en))                   
  (while (and (= "ATTRIB" (dxf 0 el))
              (/= "SEQEND" (dxf 0 el)))
    (if (= (dxf 2 el) (strcase tagname))
         (progn
           (setq el (subst (cons 1 newv) (assoc 1 el) el))
            (entmod el)                    
            (entupd bn)                    
            (setq found "yes")             
         )                                 
     )                                     
         (setq en (entnext en)
               el (entget en))
  )                                        
  (setq count (1+ count))
 )                                         
 (if (/= found "yes")
     (princ "\nThere is no block.")
 )
     (princ)
)
(defun dxf (code elist)
      (cdr (assoc code elist))
)
(princ)

I have attached the plan with the blocks to be edited with the editag command.

Editag.dwg

Link to comment
Share on other sites

1st step is to loop through the block names from a list is easier. Using (cons 2 blkname) with the ssget

 

Your welcome to use this dcl library routine for input you would pass the block name and a default value could be blank.

 

Looking at your dwg as they are single attributes makes it much easier.  update attribute 0.

 


; replace block attribute multi block names
; By Alan H May 2019
; AJH Consulting

(defun c:replaceblk ( / oldsnap lst blk x y att ans)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq oldsnap (getvar 'osmode))
(setq lst '())
(setvar 'osmode 512)
(while (/= (setq obj (entsel "Pick block Enter to exit")) nil)
(setq bname (vla-get-name (vlax-ename->vla-object (car obj))))
(setq lst (cons bname lst))
(princ "\n")
)
(repeat (setq x (length lst))
(setq blk (nth (setq x (- x 1)) lst))
(setq ss (ssget "x" (list (cons 0 "Insert") (cons 2 blk))))
(setq ans (nth 0 (AH:getvalsm (list (strcat "Attribute replacement " blk) "New attribute" 25 24 "1-1" ))))
(repeat (setq y (sslength ss))
(setq blk (vlax-ename->vla-object (ssname ss (setq y (- y 1)))))
(setq att (vlax-invoke blk 'getattributes))
(vla-put-textstring (nth 0 att) ans)
)
)
(setvar 'osmode oldsnap)
(princ)
)
(c:replaceblk)

 

Edited by BIGAL
Link to comment
Share on other sites

 

hello, something like this link, which detects the values and that are modified from a dcl, I do not want to replace the block, I wish only to replace the value, in the dwg it can be modified massively with the editag command but I want it to be from a DCL .

 

https://www.afralisp.net/dialog-control-language/tutorials/dcl-without-the-dcl-file-part-2.php

Edited by cyberactive
Link to comment
Share on other sites

I started doing the dcl as you have shown as part of the Multi gevals. It is dynamic in that it is not hard coded so you can have as many block names as you like. 

 

Working on your sample maybe tomorrow.

 

image.png.9ed5018a2790bc8fdacb0dbb7e14f809.pngimage.png.2e54866930d435e22ae94952b53d69a6.png

 

Link to comment
Share on other sites

On 5/10/2019 at 8:34 PM, BIGAL said:

I started doing the dcl as you have shown as part of the Multi gevals. It is dynamic in that it is not hard coded so you can have as many block names as you like. 

 

Working on your sample maybe tomorrow.

 

image.png.9ed5018a2790bc8fdacb0dbb7e14f809.pngimage.png.2e54866930d435e22ae94952b53d69a6.png

 

 

Link to comment
Share on other sites

  • 1 month later...

 

hi, I have the blocks title-2 and I want to change the attribute No. but it marks me the following "Command: (LOAD "C:/LISP/MasUsados/Bloques/replace block attribute multi block names.lsp")
Pick block Enter to exit
Pick block Enter to exit
(545); error: bad argument type: lselsetp nil

 

you could help me, thanks in advance

DETALLES.dwg

Link to comment
Share on other sites

The code was done for a specific dwg, can you post a before and after dwg copy the blocks so can see change. I think you need something different.

Link to comment
Share on other sites

Understand now you want to pick an attribute then jump to each block changing value. Old New etc I have nothing at moment.

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...