akgeo Posted October 1, 2013 Posted October 1, 2013 (edited) Hi everyone, so I have been reading this forum for years but have not joined until now. I am going through a long complex series of autolisps and so far have been able to get everything working from stuff cobbled together from the internet and some colleagues. Now I'm stumped on something relatively simple. I am looking to get the entity information for just the data from an app. I have used Lee Mac's awesome entity list lisp to get all of the data but I only care about the second line starting after "Facesamp" ie (1000 . "1003101") for all of the files I will be processing. here is what the entire elist shows ( (-1 . <Entity name: 7ffff7c7930>) (0 . "LWPOLYLINE") (5 . "18B") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ffff7c7c90>) (102 . "}") (330 . <Entity name: 7ffff7c19f0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 18) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 -3.29016 -5.0761) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -5.11682 -4.97795) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -4.39008 -2.89717) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -4.05618 -0.384532) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.91869 1.14661) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -4.31152 3.24702) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -2.20987 3.22739) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -2.68127 2.20663) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.34642 0.766316) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.47677 0.0853092) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.7277 -0.638116) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.76631 -1.17827) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.46711 -1.73772) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.07141 -2.0078) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -2.83282 -2.4172) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -2.79641 -2.99942) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -2.92433 -3.82089) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 -3.29016 -5.0761) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0) (-3 ( "FACESAMP" (1002 . "{") (1000 . "1003101") (1002 . "}") ) ) ) Long story short what I'm trying to do is to run through all of the drawings I've made and color the polylines and hatch them according to numbers in a csv file. So far I've gotten a lisp to create new layers with unique colors, gotten a lisp to work for creating a hatch pattern in each layer, gotten a lisp to work that reads the csv file correctly and parses it as numbers (the second column of which corresponds to the second part of the "(1000 . "1003101")". So now I'm slowly working my way towards figuring out how to read the entity information and then associate the csv information with it. any ideas? Thank you everyone, this forum has been a huge source of information for me! Scott Edited October 2, 2013 by akgeo Quote
Lee Mac Posted October 1, 2013 Posted October 1, 2013 Welcome to CADTutor Scott, I'm pleased that you found my Entity List utility of use The following code will retrieve the value 1003101 as you require from your entity DXF data: (cdr (assoc 1000 (cdadr (assoc -3 (entget [color=green]<entity>[/color] '("FACESAMP")))))) Assuming is the entity name of the object in question. Quote
akgeo Posted October 1, 2013 Author Posted October 1, 2013 (edited) wow thank you! You've been a huge help to me in starting to learn autolisp! I'll give that a shot. It looks like the entity name changes for each polyline- I usually have between 3 and 10 closed polylines per drawing- how do I automate it to look at all of the polylines? (I have an image file, polylines, text and block references. the only objects that are polylines are the ones I care to get info for) Frustratringly I had a autolisp that worked in autocad 2000i but for some reason stopped working, which is why I'm attempting to rebuild it from scratch. It fails right after the beginning of the lisp. I've attached the part leading up to where it fails. (defun c:addnsr (fn) ; Extend entity data is associated with FACESAMP app (setq rname "FACESAMP") (regapp rname) (setq dr "") (setq ff (strcat dr fn)) (setq f (open ff "r")) ;Open filename passed as parameter (setq a (list 0 0)) (setq b (list -999 0)) (setq samplist (list a b)) Edited October 2, 2013 by akgeo Quote
akgeo Posted October 2, 2013 Author Posted October 2, 2013 (edited) ; error: too few arguments is the error I get. Here's the whole thing. I have broken it into smaller and smaller parts to see where it fell apart and it was the above code. (defun addopt (fn) ; Extend entity data is associated with FACESAMP app (setq rname "FACESAMP") (regapp rname) (setq dr "") (setq ff (strcat dr fn)) (setq f (open ff "r")) ;Open filename passed as parameter (setq a (list 0 0)) (setq b (list -999 0)) (setq samplist (list a b)) (while (setq l (read-line f)) ;set variables for reading data from a csv file ;which contains the fields sample,Au_Opt (setq linelen (strlen l)) ;line length (setq cchar (substr l 1 1)) ;current character (setq fchar 1) ;first character of field (setq ccount 1) ;current count (while (<= ccount linelen) ;read through the current line and find the commas (setq cchar (substr l ccount 1)) (if (= cchar ",") (progn ;charlen is the field length (setq charlen (- ccount fchar)) (setq samp (substr l fchar charlen)) (setq fchar (+ 1 ccount)) ) ;end progn ) ;end if ;leading spaces are removed (if (= cchar " ") (setq fchar (+ 1 ccount)) ) ;increment character counter (setq ccount (+ 1 ccount)) ) ;end while, character reader (setq Au_Opt (substr l fchar linelen)) (setq samp (atoi samp)) (setq Au_Opt (atoi Au_Opt)) (setq newlist (list samp Au_Opt)) (setq samplist (cons newlist samplist )) ); end of WHILE (setq l.. (close f) ; select polyline, pick null to end (setq sset (ssget "X" '((0 . "LWPOLYLINE")))); select all LWpolyline in dwg (command "layer" "n" "LT0" "n" "0-0.08" "n" "0.08-0.15" "n" "0.15-0.30" "n" "0.30-0.50" "n" "0.50-1.00" "n" "GT1.00" "") (command "layer" "co" "9" "LT0" "co" "5" "0-0.08" "co" "4" "0.08-0.15" "co" "3" "0.15-0.30" "co" "2" "0.30-0.50" "co" "1" "0.50-1.00" "co" "6" "GT1.00" "" ) (command "layer" "LW" "0.35" "LT0" "LW" "0.35" "0-0.08" "LW" "0.35" "0.08-0.15" "LW" "0.35" "0.15-0.30" "LW" "0.35" "0.30-0.50" "LW" "0.35" "0.50-1.00" "LW" "0.35" "GT1.00" "") (setq entnum 0); Initilize entnum for while loop (while (setq p (ssname sset entnum)) (setq elist (entget p (list "*"))); includes xdata for all regd apps (if (assoc -3 elist) (progn (setq sampnum (cdr (nth 2 (nth 1 (assoc -3 elist)))));Get sampleID from elist (setq samp (atoi sampnum)) (setq Au_Opt (car (cdr (assoc samp samplist)))) (setq layer (cons 8 "LT0"));Default LAYER (if (> Au_Opt 0) (progn (setq layer (cons 8 "0-0.08")))) (if (> Au_Opt 0.08) (progn (setq layer (cons 8 "0.08-0.15")))) (if (> Au_Opt 0.15) (progn (setq layer (cons 8 "0.15-0.30")))) (if (> Au_Opt 0.30) (progn (setq layer (cons 8 "0.30-0.50")))) (if (> Au_Opt 0.50) (progn (setq layer (cons 8 "0.50-1.00")))) (if (> Au_Opt 1.00) (progn (setq layer (cons 8 "GT1.00")))) (setq ed (entget p)) (setq ed (subst layer (assoc 8 ed) ed)) (entmod ed) );end of PROGN entnum ); end of IF (assoc -3 ... (setq entnum (+ 1 entnum)) ); end of WHILE (setq p.. ;HATCH BY LAYER (command "layer" "s" "0.08-0.15" "") (if (setq sset (ssget "X" '((-4 . "<OR")(8 . "0.08-0.15")(8 . "text")(-4 . "OR>")))) (command "HATCH" "NET" "6" "45" "P" "")) (command "layer" "s" "0.15-0.30" "") (if (setq sset (ssget "X" '((-4 . "<OR")(8 . "0.15-0.30")(8 . "text")(-4 . "OR>")))) (command "HATCH" "NET" "5" "45" "P" "")) (command "layer" "s" "0.30-0.50" "") (if (setq sset (ssget "X" '((-4 . "<OR")(8 . "0.30-0.50")(8 . "text")(-4 . "OR>")))) (command "HATCH" "NET" "4" "45" "P" "")) (command "layer" "s" "0.50-1.00" "") (if (setq sset (ssget "X" '((-4 . "<OR")(8 . "0.50-1.00")(8 . "text")(-4 . "OR>")))) (command "HATCH" "NET" "3" "45" "P" "")) (command "layer" "s" "GT1.00" "") (if (setq sset (ssget "X" '((-4 . "<OR")(8 . "GT1.00")(8 . "text")(-4 . "OR>")))) (command "HATCH" "NET" "3" "45" "P" "")) ;(command "layer" "s" "text" "") ;(command "style" "standard" "arial.ttf" "" "" "" "" "") (command "layer" "s" "0" "") (command "zoom" "e" ) (command "zoom" "0.95x" ) (command "lwdisplay" "ON") (command "WMFBKGND" "OFF") (command "WMFOUT" "" "ALL" "") (vl-load-COM) (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (vla-put-GraphicsWinModelBackgrndColor disp 16777215) (vla-put-modelcrosshaircolor disp 0) (command "BMPOUT" "" "ALL" "") (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object)))) (vla-put-GraphicsWinModelBackgrndColor disp 0) (vla-put-modelcrosshaircolor disp 16777215) ) Edited October 2, 2013 by akgeo Quote
SLW210 Posted October 2, 2013 Posted October 2, 2013 Please read the Code posting guidelines and edit your posts to include the Code in Code Tags. Quote
akgeo Posted October 2, 2013 Author Posted October 2, 2013 Sorry about that, I forgot about the code button! Quote
Bhull1985 Posted October 3, 2013 Posted October 3, 2013 Is this what you're looking for? Taken from your posted code: (setq sset (ssget "X" '((0 . "LWPOLYLINE")))); select all LWpolyline in dwg Notice in your first post this thread: (-1 . <Entity name: 7ffff7c7930>) (0 . "LWPOLYLINE") The (setq sset) just above will add to a selection set all of the items that have the dxf group 0 reading LWPOLYLINE, as your line above, but the part can be different, and it will still select them. I think that's what you're attempting to locate? That will....well, select all Lwpolyline in dwg, both model space and paper space. Check this link out for more information, again from Lee's website. http://www.lee-mac.com/ssget.html Quote
Bhull1985 Posted October 3, 2013 Posted October 3, 2013 Also for your ; error: too few arguments if you enter addnsr FILENAME on the command prompt it may fix your error, alternative with the full routine (defun addopt (fn) you'd have to do (addopt filename) (just adding the parenthesis because the function name is not prefaced with C: which allows it to be typed to execute from the command line) Quote
BIGAL Posted October 4, 2013 Posted October 4, 2013 Lee not sure about this with out entity did not check code cdadr Quote
Lee Mac Posted October 4, 2013 Posted October 4, 2013 Lee not sure about this with out entity did not check code cdadr Sorry, I did not understand your post - what is the problem BIGAL? Quote
neophoible Posted October 4, 2013 Posted October 4, 2013 How did you determine what part of the code doesn't work? Did this work for you? (defun c:addnsr (fn) If so, how did you use it? Quote
akgeo Posted October 7, 2013 Author Posted October 7, 2013 Ah, got it fixed, essentially I broke a bat file that would call up the previously attached code with the csv filename in it (addopt \"S\\:\\\\Directory\\\\directory\\\\directory\\\\sample-assays.csv\") I reloaded a backed up version and it worked just fine. sorry for taking everyone time up! 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.