Jump to content

Search Drawing for missing strings from .DAT file


Recommended Posts

Posted (edited)

Would anyone have a lisp that checks a drawing for strings from a .DAT file and displays those strings that are missing in the drawing? This will help us identify missing data points particularly in very large inspection drawings with hundreds of these things.

 

For example we have a file named "UPDATE.DAT" that is populated with new data every time we open a drawing and automatically updates 'data points' in the drawing based on a specific layer and the corresponding number in the list.

 

List Example:

UPDATE.DAT

ACAD UPDATE INFORMATION FILE
DATAPOINTS
-#1- DATA POINT 0.001
-#2- DATA POINT 0.002
-#3- DATA POINT 0.003
-#4- DATA POINT 0.004

...

-#956- DATA POINT 0.956

 

I need the lisp to fetch the UPDATE.DAT file, read every line, then generate a search for "#1-, #2-, #3-, #4-, etc.." and then display and prompt or generate another text file with those that are missing. That way we can zoom to  those areas and add the missing datapoints. Currently when checking for missing data points I run the update and get this in return: Updating Datapoints....... 39 of 41 datapoint(s) updated. That tells me I am missing two data points, so I keep the list open on one screen and do CTRL+F and search for "#" and then manually go down the Find and Replace list until I find the one(s) that are missing then zoom to data points around that area and add. I believe there could be a much more efficient way.

Edited by tmelancon
  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • tmelancon

    12

  • ronjonp

    9

Top Posters In This Topic

Posted Images

Posted

Post an example drawing and data file.

Posted

What causes this data and the drawing to not have the same information? Sounds like a workflow problem.

Posted

Yea just something as simple as a CAD technician forgetting to insert a data point. We catch this during the review process. Thats the whole point of me requesting such a code. The way I currently do it is fine, I just CTRL+F and search for "#" then go down each list comparing until I come across a number that the tech missed, then I go in the drawing and insert it. I am just trying to automate crosschecking.

Posted (edited)

We receive all of our drawings from the field. Hand sketched with these data points. Our data guys enter the data into our database (the one that generates the .DAT file each time we create a drawing) and our CAD guys create the technical drawings and pulls each data point where it belongs. We draw dozens and dozens of drawings per week. Some of these data points get missed by CAD that is why we review and correct.

Edited by tmelancon
Posted (edited)

Give this a try :)

(defun c:foo (/ _readfile d f s str)
  ;; RJP » 2019-08-01
  (defun _readfile (file fltr / of r l)
    (cond ((and (eq 'str (type file)) (setq file (findfile file)) (setq of (open file "r")))
	   (while (setq l (read-line of)) (and (wcmatch l fltr) (setq r (cons l r))))
	   (close of)
	   (reverse r)
	  )
    )
  )
  (cond	((and ;; Looks for .dat file with same name as drawing in the same directory
	      (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".dat"))
	      (setq d (_readfile f "-`#*"))
	      (setq s (ssget "_X" '((0 . "text") (1 . "`#*"))))
	 )
	 (setq d (mapcar '(lambda (x) (strcase (vl-string-left-trim " -" x))) d))
	 (setq d (vl-sort d '<))
	 (foreach txt (mapcar 'cadr (ssnamex s))
	   (setq str (strcase (cdr (assoc 1 (entget txt)))))
	   (if (vl-some '(lambda (x) (= str x)) d)
	     (setq d (vl-remove str d))
	     (progn (redraw txt 3) (princ (strcat "\nIn drawing but NOT in file: " str)))
	   )
	 )
	 (foreach x d (princ (strcat "\nNot in drawing but in file: " x)))
	 (or d (alert "\nAll datapoints have been accounted for... "))
	)
  )
  (princ)
)

Result from your sample:

image.png.fd3d3441953d305592f259b810c4ba22.png

Quote

In drawing but NOT in file: #17- PIPE INACTIVE
In drawing but NOT in file: #3- PIPE .228
Not in drawing but in file: #3- PIPE .228|
Not in drawing but in file: #6.1- TOL A INACTIVE|
Not in drawing but in file: #17- PIPE INACTIVE|

 

Edited by ronjonp
Posted

Thanks for your kind reply ronjonp as soon as I get to the office tomorrow morning I will test! Youre awesome! Thanks again so much for your valuable time !

Posted

Hey man great code works like a charm. How would I go about adding a piece of code so that if all the data points are there it simply says all datapoints are accounted for:

 

(princ "\nAll datapoints have been accounted for... ")

 

something like this? Where would I insert this?

Posted
1 hour ago, tmelancon said:

Hey man great code works like a charm. How would I go about adding a piece of code so that if all the data points are there it simply says all datapoints are accounted for:

 


(princ "\nAll datapoints have been accounted for... ")

 

something like this? Where would I insert this?

Code updated above.

Posted

Yes indeed man code works great I just appreciate your help so much. I also just came across something odd.

 

Sometimes we inactivate these data points until we go back out to achieve another inspection. So in the meantime we just keep the data point on the drawing as a placeholder but inactive it in our database so it shows INACTIVE. This is where I am noticing an issue. When I run the routine I get this:

 

TMLs in drawing but NOT in UPDATE file: #12- PIPE INACTIVE
TMLs in drawing but NOT in UPDATE file: #13- 90° ELL INACTIVE
TMLs not in drawing but in UPDATE file: #12- PIPE INACTIV   <<<<<------- Missing 'E' and not recognizing it as being in both the drawing and the file? im confused.
TMLs not in drawing but in UPDATE file: #13- 90° ELL INACTIV <<<<<------- Missing 'E' and not recognizing it as being in both the drawing and the file? im confused.

 

When in fact it is in the drawing and the .DAT file... hummm.. Im trying on my end I promise. If you come up with something chime in. Tnx

Posted (edited)

#12- PIPE INACTIV is not equal to #12- PIPE INACTIVE ? If all you care about is numbers and not the text that could be easily modified, but the check right now IMO is better quality control.

 

Just like your example file you had a couple of entries that had a bar on the end of them but not in the drawing. Should be flagged right?

In drawing but NOT in file: #17- PIPE INACTIVE
In drawing but NOT in file: #3- PIPE .228
Not in drawing but in file: #3- PIPE .228|
Not in drawing but in file: #17- PIPE INACTIVE|

 

Edited by ronjonp
Posted

Here is the current code I have, I tweaked it a bit. Also see updated .DAT file. I removed "|||||EOL|" from the original .DAT post because I didnt want to confuse you with what that was for. It is just basically coded there for "End of Line" since we have other code that populates this file upon creating and opening an autocad drawing. My apologies, and yes your right the current check you have is better.

 

I guess its this line that removing the 'E' from INACTIVE now that I am thinking about it:

	 (setq d (mapcar '(lambda (x) (strcase (vl-string-right-trim "|||||EOL|" x))) d))

 

Updated Code:

(defun c:FOOD (/ _readfile b d f s str)
  ;; RJP » 2019-08-01
  (defun _readfile (file fltr / of r l)
    (cond ((and (eq 'str (type file)) (setq file (findfile file)) (setq of (open file "r")))
	   (while (setq l (read-line of)) (and (wcmatch l fltr) (setq r (cons l r))))
	   (close of)
	   (reverse r)
	  )
    )
  )
  (cond	((and
              (setq f "UPDATE.DAT")
              (setq d (_readfile f "-`#*"))
              (setq d (mapcar '(lambda (x) (strcase (vl-string-left-trim "-" x))) d))
	      (setq s (ssget "_X" '((0 . "text") (1 . "`#*"))))
	 )
	 (setq d (mapcar '(lambda (x) (strcase (vl-string-right-trim "|||||EOL|" x))) d))
	 (foreach txt (mapcar 'cadr (ssnamex s))
	   (setq str (strcase (cdr (assoc 1 (entget txt)))))
	   (if (vl-some '(lambda (x) (= str x)) d)
	     (setq d (vl-remove str d))
	     (progn (redraw txt 3) (princ (strcat "\nTMLs in drawing but NOT in UPDATE file: " str)))
	   )
	 )
	 (foreach x d (princ (strcat "\nTMLs not in drawing but in UPDATE file: " x)))
	)
  )
  (princ)
)

 

UPDATE.DAT

Posted
7 minutes ago, ronjonp said:

#12- PIPE INACTIV is not equal to #12- PIPE INACTIVE ? If all you care about is numbers and not the text that could be easily modified, but the check right now IMO is better quality control.

 

I didn't know where it was getting "INACTIV" from.. nowhere does it have that... but after further review I guess this piece of code removed that 'E', hence why its saying hey this isnt matching up:

 

	 (setq d (mapcar '(lambda (x) (strcase (vl-string-right-trim "|||||EOL|" x))) d))

 

Posted (edited)

You have some strange data files LOL.

 

You should have mentioned you changed the code .. what you are doing with vl-string-right -trim is as designed by the function. Assuming that the BAR is a symbol only reserved for EOL .. then try this instead:

(setq d	(mapcar	'(lambda (x)
		   (strcase (if	(setq i (vl-string-search "|" x))
			      (substr x 1 i)
			      i
			    )
		   )
		 )
		d
	)
)

*Edit .. You also have the keep the vl-string-left-trim to remove the "-" prefix. Here's the modified code.

(defun c:foo (/ _readfile d i f s str)
  ;; RJP » 2019-08-01
  (defun _readfile (file fltr / of r l)
    (cond ((and (eq 'str (type file)) (setq file (findfile file)) (setq of (open file "r")))
	   (while (setq l (read-line of)) (and (wcmatch l fltr) (setq r (cons l r))))
	   (close of)
	   (reverse r)
	  )
    )
  )
  (cond	((and ;; Looks for .dat file with same name as drawing in the same directory
	      (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".dat"))
	      (setq d (_readfile f "-`#*"))
	      (setq s (ssget "_X" '((0 . "text") (1 . "`#*"))))
	 )
	 (setq d (mapcar '(lambda (x)
			    (strcase (vl-string-left-trim
				       " -"
				       (if (setq i (vl-string-search "|" x))
					 (substr x 1 i)
					 i
				       )
				     )
			    )
			  )
			 d
		 )
	 )
	 (setq d (vl-sort d '<))
	 (foreach txt (mapcar 'cadr (ssnamex s))
	   (setq str (strcase (cdr (assoc 1 (entget txt)))))
	   (if (vl-some '(lambda (x) (= str x)) d)
	     (setq d (vl-remove str d))
	     (progn (redraw txt 3) (princ (strcat "\nIn drawing but NOT in file: " str)))
	   )
	 )
	 (foreach x d (princ (strcat "\nNot in drawing but in file: " x)))
	 (or d (alert "\nAll datapoints have been accounted for... "))
	)
  )
  (princ)
)

 

Edited by ronjonp
Posted

The original code was written in 1986 for a piping program. Not sure if anything has changed since. LOL

Posted
4 minutes ago, tmelancon said:

The original code was written in 1986 for a piping program. Not sure if anything has changed since. LOL

How long have you been cross checking this manually? I hope it's not more than a couple of days 😬

Posted

Our CAD guys are pretty good here, minimal errors, but occasionally I will come across a drawing with one or two missing and just find it quickly and add it. LOL

Posted

Cool .. you could also cleanup those data lines like so:

(strcase (vl-string-left-trim " -" (vl-string-subst "" "|||||EOL|" x)))

Are these DAT files available before the drawing is created? If so .. please tell me your CAD people are not manually doing this.

Posted

We manage our data out of a Mechanical program. This program writes the .DAT file each time a drawing is created(opened) through our database. We have a routine we run to pull those datapoints and it automatically brings in the data via the .DAT file.

 

 

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...