以下是我使用的:
主要功能:
- ;;; ------------------------------------------------------------------------
- ;;; STDLIB_LOAD_LINETYPE.LSP
- ;;;
- ;;; Copyright © December, 2008
- ;;; Timothy G. Spangler
- ;;;
- ;;; Permission to use, copy, modify, and distribute this software
- ;;; for any purpose and without fee is hereby granted, provided
- ;;; that the above copyright notice appears in all copies and
- ;;; that both that copyright notice and the limited warranty and
- ;;; restricted rights notice below appear in all supporting
- ;;; documentation.
- ;;;
- ;;; STDLIB_LOAD_LINETYPE
- ;;;
- ;;; Description:
- ;;; Called from a menu pulldown or rightclick menu
- ;;; * (STDLIB_LOAD_LINETYPE <LINETYPE>)
- ;;; <LINETYPE> = STRING = Valid linetype
- ;;;
- ;;; Returns:
- ;;; T if found and loaded otherwise nil
- ;;;
- ;;; ------------------------------------------------------------------------
- ;;; MAIN FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun STDLIB_LOAD_LINETYPE (Linetype / OldCmdEcho LineFiles FullFile Found OpenFile CurrentLine LinePath Result)
- ;; Set system variables
- (setq OldCmdEcho (getvar "CMDECHO"))
- (setvar "CMDECHO" 0)
- ;; Load linetype
- (if (not (tblsearch "LTYPE" Linetype))
- (progn
- ;; Check each search path for a .lin file
- (foreach Path (STR->LIST (getenv "ACAD") ";")
- (if (setq LineFiles (vl-directory-files Path "*.lin"))
- (progn
- (foreach File LineFiles
- (setq FullFile (cons (strcat Path "\" File) FullFile))
- )
- (setq Found (cons Path Found))
- )
- )
- )
- ;; Read each line file found and check for the linetype
- (foreach LineFile FullFile
- (setq OpenFile (open LineFile "r"))
- (while (setq CurrentLine (read-line OpenFile))
- (if (wcmatch (strcase CurrentLine) (strcat "*" (strcase LineType) "*"))
- (setq LinePath Linefile)
- )
- )
- (close OpenFile)
- )
- ;; Load result
- (if LinePath
- (setq Result T)
- (setq Result nil)
- )
- )
- )
- (if Result
- ;(command "-linetype" "load" Linetype LinePath "")
- (vl-cmdf "-linetype" "load" Linetype LinePath "")
- )
- ;; Reset system
- (setvar "CMDECHO" OldCmdEcho)
- ;; Send Result
- Result
- )
- (princ)
小帮手:
- ;;; ------------ STRING TO LIST SUB ROUTINE, CREATE A LIST FROM A STRING WITH DELIMETER
- (defun STR->LIST (Stg Del / CurChr PosCnt TmpLst TmpStr NewTmpLst)
- (setq PosCnt 1)
- (setq TmpStr "")
- (repeat (1+ (strlen Stg))
- (setq CurChr (substr Stg PosCnt 1))
- (if (= CurChr Del)
- (progn
- (setq TmpLst (cons TmpStr TmpLst))
- (setq TmpStr "")
- )
- (setq TmpStr (strcat TmpStr CurChr))
- )
- (setq PosCnt (1+ PosCnt))
- )
- (if (/= TmpStr "")
- (setq TmpLst (cons TmpStr TmpLst))
- )
- (setq NewTmpLst (reverse TmpLst))
- NewTmpLst
- )
你需要做的就是
(STDLIB_LOADLINETYPE“linetypename”)
这将搜索所有内容。lin文件位于线型的支持路径中,如果找到它,则加载它并返回T,否则返回nil。 |