Jump to content

Copy attributes data block to block different layouts!


Recommended Posts

Posted

Hi

After several years in autocad ive never really got into lisps all that much .

However I realise I should probably make the first steps into that direction.

As such I seek assistance !!

The problem:

Ive come into a new position and they are using a basic template.

Pretty much its an A4 , A3 and A1 title block all with the same attributes on separate layouts.

Owner : xxxx

Location : YYYY

Dwg number : ZZZZZ

Etc etc

Seems a bit old school and I would like to setup a SSM or other such method for ease of use in the future. But my current problem is, would it be possible to edit the A4 block and have all layouts update accordingly ?

What is the best method to acheive this .

Cheers

Posted

Trivial i know but if i can do it without manually doing it that would be great and save me typing it out multiple times which is what im doing now.

Maybe i should look up how to link a title block to a spread sheet !

Posted

You can do a generic lisp that will work with any block by using the attribute creation order, then you just enter the value attribute order and the lisp finds all occurances.

 

The example below will update every title block in the dwg for a certain attribute.

 

; changes to issued for construction
: thanks to lee mac for original code

(vl-load-com)
; 1.  Get current date in mm/dd/yy format.
(defun ddmmyy (/ x today)
    (setvar "cmdecho" 0)
    (setq x (getvar "CDATE"))                 ; get current date
    (setq today ( rtos x 2 4))                    ; convert to a string
    (setq date (strcat (substr today 7 2) "."    (substr today 5 2) "." (substr today 3 2) ))
)


(setq oldtag1 "DRAWING_STATUS") ;attribute tag name
(setq newstr1 "ISSUED FOR CONSTRUCTION")
(setq oldtag2 "REV_NO")  ;attribute tag name
(setq newstr2 "0")

(setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "DA1DRTXT"))))
(setq inc (sslength ss1))
(repeat inc      
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1) 
) ; end if
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2) 
) ; end if
) ; end for
) ;end repeat

(setq oldtag1 "REV-NO")
(setq newstr1 "0")

(ddmmyy)
(setq oldtag2 "DATE")
(setq newstr2 date)
(setq oldtag3 "AMENDMENT")
(setq newstr3 "ISSUED FOR CONSTRUCTION")

(setq ss2 (ssget "x"  '((0 . "INSERT") (2 . "REVTABLE"))))
(setq inc (sslength ss2))
(repeat inc
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss2 (setq inc (1- inc)))) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1) 
)
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2) 
)
(if (= oldtag3 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr3) 
)
)
)

(setq ss1 nil)
; (setq ss2 nil)
(princ)

Posted (edited)

Here's another example demonstrating how to synchronise attribute values between layouts:

(defun c:syncatts ( / ent enx idx lst sel )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect source block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (or (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
                       (/= 1 (cdr (assoc 66 enx)))
                   )
                   (princ "\nSelected object is not an attributed block.")
               )
           )
       )
   )
   (if (and ent
           (setq lst (LM:getattributes ent)
                 sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (strcat "~" (getvar 'ctab)))))
           )
       )
       (repeat (setq idx (sslength sel))
           (LM:setattributevalues (ssname sel (setq idx (1- idx))) lst)
       )
   )
   (princ)
)

;; Get Attributes  -  Lee Mac
;; Returns an association list of attributes present in the supplied block.
;; blk - [ent] Block (Insert) Entity Name
;; Returns: [lst] Association list of ((<Tag> . <Value>) ... )

(defun LM:getattributes ( blk / enx )
   (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
       (cons
           (cons
               (cdr (assoc 2 enx))
               (cdr (assoc 1 enx))
           )
           (LM:getattributes blk)
       )
   )
)

;; Set Attribute Values  -  Lee Mac
;; Sets attributes with tags found in the association list to their associated values.
;; blk - [ent] Block (Insert) Entity Name
;; lst - [lst] Association list of ((<tag> . <value>) ... )
;; Returns: nil

(defun LM:setattributevalues ( blk lst / enx itm )
   (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
       (if (setq itm (assoc (cdr (assoc 2 enx)) lst))
           (progn
               (if (entmod (subst (cons 1 (cdr itm)) (assoc 1 enx) enx))
                   (entupd blk)
               )
               (LM:setattributevalues blk lst)
           )
           (LM:setattributevalues blk lst)
       )
   )
)

(princ)

The above program uses functions from my Attribute Functions library.

 

The code will currently iterate over all attributed blocks residing in layouts other than the current layout, and will populate all attributes with tags matching those found in the selected source block; the program could therefore be made more efficient by including a block name filter in the ssget filter list, however, I was not aware of the block names you were using and so left it generic.

 

Lee

Edited by Lee Mac
  • Thanks 1
Posted

Another way is if you have XXXX YYYYY ZZZZ just use FIND it will replace every occurance handy also if you spell something wromng.

Posted

i find this post useful and Lee's code worked

however, if i have two attributed tags, the one is blank and the other one has a value, it fills in both tags

Posted
if i have two attributed tags, the one is blank and the other one has a value, it fills in both tags

 

Do both attributes have the same tag name within the block?

Posted
Do both attributes have the same tag name within the block?

 

yes Lee.

 

I edit my block and change its tag names.

 

its working fine now.

thanks a lot! this will be very useful

Posted

You're welcome!

 

For future reference, I would always strongly advise against the practice of using duplicate attribute tags, since the attribute tag is used to differentiate between the attributes held by a block - with duplicate attribute tags, any program must rely only on the order in which the attributes are encountered within the block.

 

Lee

Posted

thanks guysSo far ive run Lee's code and Its ask to select block . I select my A4 template (contains the values i want to duplicate)

 

Command:

ATTSYNC

Enter an option [?/Name/Select]

Select a block:

ATTSYNC block A4 Template 23-6-08? [Yes/No] :

ATTSYNC complete.

 

 

The lsp breaksdown at this point returns :

ATTSYNC block A4 Template 23-6-08? [Yes/No] :

ATTSYNC complete.

 

Lee

"

I was not aware of the block names you were using and so left it generic.

"

 

Thanks to part one of your lsp i hit "?" and got the full list

A4 Template 23-6-08, A3 Template 23-6-08, A1 Template 23-6-08, On-site design template 26-6-08

 

ill do some homework on this during the day i appreciate it! see if i cant figure it out, i hold some hope !

 

Regards

Greenuser

Posted

Its all there just need to switch language mode from plain english to programming which im far from fluent in but we must start somewhere!

Had a browse on lee mac nice site! Seems Lee is god in these parts appreciate the responses!

Also thanks bigal was aware of find and replace and its still more typing intensive then i would like.

Ideally Id like to type once and if ive used the wrong template i would appreciate not having to duplicate my typing efforts :P

Posted

One saving grace with the find function is it remembers the find and replace values saving having to type them out again which is nice as the text is pre filled for now!

Posted
thanks guysSo far ive run Lee's code and Its ask to select block . I select my A4 template (contains the values i want to duplicate)

 

Command:

ATTSYNC

Enter an option [?/Name/Select]

Select a block:

ATTSYNC block A4 Template 23-6-08? [Yes/No] :

ATTSYNC complete.

 

 

The lsp breaksdown at this point returns :

ATTSYNC block A4 Template 23-6-08? [Yes/No] :

ATTSYNC complete.

 

Lee

"

I was not aware of the block names you were using and so left it generic.

"

 

Thanks to part one of your lsp i hit "?" and got the full list

A4 Template 23-6-08, A3 Template 23-6-08, A1 Template 23-6-08, On-site design template 26-6-08

 

ill do some homework on this during the day i appreciate it! see if i cant figure it out, i hold some hope !

 

Regards

Greenuser

 

The command for my code is syncatts, not attsync (this is a standard command).

Posted

I thought so i think VBA is not installed hence no lsp files are working ! cheers lee ill get onto this.

Posted

Scrap that i loaded it from visual lisp editor and boom bang all done .

What a boss!!!!

Thanks

Posted

VBA is no longer supported, but is nothing to do with AutoLISP.

 

I'm pleased to hear you were able to run the program - you're welcome :)

 

Lee

Posted

Thank for your time Lee.

I was browsing your site and found numerous oppoutunities to become more efficient!

Ill be sure to find some begginer threads in an attempt to improve my lisp knowledge!

Posted

Excellent to hear Greenuser - good luck with your LISP studies :)

 

Lee

  • 8 years later...
Posted

Hello Lee, it is possible to syncatts of blocks from a specifics (selected) layouts?

Posted
1 hour ago, asuarez2311 said:

Hello Lee, it is possible to syncatts of blocks from a specifics (selected) layouts?

 

From specific layouts or to specific layouts? Currently the user is selecting a single block and attributes are synchronised to all other blocks in other layouts which possess the same attribute tags; are you looking to target specific layouts?

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