Organic Posted February 13, 2011 Posted February 13, 2011 I have a CAD file with property parcels in it. It has come from an external contractor and from a GIS program of sort sort I believe. If you click each 'boundary'/land piece, it is a block/object (not a proxy graphic) and in the properties pane window, there are attributes that has the lot number, the lot area, parcel number, other info etc in it. Each block is irregular and different, i.e. they are not all the same rectangle block repopulated, they are different blocks. I don't know much about attributes in AutoCad althoguh after reading about them, is there some way to edit an attribute (make it not 'invisible' and to increase the text size of its display) when it is already in several hundred different blocks? The only way I could work out how to do it was to go into every block and do it. I also tried using the ATTSYNC command to update blocks with attributes although that requires me to individually select each block/give each blocks name. I also tried using the DATA EXTRACTION wizard and was able to extract the attributes into a table/excel file, although that is not really good enough as I need the attributes displayed over the CAD data so you can see what parcel of land the attributes are referring to. Or does anyone know of a better way or a lisp command to do this? Clicking each block/boundary/land unit to place a label over it would also be okay. I just don't want to have to manually create the labels from reading the property pane, there must surely be a better way, Quote
Smirnoff Posted February 13, 2011 Posted February 13, 2011 (edited) Very, very fast 'on the fly' coding, but seems it works. If you need also add Constant attributes tell me. (defun c:attmt(/ aDoc aSp oSiz bSet aLst cLst tStr nTxt bCtr Tags TextInsert) [color="#0000ff"] ; ***************************************************************************** ; ADJUSTMENTS ; ; (Modify it to adjust for your own requirements) ; ; ***************************************************************************** (setq Tags T) ; - if T add tags to MText if Nil not (setq TextInsert T) ; - Text insertion point. If T center of Bounding Box ; of block, if Nil Block insertion point. ; ******************************* END ADJUSTMENTS *****************************[/color] (vl-load-com) (defun GetBoundingCenter (vlaObj / blPt trPt cnPt) (vla-GetBoundingBox vlaObj 'minPt 'maxPt) (setq blPt(vlax-safearray->list minPt) trPt(vlax-safearray->list maxPt) cnPt(vlax-3D-point (list (+(car blPt)(/(-(car trPt)(car blPt))2)) (+(cadr blPt)(/(-(cadr trPt)(cadr blPt))2)) 0.0 ); end list ); end vlax-3D-point ); end setq ); end of GetBoundingCenter (if(not attmt:Size)(setq attmt:Size(getvar "TEXTSIZE"))) (setq oSiz attmt:Size attmt:Size(getreal(strcat "\nText size <"(rtos attmt:Size)">: "))) (if(null attmt:Size)(setq attmt:Size oSiz)) (setq aDoc(vla-get-ActiveDocument(vlax-get-acad-object))) (if(= 1(vla-get-ActiveSpace aDoc)) (setq aSp(vla-get-ModelSpace aDoc)) (setq aSp(vla-get-PaperSpace aDoc)) ); end if (princ "\n<<< Select text to extract attributes to MText >>> ") (if(setq bSet(ssget '((0 . "INSERT")))) (progn (foreach b(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex bSet)))) (setq aLst '() tStr "") ; end setq (if TextInsert (setq bCtr(GetBoundingCenter b)) (setq bCtr(vla-get-InsertionPoint b)) ); end if (if(= :vlax-true(vla-get-HasAttributes b)) (progn (setq aLst (mapcar '(lambda (a) (list (vla-get-TagString a) (vla-get-TextString a))) (vlax-safearray->list (vlax-variant-value(vla-GetAttributes b))))) (foreach i(reverse aLst) (setq tStr(strcat tStr(if Tags(strcat(car i) ": ")"")(last i)"\\P")) ); end foreach (if(/= "" tStr) (progn (setq nTxt(vla-AddMText aSp bCtr (* attmt:Size 30.0) tStr)) (vla-put-Height nTxt attmt:Size) ); end progn ); end if ); end progn ); end if ); end foreach (vla-EndUndoMark aDoc) ); end progn ); end if (princ) ); end of c:attmt Edit. Size of MText now works. Edited February 13, 2011 by Smirnoff Text size now works 1 Quote
Organic Posted February 13, 2011 Author Posted February 13, 2011 Thanks, that seems to do exactly what I wanted it to! Quote
Smirnoff Posted February 13, 2011 Posted February 13, 2011 Ok. If need I can to add export to *.CSV file. You can open it in MS Excel. Quote
troggarf Posted April 25, 2011 Posted April 25, 2011 Hey Smirnoff, This is a great routine. Can you please adjust this to place the mtext or even dtext on top of the Attribute so that it has the same text size? I am amazed at how few routines there are that turn attributes in a block to text... So this is great. Thanks Quote
Ryder76 Posted April 25, 2011 Posted April 25, 2011 Ok - I'm curious. Wouldn't 'Explode attributes to text' have done the same thing? Quote
troggarf Posted April 25, 2011 Posted April 25, 2011 Ok - I'm curious. Wouldn't 'Explode attributes to text' have done the same thing? I wish it worked but no it doesn't work for this task. The express tool BURST explodes a perfectly good block and leaves the attribute tag value visible instead of the attribute prompt. If I have a dynamic block and use burst on it I ruin my block. i wish there was a BURST without ruining the block Quote
rubyfire Posted August 13, 2012 Posted August 13, 2012 Is there a way you could edit this to allow me to the attributes from the block and/or the ones I do not want to be output to text? I am pretty good with php and this language looks somewhat similiar. I'd be extremely grateful. Quote
irneb Posted August 13, 2012 Posted August 13, 2012 Is there a way you could edit this to allow me to the attributes from the block and/or the ones I do not want to be output to text? I am pretty good with php and this language looks somewhat similiar. I'd be extremely grateful.Yes it's very possible to modify the code. This language is called AutoLisp (a very cut-down subset of the ubiquitous high-level language known as Lisp). It's made it's way into ACad in the '80s from XLisp. If you're interested there's an entire forum folder dedicated to its use in acad (and others): http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP-Visual-LISP-amp-DCL As for your requested modification there might be various ways of going abut it. If it's always the same tag name, you might simply add a check in an if statement inside the (foreach i (reverse aLst) ... loop so it only adds the attribute if matching one or more tagname(s). Seeing as you've already done some programming (though PHP is a bit specialist), you might be able to grasp it for yourself. If you want to attempt this for yourself, there are many resources with example coding to teach you lisp - just be warned, after you learn to Lisp you find all other languages to be rather pathetic in comparison (even PHP/Java/JavaScript/VB/C++/C#). At least that was my experience. You might also find someone to help you in the above forum (or many others as well), or if lucky to do the mod for you. BTW, does your moniker mean you use the Ruby language? Quote
rubyfire Posted August 13, 2012 Posted August 13, 2012 Nahh man no Ruby Language at this point. I actually started with Java under Ted Kosan in high school, played around with C++ also in high school, Visual Basic, and then I got out of it all together due to a heavy drug addiction. I cleaned up and threw myself into telecommunications and am now a telecom engineer. I went unemployed for awhile and started Rubyfire Designs http://rubyfiredesigns.com getting into PHP due to the fact that is what Wordpress is based off of. I have found myself back in telecom as finding work to support a family is rough as freelancer until you've got your name out there. I still build sites and am actually developing an uber cool Project Management Tool for one of the companies I contract from. My last name is 'Ruby' also lol so you would think I would have gotten into Ruby coding by now eh? I do plan on taking a fundamentals course on NetTuts+ in the coming year. Thanks for the link bro. I'll be looking into that because otherwise the attachments on a 100 pole run means typing each one into a damned text-block. The simple conditional check is what I thought I might need. **** you know more about me now than most. Quote
Dustyg Posted January 3, 2014 Posted January 3, 2014 I really like this routine. One thing I was wondering was why it placed the attribute info from the last to the first. Can the routine be changed to place the first attribute to the last attribute? Does that make sense? Quote
ktbjx Posted May 10, 2018 Posted May 10, 2018 http://www.cadtutor.net/forum/showthread.php?56833-Display-ATTRIBUTES-as-Text-from-multiple-blocks&p=384993&viewfull=1#post384993 can you edit this to get an specific attribute?? like Hole_ID??? Quote
victor.romero Posted April 6, 2021 Posted April 6, 2021 excellent routine, but is it possible that the text that is extracted from the attribute has a prefix and is in a new layer? Quote
Nikon Posted August 11 Posted August 11 On 2/13/2011 at 12:22 PM, Smirnoff said: (defun c:attmt(/ aDoc aSp oSiz bSet aLst cLst tStr nTxt bCtr Tags TextInsert) [color="#0000ff"] ; ***************************************************************************** ; ADJUSTMENTS ; ; (Modify it to adjust for your own requirements) ; ; ***************************************************************************** (setq Tags T) ; - if T add tags to MText if Nil not (setq TextInsert T) ; - Text insertion point. If T center of Bounding Box ; of block, if Nil Block insertion point. ; ******************************* END ADJUSTMENTS *****************************[/color] (vl-load-com) (defun GetBoundingCenter (vlaObj / blPt trPt cnPt) (vla-GetBoundingBox vlaObj 'minPt 'maxPt) (setq blPt(vlax-safearray->list minPt) trPt(vlax-safearray->list maxPt) cnPt(vlax-3D-point (list (+(car blPt)(/(-(car trPt)(car blPt))2)) (+(cadr blPt)(/(-(cadr trPt)(cadr blPt))2)) 0.0 ); end list ); end vlax-3D-point ); end setq ); end of GetBoundingCenter (if(not attmt:Size)(setq attmt:Size(getvar "TEXTSIZE"))) (setq oSiz attmt:Size attmt:Size(getreal(strcat "\nText size <"(rtos attmt:Size)">: "))) (if(null attmt:Size)(setq attmt:Size oSiz)) (setq aDoc(vla-get-ActiveDocument(vlax-get-acad-object))) (if(= 1(vla-get-ActiveSpace aDoc)) (setq aSp(vla-get-ModelSpace aDoc)) (setq aSp(vla-get-PaperSpace aDoc)) ); end if (princ "\n<<< Select text to extract attributes to MText >>> ") (if(setq bSet(ssget '((0 . "INSERT")))) (progn (foreach b(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex bSet)))) (setq aLst '() tStr "") ; end setq (if TextInsert (setq bCtr(GetBoundingCenter b)) (setq bCtr(vla-get-InsertionPoint b)) ); end if (if(= :vlax-true(vla-get-HasAttributes b)) (progn (setq aLst (mapcar '(lambda (a) (list (vla-get-TagString a) (vla-get-TextString a))) (vlax-safearray->list (vlax-variant-value(vla-GetAttributes b))))) (foreach i(reverse aLst) (setq tStr(strcat tStr(if Tags(strcat(car i) ": ")"")(last i)"\\P")) ); end foreach (if(/= "" tStr) (progn (setq nTxt(vla-AddMText aSp bCtr (* attmt:Size 30.0) tStr)) (vla-put-Height nTxt attmt:Size) ); end progn ); end if ); end progn ); end if ); end foreach (vla-EndUndoMark aDoc) ); end progn ); end if (princ) ); end of c:attmt Please tell me how to change the code to output only one attribute with the tag cell_4 F3 Quote
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.