Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I copy an attribute tag value and paste it to a new block tag value?

16 REPLIES 16
Reply
Message 1 of 17
joshd0000
516 Views, 16 Replies

How do I copy an attribute tag value and paste it to a new block tag value?

I am basically just replacing a block with an updated block. It is an other wise identilcal block that consists of just one AttDef object so there is only one attribute to edit. What is changing is the block name and all the AttDef tag names. How do get the current block "dateblk2" attribute tag value and then insert that tag value for the new insert of the new block "version".
Thank you for your help!
16 REPLIES 16
Message 2 of 17
EC-CAD
in reply to: joshd0000

Untested. Something like this.
At Command prompt, do:
(load "revisions")
Then, just type in GO

Your new block must be located in a support folder..
Assumes only (1) attribute.

Give it a whirl

Bob
Message 3 of 17
joshd0000
in reply to: joshd0000

I can not download the file. Can you just paste the lisp in the message?
thank you.
Josh
Message 4 of 17
EC-CAD
in reply to: joshd0000

Sure, here it is:
(defun C:GO ( / ss C ent elist ip atr Val )
(setq old_block "dateblk2")
(setq new_block "version")

;;
;; define dxf function
;;
(defun dxf (code elist)
(cdr (assoc code elist)); Find association pair, strip first element
); end function
;;

;; Get old Block(s)
(setq ss nil)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
(setq C 0)
(repeat (sslength ss)
(setq ent (ssname ss C)); entity
(setq elist (entget ent)); entity list
(setq ip (cdr (assoc 10 elist))); ip
(setq atr (entget (entnext (dxf -1 ent)))); next entity is Attrib
(setq Val (cdr (assoc 1 atr))); get Attr Value
(command "_erase" ent "")
(command ".insert" new_block ip "1" "1" "0" Val)
(command "_regen")
(setq C (+ C 1))
); repeat
); progn
); if
;;
(princ)
); function


Bob
Message 5 of 17
joshd0000
in reply to: joshd0000

When i tried to rund the lisp i got this error.
Command: ap APPLOAD FF.lsp successfully loaded.


Command:
Command:
Command: go ; error: bad argument type: listp Entity name: 7ac7e7a8

I can not identify what is going wrong aside from it seems that one of the setq lines is not running correctly.
any ideas? Message was edited by: joshd0000
Message 6 of 17
EC-CAD
in reply to: joshd0000

Josh,
I'll check it.
:)
Bob
Message 7 of 17
EC-CAD
in reply to: joshd0000

Ok, I renamed the revisions.lsp to be ff.lsp, and I get:
Command: (load"/acad/ff")
C:GO

Command: go

Which seems to be right.. since I don't have the blocks..

Bob
Message 8 of 17
EC-CAD
in reply to: joshd0000

If you attach a .dwg with (both) blocks.. I can test it
further.

Bob
Message 9 of 17
EC-CAD
in reply to: joshd0000

Change:
(setq atr (entget (entnext (dxf -1 ent)))); next entity is Attrib
To be:
(setq atr (entget (entnext (dxf -1 elist)))); next entity is Attrib

Probably the fault.

Bob
Message 10 of 17
joshd0000
in reply to: joshd0000

I've got it working. Thank you very much Bob. One question. Can I change the 3rd line of this lisp as follows:

Change from:
(defun C:GO ( / ss C ent elist ip atr Val )
(setq old_block "dateblk2")
(setq new_block "version")

Change to:
(defun C:GO ( / ss C ent elist ip atr Val )
(setq old_block "dateblk2")
(setq new_block "C:/Program Files/AutoCAD 2005/Ref/version.dwg")

The second block, the new one will not be in the dwg (that what the other problem why it was not working). So I need to insert it before the setq lines or just do this. Let me know. Thanks for the help Bob!
Message 11 of 17
joshd0000
in reply to: joshd0000

Ok what I just asked works. Two more questions.

1. Can make this entire lisp an "IF" function. So it only runs "IF" it finds the old block "dateblk2". I will be running this on many files and I only want this function to run "IF" the old block "dateblk2" is in the dwg (replaced by new block "version"). So how do I do that?

2. Can I run this function in lisp FF if both lisp files are loaded into AutoCAD and in the support path folders? Do I just put it into the lisp FF as a line that is written as (c: JJ) ?

lisp in question below:

(defun C:JJ ( / ss C ent elist ip atr Val )
(setq old_block "dateblk2")
;;;;;;;; I WANT THE REST TO HAPPEN ONLY IF THIS FUNCTION
;;;;;;;; FINDS THE BLOCK ABOVE IN THE DRAWING
;;;;;;;; HOW DO I DO THAT

(setq new_block "S:/Architecture/DWG/REF/version.dwg")

;;
;; define dxf function
;;
(defun dxf (code elist)
(cdr (assoc code elist)); Find association pair, strip first element
); end function
;;

;; Get old Block(s)
(setq ss nil)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
(setq C 0)
(repeat (sslength ss)
(setq ent (ssname ss C)); entity
(setq elist (entget ent)); entity list
(setq ip (cdr (assoc 10 elist))); ip
(setq atr (entget (entnext (dxf -1 elist)))); next entity is Attrib
(setq Val (cdr (assoc 1 atr))); get Attr Value
(command "_erase" ent "")
(command ".insert" new_block ip "9" "9" "0" Val)
(command "_regen")
(setq C (+ C 1))
); repeat
); progn
); if
;;
(princ)
); function
Message 12 of 17
EC-CAD
in reply to: joshd0000

Yes, the process will only run when it finds the
'old block' .. by checking for that particular 'Insert'..
e.g.
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
........
The (setq ss (ssget "x" .. can only 'return' a value..when
it finds an Insert named (old_block).. and then,
the (if ss (progn..
part checks if ss is nil (or not).. before continuing.

You are Welcome.
:)
Cheers.
Bob
Message 13 of 17
EC-CAD
in reply to: joshd0000

Answer to 2nd question.
If you want to 'batch' this, just add:
(c:jj)
to the very bottom of the file, and save it.
If you want to just load it, and use the JJ at the
command prompt, then leave as is, and in your
acaddoc.lsp, add:
(load"jj.lsp")
..
then, for each open drawing, the function JJ will be available.

Bob
Message 14 of 17
joshd0000
in reply to: joshd0000

Ok, so will this work? I have an FF lisp that is run and in that lisp it runs the JJ lisp, all as discussed here. In the JJ lisp I added the IF function that first looks for the old_block to run the function. Do I need to add two closing paranthasese at the end of the JJ lisp? That would be to close this line where to paranthasese were added (if ss (progn. Also, did I add the IF function lines in the correct location? thank you.

(defun c:FF(/ dn)
(c:JJ)
(setq ss_2 (ssget "x"
'((2 . "item")))
)
(command "erase" ss_2 "")
(setq DN (vl-filename-base (getvar "dwgname")))
(command "insert" "item" "0,0" "1" "1" "0" DN "qsave")
(command "-attedit" "n" "n" "item" "" "" ".dwg" "")
(command "-layer" "s" "0" "")
(COMMAND "ZOOM" "E")
(COMMAND "-LAYER" "A" "S" "ONE" "" "" "")
(COMMAND "-LAYER" "T" "**" "")
(COMMAND "-LAYER" "U" "**" "")
(COMMAND "-LAYER" "ON" "**" "")
(if (setq ss (ssget "x" '((0 . "HATCH,SOLID"))))
(command "_.draworder" ss "" "_b")
)
(COMMAND "-LAYER" "U" "**" "")
(COMMAND "-LAYER" "A" "R" "ONE" "" "")
(COMMAND "-LAYER" "A" "D" "ONE" "" "")
(COMMAND "LAYOUT" "D" "Continental")
(COMMAND "LAYOUT" "T" "S:/Architecture/Autocad Setup/Continental.dwt" "Continental")
(COMMAND "REGEN")
(COMMAND "QSAVE")
)

*************************************************************

(defun C:JJ ( / ss C ent elist ip atr Val )
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
(setq old_block "dateblk2")
(setq new_block "S:/Architecture/DWG/REF/version.dwg")
;;
;; define dxf function
;;
(defun dxf (code elist)
(cdr (assoc code elist)); Find association pair, strip first element
); end function
;;

;; Get old Block(s)
(setq ss nil)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
(setq C 0)
(repeat (sslength ss)
(setq ent (ssname ss C)); entity
(setq elist (entget ent)); entity list
(setq ip (cdr (assoc 10 elist))); ip
(setq atr (entget (entnext (dxf -1 elist)))); next entity is Attrib
(setq Val (cdr (assoc 1 atr))); get Attr Value
(command "_erase" ent "")
(command ".insert" new_block ip "9" "9" "0" Val)
(command "_regen")
(setq C (+ C 1))
); repeat
); progn
); if
;;
(princ)
); function
Message 15 of 17
EC-CAD
in reply to: joshd0000

You don't need to 'add' the (if ss (progn.. in the
2nd function FF.
As I mentioned before, the check for the old blockname
is covered in JJ function. All you need is to have it loaded,
and call it from FF function.
Like this:

(defun c:FF(/ dn)
(if (not C:JJ)(load "jj.lsp"))
(C:JJ); call the other function
(setq ss_2 (ssget "x"
'((2 . "item")))
)
(command "erase" ss_2 "")
(setq DN (vl-filename-base (getvar "dwgname")))
(command "-insert" "item" "0,0" "1" "1" "0" DN "qsave")
(command "-attedit" "n" "n" "item" "" "" ".dwg" "")
(command "-layer" "s" "0" "")
(COMMAND "ZOOM" "E")
(COMMAND "-LAYER" "A" "S" "ONE" "" "" "")
(COMMAND "-LAYER" "T" "**" "")
(COMMAND "-LAYER" "U" "**" "")
(COMMAND "-LAYER" "ON" "**" "")
(if (setq ss (ssget "x" '((0 . "HATCH,SOLID"))))
(command "_.draworder" ss "" "_b")
)
(COMMAND "-LAYER" "U" "**" "")
(COMMAND "-LAYER" "A" "R" "ONE" "" "")
(COMMAND "-LAYER" "A" "D" "ONE" "" "")
(COMMAND "LAYOUT" "D" "Continental")
(COMMAND "LAYOUT" "T" "S:/Architecture/Autocad Setup/Continental.dwt" "Continental")
(COMMAND "REGEN")
(COMMAND "QSAVE")
)

;;********************************************************** ***

(defun C:JJ ( / ss C ent elist ip atr Val )
;;
(setq old_block "dateblk2")
(setq new_block "S:/Architecture/DWG/REF/version.dwg")
;;
;; define dxf function
;;
(defun dxf (code elist)
(cdr (assoc code elist)); Find association pair, strip first element
); end function
;;

;; Get old Block(s)
(setq ss nil)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 old_block))))
;;
(if ss
(progn
(setq C 0)
(repeat (sslength ss)
(setq ent (ssname ss C)); entity
(setq elist (entget ent)); entity list
(setq ip (cdr (assoc 10 elist))); ip
(setq atr (entget (entnext (dxf -1 elist)))); next entity is Attrib
(setq Val (cdr (assoc 1 atr))); get Attr Value
(command "_erase" ent "")
(command ".insert" new_block ip "9" "9" "0" Val)
(command "_regen")
(setq C (+ C 1))
); repeat
); progn
); if
;;
(princ)
); function

Bob
Message 16 of 17
joshd0000
in reply to: joshd0000

Thanks for all your help Bob! It's all working now. Automation, it's a wonderful thing.
Message 17 of 17
EC-CAD
in reply to: joshd0000

You are Welcome.!
Cheers,
Bob

http://www.bobscadshop.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost