Update attributes in block based on insertion point.

Update attributes in block based on insertion point.

jpCADconsulting
Advocate Advocate
367 Views
2 Replies
Message 1 of 3

Update attributes in block based on insertion point.

jpCADconsulting
Advocate
Advocate

Hi folks, 

 

I'm looking for some help putting a routine together that will:

 

Allow me to select multiple instances of the same block.

Update two attributes in each block based on the X and Y values of the blocks' insertion points.

 

Here is some background:

 

I have a routine that inserts these blocks and populates the two attributes on insertion (based on the picked point).  Works like a charm. See code below.

 

Now however, my client wants to (or has to) move all of these blocks to correct for some misinformation earlier in the project.

 

So I need to update them all en masse.

thanks in advance for your help as alwasy!

 

Code that inserts/populates the blocks:

 

 

(defun POMDF (/ DZ CRDX CRDY CRDXY CRDA CRDB P DZORIG SCL DIV)
(setvar 'ATTDIA 0)

(setq CL (getvar "CLAYER"))

(cond ((= (getvar "INSUNITS") 1) (setq SCL 1)(setq CRDA 4)(Setq CRDB 1)(setq DIV 12.0))
      ((= (getvar "INSUNITS") 2) (setq SCL 0.08333)(setq CRDA 4)(Setq CRDB 1)(setq DIV 12.0))
      (t (alert "Current DWG set to non-standard units.  Check UNITS settings")(exit))
)



;;;;; Bring in block Point Of Test from SCAPE Tags.dwg
(defun open_dbx (dwg / dbx)
   (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
      (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument"))
      (setq dbx (vlax-create-object
      (strcat "ObjectDBX.AxDbDocument."
         (substr (getvar "ACADVER") 1 2)
         )
      )
   )
)
(vla-open dbx dwg)
dbx
)
(setq Dbx (open_dbx "V:/AutoCAD 2018/Drawings/SCAPE Tags.dwg"))
(vla-CopyObjects
Dbx
(vlax-safearray-fill
(vlax-make-safearray vlax-vbObject '(0 . 0))
(list (vla-item (vla-get-blocks dbx) "Coordinates Key r02"))
)
(vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-release-object dbx)

;;;;; Insert and populate block

(command "-layer" "Make" "0-Dims" "Color" "3" "0-Dims" "Ltype" "CONTINUOUS" "" "Plot" "P" "" "")
(setvar "CLAYER" "0-dims")

(setq dz (getvar 'DIMZIN))
(setvar 'DIMZIN 0)

(while (setq p (getpoint "\n Specify point :"))
(setq CRDX (/ (car p) DIV))
(setq CRDY (/ (cadr p) DIV))
  (command "_.-insert"

           "Coordinates Key r02"
           p
           SCL
           ""
           "0"
           (strcat "E: "(rtos CRDX 2 2) "'")
           ""
           (strcat "N: "(rtos CRDY 2 2) "'")
           ""
  )

)

(setvar "CLAYER" CL)
(setvar 'DIMZIN dz)

)

 

 

 

0 Likes
368 Views
2 Replies
Replies (2)
Message 2 of 3

john.uhden
Mentor
Mentor

Um, how do you intend to perform this en masse when it requires a (getpoint)?

And if all you're doing is inserting the copied block definition, then why not just wblock it to somewhere in your support path and insert it?

Also, you should add code to make sure that ATTDIA and ATTREQ are proper.

John F. Uhden

0 Likes
Message 3 of 3

jpCADconsulting
Advocate
Advocate

The blocks are already inserted. All the lisp needs to do is read the X and Y values and replace the existing text in the attributes with the new values.

I may have made it more complex by explaining it the way I did.  A simplified version would be:

 

I have a whole bunch of inserted blocks with attributes and I'm trying to write a lisp that will read the X and Y values of each block's insertion point and populate the two attributes with that info.

The code I posted was the code that inserts the blocks in the first place and was really there as reference. (block names, attribute tags, etc.)

Hope that clarifies things.

0 Likes