| Author |
Message |
jlspartz
Guest
|
Posted:
Tue Jan 04, 2005 10:13 pm Post subject:
copy attribute values |
|
|
I want to be able to select a block (room tag) and have it copy the text out of the 1st text value and place it in the 14th, and then the 2nd value to the 15th. Can anyone share with me some code for doing this?
|
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 04, 2005 10:27 pm Post subject:
Re: copy attribute values |
|
|
Do you know what the tags for all of them are? Because you could do a while loop with either the "GetAttributes" of vlisp or "Entnext" of regular lisp and just search for the tag values, then do what you need to do with them.
Tim
(while (setq AttEnt (entnext Attent))
(setq AttData (entget AttEnt))
(setq TagValue (cdr (assoc 2 AttData)))
(cond
((= TagValue "Tag1")
(setq Val1 (cdr (assoc 1 AttData)))
)
((= TagValue "Tage14")
(entmod (subst (cons 1 Val1) (assoc 1 AttData) AttEnt))
)
)
)
Something like that. |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Tue Jan 04, 2005 10:42 pm Post subject:
Re: copy attribute values |
|
|
The block name is EXRMNAME.
The tag names are:
1st NameX
2nd Name
14th NameY
15th NameZ
So, NameX needs to be copied to NameY, and Name to NameZ.
|
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 04, 2005 10:55 pm Post subject:
Re: copy attribute values |
|
|
This should get you going.
Tim
(defun c:UdateValues (/ ss Ent Att AttData Val1 Val2)
(if (setq ss (ssget "x" '((2 . "EXRMNAME"))))
(while (setq Ent (ssname ss 0))
(setq Att Ent)
(while (setq Att (entnext Att))
(setq AttData (entget Att))
(cond
((= "NAMEX" (cdr (assoc 2 AttData)))
(setq Val1 (cdr (assoc 1 AttData)))
)
((= "NAME" (cdr (assoc 2 AttData)))
(setq Val2 (cdr (assoc 1 AttData)))
)
((= "NAMEY" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val1) (assoc 1 AttData) AttData))
)
((= "NAMEz" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val2) (assoc 1 AttData) AttData))
)
)
)
(ssdel Ent ss)
)
(prompt "\n No blocks name \"EXRMNAME\" in the drawing.")
)
(princ)
) |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 04, 2005 10:56 pm Post subject:
Re: copy attribute values |
|
|
Change this line
((= "NAMEz" (cdr (assoc 2 AttData)))
to
((= "NAMEZ" (cdr (assoc 2 AttData)))
Took off caps lock.
Tim |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Wed Jan 05, 2005 1:31 am Post subject:
Re: copy attribute values |
|
|
| Thanks Tim! This works great! I'm adding extra block names and fields to copy to it now. :) |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Wed Jan 05, 2005 1:49 am Post subject:
Re: copy attribute values |
|
|
You may want to add an undo feature. Glad you got it to work for you.
Tim |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Wed Jan 05, 2005 2:32 am Post subject:
Re: copy attribute values |
|
|
would that just be:
(command "undo" "begin")
and
(command "undo" "end")
? |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Wed Jan 05, 2005 2:37 am Post subject:
Re: copy attribute values |
|
|
Yup, but you might want to add an undo end to the beginning also like
(defun c:whatever ()
(command "_.undo" "_end")
(command "_.undo" "_group") ; I just use group for some reason
do your lisp here..
(command "_.undo" "_end")
); end of defun
Do it that way incase there has been and undo left open previous to someone executing the lisp routine.
Tim |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Thu Jan 06, 2005 2:05 am Post subject:
Re: copy attribute values |
|
|
Works great! But one more question if you don't mind. Here's what I got so far. How would I put in a getsel and ask the user to pick the object to grab the blockname instead so it's more dynamic?
(defun c:roomnamefillin-old (/ ss Ent Att AttData Val1 Val2 Val3)
(setvar "cmdecho" 0)
(command "undo" "end")
(command "undo" "group")
(if (setq ss (ssget "x" '((2 . "*RMNAME"))))
(while (setq Ent (ssname ss 0))
(setq Att Ent)
(while (setq Att (entnext Att))
(setq AttData (entget Att))
(cond
((= "NAMEX" (cdr (assoc 2 AttData)))
(setq Val1 (cdr (assoc 1 AttData)))
)
((= "NAME" (cdr (assoc 2 AttData)))
(setq Val2 (cdr (assoc 1 AttData)))
)
((= "####" (cdr (assoc 2 AttData)))
(setq Val3 (cdr (assoc 1 AttData)))
)
((= "NAMEY" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val1) (assoc 1 AttData) AttData))
)
((= "NAMEZ" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val2) (assoc 1 AttData) AttData))
)
((= "#####" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val3) (assoc 1 AttData) AttData))
)
)
)
(ssdel Ent ss)
)
(prompt "\n No blocks named *RMNAME in this drawing.")
)
(command "undo" "end")
(setvar "cmdecho" 1)
(princ)
) |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Thu Jan 06, 2005 2:15 am Post subject:
Re: copy attribute values |
|
|
You could do
(setq BlkEnt (entsel "\n Select block: "))
(setq BlkName (cdr (assoc 2 (entget (car BlkEnt)))))
This will error out if nothing is selected, so another way is
(if (setq BlkEnt (entsel "\n Select block: "))
(progn
(setq BlkName (cdr (assoc 2 (entget (car BlkEnt)))))
<rest of the lisp here>
)
)
Hope that helps. You could do even more checking. Like make sure that a block was selected, if not tell them, and let the select again.
Tim |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Thu Jan 06, 2005 5:14 am Post subject:
Re: copy attribute values |
|
|
Ok, I'm so close now. The only problem is that it still says "No block selected.bad argument type: lentityp nil" if nothing is selected. What do I need to change? This is what I got:
(defun c:roomnamefillin-pick (/ BlkEnt BlkName ss Ent Att AttData Val1 Val2 Val3)
(setvar "cmdecho" 0)
(command "undo" "end")
(command "undo" "group")
(setq BlkEnt (entsel "\nSelect block: "))
(if (null BlkEnt)
(princ "\nNo block selected."))
(setq BlkName (cdr (assoc 2 (entget (car BlkEnt)))))
(if (setq ss (ssget "x" (list (cons 2 BlkName))))
(while (setq Ent (ssname ss 0))
(setq Att Ent)
(while (setq Att (entnext Att))
(setq AttData (entget Att))
(cond
((= "NAMEX" (cdr (assoc 2 AttData)))
(setq Val1 (cdr (assoc 1 AttData)))
)
((= "NAME" (cdr (assoc 2 AttData)))
(setq Val2 (cdr (assoc 1 AttData)))
)
((= "####" (cdr (assoc 2 AttData)))
(setq Val3 (cdr (assoc 1 AttData)))
)
((= "NAMEY" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val1) (assoc 1 AttData) AttData))
)
((= "NAMEZ" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val2) (assoc 1 AttData) AttData))
)
((= "#####" (cdr (assoc 2 AttData)))
(entmod (subst (cons 1 Val3) (assoc 1 AttData) AttData))
)
)
)
(ssdel Ent ss)
)
)
(command "undo" "end")
(setvar "cmdecho" 1)
(princ (strcat "\nBlocks named " BlkName " in this drawing are filled in."))
(princ)
) |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Thu Jan 06, 2005 5:37 am Post subject:
Re: copy attribute values |
|
|
Real quick before I go home. If statements only allow you to do two things, so you have to use a (progn....) if you want to do more then that. So you need to change it in this fashion.
(setq BlkEnt (entsel "\nSelect block: "))
(if (null BlkEnt)
(princ "\nNo block selected.") ;<- took out the parentises so that the the other option will be valid, so if something is picked it will process the rest of the routine
(progn ; <- add this
(setq BlkName (cdr (assoc 2 (entget (car BlkEnt)))))
(if (setq ss (ssget "x" (list (cons 2 BlkName))))
<rest of code>
) ; <- end the progn
); <- end the if, since I took out that parentises at the beginning
<rest of the code after the if statement>
Hope that helps, if not I or someone will help more tomorrow.
Watch for word wrap.
Tim |
|
| Back to top |
|
 |
jlspartz
Guest
|
Posted:
Thu Jan 06, 2005 9:21 pm Post subject:
Re: copy attribute values |
|
|
It worked the way I wanted but it still output "stringp nil" which after looking at it I saw the princ string with the Blkname variable in it at the end wouldn't work because Blkname would be nil if nothing is selected so I put it before the end progn bracket and everything works great! Thanks for all your help! I learned a lot.
Jamie |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Thu Jan 06, 2005 9:36 pm Post subject:
Re: copy attribute values |
|
|
No problem, happy to help when I can.
Glad you got it to work the way you wanted it to.
Tim |
|
| Back to top |
|
 |
|
|
|
|