PDA

View Full Version : Dimension String Verification



pinkguju
21st Sep 2010, 09:34 pm
I need to be able to make sure that there are Dimension Strings in a CAD file that range from 0 to 210. So each dimension string has a number ("01") as the unit. I want to be able to pull an external file (txt) off all the numbers that are NOT in the file.

So if 200 and 151 were not in the file it would give me that.

Any thoughts?

Lee Mac
21st Sep 2010, 09:47 pm
A rough estimate, hacked together:



(defun c:test ( / _PadLeft )

(defun _PadLeft ( s l )
(if (< (strlen s) l) (_PadLeft (strcat "0" s) l) s)
)

(
(lambda ( i / l )
(while (<= (setq i (1+ i)) 210)
(or (ssget "_X" (list '(0 . "DIMENSION") (cons 1 (_PadLeft (itoa i) 3))))
(setq l (cons i l))
)
)
(print l)
)
-1
)
)



File:


(defun c:test ( / _PadLeft f )

(defun _PadLeft ( s l )
(if (< (strlen s) l) (_PadLeft (strcat "0" s) l) s)
)

(if (setq f (getfiled "Output File" "" "txt" 1))
(
(lambda ( i / l )
(while (<= (setq i (1+ i)) 210)
(or (ssget "_X" (list '(0 . "DIMENSION") (cons 1 (_PadLeft (itoa i) 3))))
(setq l (cons i l))
)
)
(setq f (open f "a")) (princ l f) (close f)
)
-1
)
)
(princ)
)

BlackBox
21st Sep 2010, 09:49 pm
*IF* I understand you correctly, using Visual LISP, look into the TextOverride property of the Dimension object(s).

pinkguju
21st Sep 2010, 11:48 pm
*IF* I understand you correctly, using Visual LISP, look into the TextOverride property of the Dimension object(s).


That is exactly what i need.

pinkguju
22nd Sep 2010, 06:42 pm
Lee Mac - This works but it's reporting all the dimension strings that are in the CAD file. Even the ones that i deleted and purged out of the drawing.

I deleted "178" and "180" from the file, saved and ran the LISP routine. 178 and 180 showed up on the report.

Is there a way to show which ones are missing versus which ones are in the file? We have the criteria (0-210)

Lee Mac
22nd Sep 2010, 06:50 pm
What is the exact format of these dimension strings?

alanjt
22nd Sep 2010, 10:31 pm
FYI, Lee:

(wcmatch "25" "*5")
TI liked the idea. :)

Lee Mac
22nd Sep 2010, 10:37 pm
FYI, Lee:

(wcmatch "25" "*5")
TI liked the idea. :)

Ahh - overlooked that fact :oops:

Thanks mate. I need more sleep lately

Lee Mac
22nd Sep 2010, 10:44 pm
Updated :)

pinkguju
22nd Sep 2010, 10:46 pm
The exact format....

Linear dimension string
numbers in quotes ("02")

what else do you need?

pinkguju
23rd Sep 2010, 12:56 pm
i tried the updated code.

it's still giving me all of the ones that are in the CAD file. I just need the ones that are not in the file.

it's also giving me the ones that i've deleted and purged from the file.

Lee Mac
23rd Sep 2010, 07:41 pm
Unless the dimension string matches exactly, that is what it will do.

I am matching 001, 002, etc.

pinkguju
23rd Sep 2010, 10:29 pm
So then should i change the original to have the ### convention?

Lee Mac
23rd Sep 2010, 10:30 pm
So then should i change the original to have the ### convention?

That's why I asked for your format.

You say that the numbers run from 0 to 210, but then you give examples of 01, 02...

pinkguju
23rd Sep 2010, 10:38 pm
Sorry. i misunderstood what you were asking for.

the strings are written as such "001", "002", "003", "004", "005". all the way up to "210"

is that better?

Lee Mac
23rd Sep 2010, 10:45 pm
If that's the case then my original code should work

pinkguju
24th Sep 2010, 07:16 pm
I tried the original code and it's giving me the same result. Listing all the one that are in the file, as opposed to the ones that are not in the file. The ones that are not in the file are also coming up in the list.

Lee Mac
24th Sep 2010, 08:46 pm
Just tested the programs and it seems to work fine for me..

Testing on Dims such as...

23291

pinkguju
27th Sep 2010, 01:45 pm
The strings have the quotation marks in them.

Once all strings ("001" to "210") have been verified i have a script that turns them into text.

if i have numbers without the quotes then the conversion text doesn't work.

alanjt
27th Sep 2010, 05:23 pm
What about something like this?


(defun c:Test (/ ss)
(vl-load-com)
(if (setq ss (ssget "_X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
((lambda (i n / lst e)
(while (> (setq n (1- n)) 0) (setq lst (cons n lst)))
(while (setq e (ssname ss (setq i (1+ i))))
(setq lst (vl-remove
(atoi (vl-list->string
(vl-remove 34 (vl-string->list (cdr (assoc 1 (entget e)))))
)
)
lst
)
)
)
(cond (lst (print lst)))
)
-1
211
)
)
(princ)
)

pinkguju
28th Sep 2010, 08:41 pm
That works.

I added the output file part. I get "malformed list on input". I don't know how to fix it.

I've tried a space between lines 3 and 4 as well as putting it in other locations. What am i missing?



(defun c:Test (/ ss)
(vl-load-com)
(if (setq f (getfiled "Output File" "" "xls" 1))
(if (setq ss (ssget "_X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
((lambda (i n / lst e)
(while (> (setq n (1- n)) 0) (setq lst (cons n lst)))
(while (setq e (ssname ss (setq i (1+ i))))
(setq lst (vl-remove
(atoi (vl-list->string
(vl-remove 34 (vl-string->list (cdr (assoc 1 (entget e)))))
)
)
lst
)
)
)
(cond (lst (print lst)))
)
-1
211
)
)
(princ)
)

BlackBox
28th Sep 2010, 08:46 pm
For starters, you were missing a paren. Are you using the VLIDE to check your code?

I just glanced at your code, and here's a couple revisions that jumped out to me:



(defun c:Test (/ f ss)
(vl-load-com)
(if (and (setq f (getfiled "Output File" "" "xls" 1))
(setq ss
(ssget
"_X"
'((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>")))))
((lambda (i n / lst e)
(while (> (setq n (1- n)) 0) (setq lst (cons n lst)))
(while (setq e (ssname ss (setq i (1+ i))))
(setq lst
(vl-remove
(atoi
(vl-list->string
(vl-remove
34
(vl-string->list (cdr (assoc 1 (entget e)))))))
lst)))
(cond (lst (print lst))))
-1
211))
(princ))



I have not tested this, so if there's something else I've overlooked, I apologize.

alanjt
28th Sep 2010, 09:01 pm
(defun c:Test (/ file ss)
;; Alan J. Thompson
(vl-load-com)
(if (and (setq file (getfiled "Output File" "" "xls" 1))
(setq ss (ssget "_X" '((0 . "DIMENSION") (-4 . "<NOT") (1 . "") (-4 . "NOT>"))))
)
((lambda (i n / lst e)
(while (> (setq n (1- n)) 0) (setq lst (cons n lst)))
(while (setq e (ssname ss (setq i (1+ i))))
(setq lst (vl-remove
(atoi (vl-list->string
(vl-remove 34 (vl-string->list (cdr (assoc 1 (entget e)))))
)
)
lst
)
)
)
(cond (lst (print lst) (AT:WriteToFile file lst T)))
)
-1
211
)
)
(princ)
)


(defun AT:WriteToFile (file lst overwrite / fo)
;; Write list to file
;; file - file to write list to (must be in form "c:\\File.txt")
;; lst - list to write to file
;; overwrite - If T, will overwrite; nil to append
;; Alan J. Thompson, 04.28.09
(if (and (vl-consp lst)
(setq fo (open file
(if overwrite
"W"
"A"
)
)
)
)
(progn (foreach x lst (write-line (vl-princ-to-string x) fo))
(close fo)
file
)
)
)

alanjt
28th Sep 2010, 09:04 pm
; error: no function definition: AT:WRITETOFILE

Scroll down and copy everything. :wink:

BlackBox
28th Sep 2010, 09:05 pm
Scroll down and copy everything. :wink:

I deleted the post before I got your notification... I overlooked the scrollbar handle.