tmelancon Posted April 30, 2014 Share Posted April 30, 2014 When I generate a new drawing it creates a text file with information. Autocad updates text automatically from this file using specific layers that the string is on in the drawing. Depending on what layer a string is on, that will determine what information it is updated with. With that being said, it will not update ATTRIBUTES within a BLOCK. Can someone help. I am willing to discuss and assist with figuring this out. I will be automating some information for my titleblocks and ALL of our titleblocks are blocked with attributes. Here is the code used to update the info (defun uinfo () (princ "\nUpdating Drawing Information...") (if (= found 1) (progn (setq dummy (read-line infile)) (setq desc (read dummy)) (setq dummy (read-line infile)) (setq drawing (read dummy))) (progn (setq desc '(1 . "- NEW EQUIPMENT -")) (setq drawing '(1 . "- UNASSIGNED -")))) (setq sset (ssget "X" (list (cons 0 "TEXT") (cons 8 "TITLE")))) (setq lp 0) (while (< lp (sslength sset)) (setq ent (entget (ssname sset lp))) (setq entinfo (cdr (assoc 1 ent))) (if (= (substr entinfo 1 4) "Desc") (entmod (subst desc (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "Draw") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 3) "Dwg") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "DESC") (entmod (subst desc (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "DRAW") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 3) "DWG") (entmod (subst drawing (assoc 1 ent) ent))) (setq lp (1+ lp))) (setq sset nil) (setq lp nil) (setq sset (ssget "X" (list (cons 0 "TEXT") (cons 8 (strcat tcircuit "-EQMRK"))))) (setq lp 0) (if (/= sset nil) (while (< lp (sslength sset)) (setq ent (entget (ssname sset lp))) (setq entinfo (cdr (assoc 1 ent))) (if (= (substr entinfo 1 4) "Desc") (entmod (subst desc (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "Draw") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 3) "Dwg") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "DESC") (entmod (subst desc (assoc 1 ent) ent))) (if (= (substr entinfo 1 4) "DRAW") (entmod (subst drawing (assoc 1 ent) ent))) (if (= (substr entinfo 1 3) "DWG") (entmod (subst drawing (assoc 1 ent) ent))) (setq lp (1+ lp)))) (princ "Done.") (prin1)) Here is the actual routine used to provoke the update of all information in the drawing based on its respective layer. (defun C:UPDATE () (setvar "CMDECHO" 0) (setvar "MENUCTL" 0) ;; (command "._snap" "0.03125") (command "plinewid" "0.0") (if (null filename) (setq filename (getstring "\nPath and name of update file: "))) (if (null tcircuit) (progn (C:EQUIP2)) (progn (makenames tcircuit) (checklayers tcircuit))) (if (null tcircuit) (progn (princ "\nCurrent name has not been established") (princ "\nplease type EQUIP and establish current equip. or make new")) (progn (openfile) (seek-tcircuit) (if (= (getvar "userr1") 0.0) (setvar "userr1" 3.0)) (if (= (getvar "userr2") 0.0) (setvar "userr2" 1.0)) (if (ssget "X" (list (cons 8 "CIRCUIT-INFO") (cons 0 "TEXT"))) (uinfo) (repeat 2 (read-line infile))) (if (ssget "X" (list (cons 8 "TITLE") (cons 0 "TEXT"))) (udates) (repeat 2 (read-line infile))) ;; (uinfo) ;; (udates) (if (= found 1) ;; (progn (udp) (uext) (uldar) (uvalve)) (princ "\nNO INFORMATION TO UPDATE")) (closefile))) (command "._-layer" "s" PIPING "") (princ)) I need to add to the code so that it will update the defined text strings of attributes within a block. IF you have any input or any questions I would appreciate everything. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 1, 2014 Share Posted May 1, 2014 Here is an example of changing values in a title block, uses VL rather than ent's. As implied GET a value or PUT a new value. Uses attribute tag name to work out which one to change. ; 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) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted May 15, 2014 Author Share Posted May 15, 2014 Is there a piece of code I can add to my existing code that just tells it to search in Blocks and attributes instead of just plain text. Thanks Quote Link to comment Share on other sites More sharing options...
ymg3 Posted May 15, 2014 Share Posted May 15, 2014 There is a slew of them you may use that one by Lee Mac ;; 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 ) (while (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (and (setq itm (assoc (cdr (assoc 2 enx)) lst)) (entmod (subst (cons 1 (cdr itm)) (assoc 1 enx) enx)) ) (entupd blk) ) ) ) This is for regular block. ymg Quote Link to comment Share on other sites More sharing options...
neophoible Posted May 15, 2014 Share Posted May 15, 2014 Perhaps it's worth asking how familiar you are with attributes and their tags. Maybe you have several titleblock blocks per drawing file? Do you need to update these based on layer as well? Quote Link to comment Share on other sites More sharing options...
tmelancon Posted May 16, 2014 Author Share Posted May 16, 2014 Thanks for chiming in guys. I'm a quite familiar with Attributes and their tags as we work with them on a daily basis. We have .dwg templates based on how many sheets the drawing will have (1SHT, 2SHT, 3SHT), but each template contains the same titleblock with defined attributes/tags. (i.e. DRAWBY, SURVEYBY, DRAWDATE, SURVEYDATE, CLIENT, FACILITY) My current routine retrieves information from a .dat file and will update the regular text on a specific layer HOWEVER it will not search in a block that has attributes. The code is posted above. Quote Link to comment Share on other sites More sharing options...
ymg3 Posted May 16, 2014 Share Posted May 16, 2014 tmelancon, I have a little trouble following you. As it is all the code you posted never ever even look for a block, it is text only. Now if you have a title block or many title blocks , you would use another routine to get whatever value is in the attributes of the block. That routine would be LM:getattributevalues. It can be found on Lee's site. If you want to update the block attributes from data that is in a file the one I posted above LM:setattributevalues would set all attributes that you would supply in a list for a given block to their new value. All you need to do is having a routine that will put together a dotted list of '((tag . value)(.....)) then call the above with : (setq attriblst '("DRAWBY" "SURVEYBY" "DRAWDATE" "CLIENT" "FACILITY") valuelst '("TM" "JB" "2014/05/16" "OUR BEST CLIENT" "WAREHOUSE #2") updatelst (mapcar '(lambda (a b) (cons a b)) attriblst valuelst) ) ( LM:setattributevalues "TitleBlock Name" updatelst) Quote Link to comment Share on other sites More sharing options...
pBe Posted May 17, 2014 Share Posted May 17, 2014 Is there a piece of code I can add to my existing code that just tells it to search in Blocks and attributes instead of just plain text. Thanks Will that be "to work with ATTRIBUTES and/or TEXT? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.