prashanthmsp Posted February 4, 2013 Posted February 4, 2013 (edited) Hi Folks! I have a situation where I need to compare various texts in Autocad drawing with a text report. I need help in writing a LISP for this. Logic would be to follow these steps: 1) Select Text (Particular layer and color) in .dwg file 2) Export the all these text to a text file (I already have a lisp for this- txtexprt) And it works good! See below 3) Compare the values in the output text file with another text file and report missing values. Below is the code for extracting text (Step-2) Would appreciate if somebody can help me in achieving steps-1 and 3 mentioned above!! (defun c:txtexprt () (setq sset (ssget '((0 . "TEXT")))) (if sset (progn (setq itm 0) (setq num (sslength sset)) (setq fn (getfiled "Text Export File" "" "txt" 1)) (if (/= fn nil) (progn (setq fh (open fn "w")) (while (< itm num) (setq hnd (ssname sset itm)) (setq ent (entget hnd)) (setq stv (cdr (assoc 1 ent))) (princ (strcat stv "\n") fh) (setq itm (1+ itm)) ) (close fh) ) ) ) ) (setq sset nil) (princ) ) Edited February 4, 2013 by prashanthmsp Tagged the code Quote
MSasu Posted February 4, 2013 Posted February 4, 2013 To filter the lables by layer and color: '((0 . "TEXT") (8 . [i]LayerName[/i]) (62 . [i]ColorNumber[/i])) example: '((0 . "TEXT") (8 . "Labels") (62 . 2)) To compare two files you may use a dedicated tool, for example CSDiff (free). Please edit your post and add the required code tags. Also, welcome to the Forum! Quote
Tharwat Posted February 4, 2013 Posted February 4, 2013 Welcome to the forum . Use TAG CODE to place the code in it . What is the name of the Layer and the Color number ? Quote
Tharwat Posted February 4, 2013 Posted February 4, 2013 What kind of comparison you want to compare the strings with ? More details needed in this regard . Quote
prashanthmsp Posted February 4, 2013 Author Posted February 4, 2013 Thank you for your response and educating me on "Code posting guidelines" ! From now on, I will tag the codes. I'm still looking for a place where I can "edit" my previous post. Sorry I just joined the Forum today! To filter the lables by layer and color: '((0 . "TEXT") (8 . [i]LayerName[/i]) (62 . [i]ColorNumber[/i])) example: '((0 . "TEXT") (8 . "Labels") (62 . 2)) To compare two files you may use a dedicated tool, for example CSDiff (free). Please edit your post and add the required code tags. Also, welcome to the Forum! Quote
prashanthmsp Posted February 4, 2013 Author Posted February 4, 2013 To explain it further: I have a text report from Tekla Structures which I want to compare with Text in Autocad drawing. A report from Tekla structures would always contain X number of values (Say 100), but when I make a text file from Autocad, it would contain Y number (say 95: always less than X). Now, I am interested in the missing values in the Autocad drawing (100-95=5 values) Now I want another text file with these 5 values Quote
prashanthmsp Posted February 4, 2013 Author Posted February 4, 2013 Thank you for your response and thanks for educating me on "Code posting guidelines" ! I will use the Tags from now on when I post a code. I am still figuring out how to "edit" previous post:roll: Sorry I just joined the forum today Quote
Tharwat Posted February 4, 2013 Posted February 4, 2013 I have a text report from Tekla Structures which I want to compare with Text in Is it only just one value or a list of values ? Can you upload a sample txt file that contains these values ? I am still figuring out how to "edit" previous post:roll: Take a look below you post and you would see a small button ( edit post ). Quote
prashanthmsp Posted February 4, 2013 Author Posted February 4, 2013 I have edited the post! Thanks I have attached the two files I want to compare. When you compare the two files, value in line 5 and line 7 in List_Tekla.txt file is missing in List_Autocad.txt file. As advised by MSasu, the software CSDiff can highlight this difference. But I know there is a way to compare this within the LISP List_Autocad.txt List_Tekla.txt Quote
BIGAL Posted February 5, 2013 Posted February 5, 2013 Can be done pretty easy 1st step read in external txt into a list say 100 items then (nth 56 listtxt) is the 56th line, a 2nd list is your ssget as above code but I would add layer etc as suggested. Ok you need two loops take the first list, 1st value and compare it to every line in the 2nd list if not found then add to 3rd list get next value compare to list again. I would expect someone has code for this already something like this method (repeat numlist1 (setq ans (nth x sset)) (repeat numlist2 ((setq ans2 (nth y sset)) (if (= ans ans2) (princ "found") ; could delete from list as it will make searching faster ))))) 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.