Jump to content

Display ATTRIBUTES as Text from multiple blocks


Organic

Recommended Posts

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,

Link to comment
Share on other sites

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 by Smirnoff
Text size now works
Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

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?

Link to comment
Share on other sites

  • 4 years later...
  • 2 years later...

excellent routine, but is it possible that the text that is extracted from the attribute has a prefix and is in a new layer?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...