View Full Version : Attribute Extraction
jim.temple
2004-12-29, 08:31 PM
I've used AutoCAD for years, but am new to AutoLISP. I have a particular function that I do quite frequently, and while it's a simple process it takes quite a bit of time. I collect tree locations with my GPS unit, and the attributes include the DBH (trunk diameter in inches) and tree species. I import this data into Cad as blocks with attributes for the DBH and Species. Open the attached file for a clearer description.
After importing the data, I draw a circle around each block insertion to represent the approximate tree crown (1' R per 1" DBH). I don't want to include this in the block, because I don't want the attributes to scale since they appear on my final plan.
So here's where I want to create a lisp routine. I want the routine to read the DBH numerical attribute and draw a circle centered on the block insertion with a radius of the attribute. Does this make sense?
I found the following routine online at the following link, and I think may be useful: http://www.afralisp.com/newsletter/code/code89.htm
This sample routine reads the attributes and displays the results on the command line. It appears to me that it stores the attribute values as a variable, I just can't figure out which one. How can I develop a similar routine to draw the circles instead of displaying the attribute values?
With a bunch of trees on each project (all with different radii), it would be useful to select blocks with a window and have the routine repeat until all the blocks have been processed. Is this possible?
Thanks in advance for any help.
--Jim
kennet.sjoberg
2004-12-30, 02:05 AM
Hi Jim !
Firs of all, I can not open Your AutoCAD Map 2005 drawing, because of that I presuppose that the block name is "MYBLOCK" and the attribute name is "MYVALUE", You have to change the code to match Your block name from "MYBLOCK" and change the attribute name from "MYVALUE".
Second, I iterate all named blocks "MYBLOCK", You do not need to select anything manually.
Third, the circles are created at current layer.
(defun c:CirOnBlock ( / SelSet Items Counter BlkName BlOrg AttName AttDxf )
(setq SelSet (ssget "x" '((-4 . "<and" )(0 . "INSERT" )(2 . "MYBLOCK" )(-4 . "and>" ))) )
(if SelSet
(progn
(setq Items (sslength SelSet ) )
(setq Counter -1 )
(repeat Items
(setq Counter (1+ Counter ) )
(setq BlkName (ssname SelSet Counter ) )
(setq BlOrg (assoc 10 (entget BlkName )) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "MYVALUE" ) (command "._circle" (cdr BlOrg ) (atof (cdr (assoc 1 AttDxf ))) ) ( ) )
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
(setq AttName BlkName )
)
)
(princ "MyBlock not found ! " )
)
(princ)
)
: ) Happy Computing !
kennet
jim.temple
2004-12-30, 02:35 PM
Wow! Thanks, Kennet! It worked great! I never thought of just putting the block name into the routine, it's much simpler than creating a selection set. I'm very much obliged for your help on my topic. What would have taken me two hours worth of work was accomplished in less than a second! There's no doubt this routine will be used on each of my projects.
I need to learn more of this LISP stuff! I'm going to research the commands you used in the routine so I can figure out how you did it. Again, thanks for your help.
--Jim
jim.temple
2004-12-30, 02:36 PM
Incidentally, what format should I save my drawings in so that most people can open it?
--Jim
kennet.sjoberg
2004-12-30, 10:16 PM
Jim, I am Happy when You are Happy, Rate Thread ; )
If You save as AutoCAD 2000 drawing probably all can read the format.
: ) Happy Computing !
kennet
LLAW3224
2005-03-08, 06:51 PM
Hi all. I was trying to use this code to create a circle coverage pattern. I noticed when I had my quadrant osnaps on it wouldnt be centered. Is there a way to turn off the osnaps within the lisp? Is there a way to make the circle come in a certain layer? Also is there a way to make a calculation based on the attribute info? for example I always want to subtract 5' from various heights that I input in an attribute is there a way to subtract the two and come up with the circle diameter we want?
scwegner
2005-03-08, 06:59 PM
Hi all. I was trying to use this code to create a circle coverage pattern. I noticed when I had my quadrant osnaps on it wouldnt be centered. Is there a way to turn off the osnaps within the lisp? Is there a way to make the circle come in a certain layer? Also is there a way to make a calculation based on the attribute info? for example I always want to subtract 5' from various heights that I input in an attribute is there a way to subtract the two and come up with the circle diameter we want?
Everything is possible. To turn off OSNAPS add this into the code when you want them turned off:
(setq oldosmode (getvar "osmode"))
(setvar "osmode" 0)
And then to turn it back on later:
(setvar "osmode" oldosmode)
To change the layer, you do pretty much the same thing.
(setq oldlayer (getvar "clayer"))
(setvar "clayer" "THE NAME OF YOUR LAYER")
blah blah blah
(setvar "clayer" oldlayer)
And yes, you can extract attribute info and calculate with it but I'm not clear on exactly what you're asking specifically.
LLAW3224
2005-03-08, 08:02 PM
I need to create a circle based on the ceiling height attribute. For example if I have a 10' ceiling I know that I need a 9' circle. If I have a 9' ceiling I need a 7' circle. What would be the best way to do this?
positiveyemi
2006-11-10, 02:54 PM
hi, keneth
Pls am also a very good user of autoCAD but not of AutoLISP. pls i deal with as built documentation by using laser scans which i linked with autocad by taking sections from the scan software - prism, exporting it to autocad. This gives me little dots which i trace to get boundary and edges of the scan images, pls if you can help me with the best lisp code that would fix this then i'll be as greatful forever.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.