Code Red > AutoLISP (Vanilla / Visual)

Check for Linetype

(1/1)

TimSpangler:
In this post http://www.theswamp.org/index.php?topic=10923.msg137954#msg137954 I had a question about checking for a linetype.  Well with CABs help I finally use this.  I know it can be made more efficient that is the reason for posting.  Please post some input.

code below

--- Code: ---;;;
;;; Timothy G. Spangler
;;;
;;; ------------ Checks to see if a linetype is availible
(defun FIND_LINETYPE(LineType / Files)

(setq Files (GET_LINETYPE_FILES))
  (vl-some '(lambda(x) (if (CHECK_LINETYPE (findfile x) LineType) x)) Files)
)
(defun CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Result)

(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
(if (wcmatch CurrentLine "`**")
(progn
(setq LinetypeName (substr(car(TGS:Stringtolist CurrentLine ","))2))
(if (= (strcase Linetype) LinetypeName)
(setq Result T)
)
)
)
)
(close OpenFile)
Result
)
(defun GET_LINETYPE_FILES (/ AcadTemp Dir)

;;; gets a list of all directories in the support path
(setq AcadTemp (reverse(STRING_TO_LIST (getenv "ACAD")";")))

;;; creates a list of all files with the ".ext" in the support path
(foreach X AcadTemp
(setq Dir (vl-string-translate  "\\" "/" X))
(if (vl-directory-files Dir "*.lin" 1)
(foreach Y (vl-directory-files Dir "*.lin" 1)
(setq LINFileList (cons Y LINFileList))
)
)
)
;;; return the list
LINFileList
)

--- End code ---

load it type (find_linetype "linetype")
It will search all .lin files in your search path if it finds it it will return the file it is in.

I have also thought about making it more ambiguous.  use it to search any file type for anything (just a thought)

Anyway here it is, help make it more efficient.

Navigation

[0] Message Index

Go to full version