View Full Version : Attribute Edit
rken.laws
2009-07-03, 07:17 PM
I have been entering the same information over and over in a dwg. I need a routine where I only do it once. So far I have this.
(defun c:newfile ()
(setq name (getstring t "\nHome Owners Name?:"))
(setq unitlot (getstring t "\nUnit/Lot?:"))
(setq homephone (getstring t "\nHome Phone Number?:"))
(setq address (getstring t "\nProject Address?:"))
(setq salesperson (getstring t "\nSalesperson?:"))
(setq cellphone (getstring t "\nCell Phone Number?:"))
(setq filelocation "C:/CADD FILES/ALL IN ONE/AFTERMARKET/")
(setq newfolder (strcat filelocation name " " unitlot))
(vl-mkdir newfolder)
)
Now I want to select my title block and change the attributes to the variable I have already set. The block name is A$C3D444DC2. After that I want to save the .dwg in the directory I created above with the same name as the directory. Then I want to open a dwg that is similarly named in a different directory. I've heard that Autolisp will stop there cause a new dwg opens and the original is no longer active. Is there a work around for this?
irneb
2009-07-06, 11:45 AM
Look at some of the threads already discussing similar stuff:
http://forums.augi.com/showthread.php?t=47670&highlight=attrib+set+value
http://forums.augi.com/showthread.php?t=85226&highlight=attrib+set+value
http://forums.augi.com/showthread.php?t=64985&highlight=edit+attribute
http://forums.augi.com/showthread.php?t=60814&highlight=edit+attribute
http://forums.augi.com/showthread.php?t=90626
parkerfeldman
2009-07-06, 08:12 PM
xref the border into the drawings. we do this in my office. that is basically what you are trying to do from what i read. then you will change your border block once in the xref and use it for each drawing in the project. you may have to make different sizes for different layouts though.
rken.laws
2009-07-06, 08:19 PM
I also needed to create a directory and save the drawing, both of which are something I already typed once. I was able to create what I wanted after reading the first link from above (although I did read through the forum for a couple hours and didn't find anything near as helpful as the link). The code could use a lot of cleanup and error checking but it works for my exact issue. In case your interested.
(defun c:newfile ()
(setq name (getstring t "\nHome Owners Name?:"))
(if (= name "")(setq name "--"))
(setq unitlot (getstring t "\nUnit/Lot?:"))
(if (= unitlot "")(setq unitlot "--"))
(setq homephone (getstring t "\nHome Phone Number?:"))
(if (= homephone "")(setq homephone "--"))
(setq address (getstring t "\nProject Address?:"))
(if (= address "")(setq address "--"))
(setq salesperson (getstring t "\nSalesperson?:"))
(if (= salesperson "")(setq salesperson "--"))
(setq cellphone (getstring t "\nCell Phone Number?:"))
(if (= cellphone "")(setq cellphone "--"))
(setq filelocation "C:/CADD FILES/ALL IN ONE/AFTERMARKET/")
(setq newfolder (strcat filelocation name " " unitlot))
(setq filename (strcat newfolder "/" name " " unitlot ".dwg"))
(vl-mkdir newfolder)
(setq SelSet (ssget "_X" '((0 . "INSERT") (2 . "A$C3D444DC2" ))) ) ;; <-- Your block name
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "UNIT-LOT" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 unitlot ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "SALES_PERSON" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 salesperson ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "CELL_NUMBER" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 cellphone ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "HOME_NUMBER" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 homephone ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "ADDRESS" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 address ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(setq Ent (ssname SelSet 0 ) )
(while Ent
(setq Ent (entnext Ent ))
(if (equal (assoc 0 (entget Ent )) '(0 . "SEQEND"))
(setq Ent nil )
(if (= (cdr (assoc 2 (entget Ent ))) "CUSTOMER_NAME" ) ;; <-- Your attribute tag name
(progn
(setq EntDxf (entget Ent ) )
(setq EntDxf (subst (cons 1 name ) (assoc 1 (entget Ent )) EntDxf ) )
(entmod EntDxf )
)
)
)
)
(command "._regenall" )
(COMMAND "FILEDIA" 0)
(command "saveas" "2007" filename)
(COMMAND "FILEDIA" 1)
)
irneb
2009-07-07, 07:13 AM
Tip: you could combine all your while loops into one. Should make the code run faster. Basically the block has several ATTRIBS after it, so using entnext you step through them until you reach a SEQEND entity. While the entity is an ATTRIB you compare it's name (DXF code 2) to the relevant tag name, if matching change the string value (DXF code 1). So what I'm suggesting is to use cond to compare the tagname, this way you only step through the list of ATTRIBs once, changing as you go.
Oh! and very important ... declare (at least) the SelSet as local to the function.
rken.laws
2009-07-07, 01:03 PM
I know I definately butcher some of these routines ;) . Why do I need to declare selset more than anything else? Actually, why do you declare anything? I set every variable, usually at the beginning of every routine, so if there is something already there it gets overwriten. I'm sure you are right. I am just wondering what I am missing.
irneb
2009-07-07, 01:28 PM
See this thread: http://forums.augi.com/showthread.php?t=102333
From post no 10 onwards, explains the reasons for declaring vars as local to a defun. Global vars are only to be used to store persistent info between defun calls.
rken.laws
2009-07-07, 02:38 PM
That was helpful. I could see myself going over the selection set limit in the future. Not with one routine, but with the dozens used through out the day. And if the error wasnt very clear I would never figure it out.
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.