I have the need to make the current open dwg (name) equal to its predefined number in a large list. For example, building66.dwg is equal to 123789. I’ll have a large list in a tab delimited txt file with the example below. I can put the list in the lsp file if needed. Something like (if (getvar "dwgname") make equal to listname) and go out to the list and return its number. Seems kind of easy but I can’t make it happen. Any iseas?
building66.dwg 123789
building12.dwg 333789
building94.dwg 345789
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@Anonymous wrote:
Oh, not looking to rename the current open dwg. I just need to pluck a number from a list based on the current open dwg.
(defun c:pluck (/ file data of a suff f) (if (and (= (getvar 'DwgTitled) 1) (setq data nil file (getfiled "Select text file" (getvar 'dwgprefix ) "txt" 16 ) ) ) (progn (setq of (open file "r")) (while (setq a (read-line of)) (if (setq suff (vl-string-position 32 a)) (setq data (cons (list (strcase (substr a 1 suff)) (substr a (+ 2 suff)) ) data ) ) ) ) (close of) (if (setq f (assoc (strcase (getvar 'dwgname)) data)) (print (cadr f)) (princ "\n<<<Drawing name not found>>>") ) ) ) (princ) )
Or you can make this change this line to where the drawing.txt is located
(setq data nil file (getfiled "Select text file" (getvar 'dwgprefix ) "txt" 16 ) )
to
(setq data nil file (findfile "H:\\Documents and Settings\\pbe\\My Documents\\drawing list.txt"))
Where the highlighted text is the permanent name and location of the txt file.
HTH
Thanks for the quick replies! Pardon my rustyness with this. It the code designed to read like the attached txt file? I got a <<<Drawing name not found>>> while in the FMAARABOF3.dwg. Anyway, I take it data or stuff will be the number value found in the file based on the dwg name?
@Anonymous wrote:
Thanks for the quick replies! Pardon my rustyness with this. It the code designed to read like the attached txt file? I got a <<<Drawing name not found>>> while in the FMAARABOF3.dwg. Anyway, I take it data or stuff will be the number value found in the file based on the dwg name?
I wasnt expecting the "\t" <tab> dilimeter
change this
(setq suff (vl-string-position 32 a))
to
(or (setq suff (vl-string-position 32 a)) (setq suff (vl-string-position 9 a)))
That way you can still use the code even if you are using a " " <space> dilimeted file
HTH