Thx Lee,
它工作得很好,但我认为它帮助不大。
看,我想处理1300个文件。
它们都需要创建层并重命名一些层。
如果你不介意,我将使用你的一些代码来创建层:
- (defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
- ;; © Lee Mac 2010
- (or (tblsearch "LAYER" name)
- (entmake
- (append
- (list
- (cons 0 "LAYER")
- (cons 100 "AcDbSymbolTableRecord")
- (cons 100 "AcDbLayerTableRecord")
- (cons 2 name)
- (cons 70 bitflag)
- (cons 290 (if willplot 1 0))
- (cons 6
- (if (and linetype (tblsearch "LTYPE" linetype))
- linetype "CONTINUOUS"
- )
- )
- (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7))
- (cons 370
- (fix
- (* 100
- (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0)
- )
- )
- )
- )
- (if description
- (list
- (list -3
- (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description))
- )
- )
- )
- )
- )
- )
- )
- (defun c:MakeLayers nil (vl-load-com)
- ;; © Lee Mac 2010
- ;; Specifications:
- ;; Description Data Type Remarks
- ;; -----------------------------------------------------------------
- ;; Layer Name STRING Only standard chars allowed
- ;; Layer Colour INTEGER may be nil, -ve for Layer Off, Colour < 256
- ;; Layer Linetype STRING may be nil, If not loaded, CONTINUOUS.
- ;; Layer Lineweight REAL may be nil, 0 <= x <= 2.11
- ;; Plot? BOOLEAN T = Plot Layer, nil otherwise
- ;; Bit Flag INTEGER 0=None, 1=Frozen, 2=Frozen in VP, 4=Locked
- ;; Description STRING may be nil for no description
- ;; Function will return list detailing whether layer creation is successful.
- (
- (lambda ( lst / lts ) (setq lts (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))))
- (mapcar 'cons (mapcar 'car lst)
- (mapcar
- (function
- (lambda ( x )
- (and (caddr x)
- (or (tblsearch "LTYPE" (caddr x))
- (vl-catch-all-apply 'vla-load (list lts (caddr x) "acad.lin"))
- )
- )
- (apply 'MakeLayer x)
- )
- )
- lst
- )
- )
- )
- '(
- ; Name Colour Linetype Lineweight Plot? BitFlag Description
- ( "CEN" 6 "CENTER" 0.18 T 0 nil )
- ( "DIMS" -1 nil 0.18 T 0 nil )
- ( "HAT" 3 nil 0.18 T 0 nil )
- ( "HID" 4 "HIDDEN" 0.15 T 0 "Hidden" )
- ( "LOGO" 176 nil 0.09 T 0 "For Logo" )
- ( "OBJ" -2 nil 0.40 T 0 nil )
- ( "PAPER" 5 "PHANTOM" nil T 0 nil )
- ( "PHAN" 6 "PHANTOM" 0.18 T 0 nil )
- ( "TITLE" 176 nil nil T 0 "For Title" )
- ( "TXT" 7 nil nil T 0 nil )
- )
- )
- )
这将完成层转换器所做的工作,但只需1秒
您确实需要始终使用相同的旧层,但大多数情况下都是这样。
- (dolayers);creates new layers if not already there.
- (setlayernew);will merge all old layers that are set with the new ones.
- ;;function to rename a layer.
- ;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
- ;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
- ;;if old layer doesn't exist, it does nothing.
- (defun renlay (ol nl / ss i ent )
- (cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl)))
- (command "._rename" "la" ol nl)
- )
- ((and (tblsearch "layer" ol)(tblsearch "layer" nl))
- (command "-LAYMRG" "N" ol "" "N" nl "Y")
- )
- ((not (tblsearch "layer" ol))
-
- (prompt (strcat "\nLayer " ol " not found. "))
- )
- )
- (princ)
- )
- ;;example
- (defun c:setlayernew ()
- (command "-layer" "s" "0" "")
- (renlay "1" "01 Dimensions")
- (renlay "2" "02 Project dimensions notes")
- (renlay "8" "05 Center")
- (renlay "9" "08 Surrounding")
- (renlay "11" "05 Center")
- (renlay "13" "13 Border")
- (renlay "BORDER" "13 Border")
- (renlay "BORDER-V" "13 Border")
- (renlay "HORIZONTAL REF BOX" "0")
- (renlay "LOGO" "01 Dimensions")
- (renlay "3D" "0")
- (renlay "3d" "0")
- (renlay "Dimension (ISO)" "01 Dimensions")
- (renlay "Visible (ISO)" "0")
- (renlay "Visible Narrow (ISO)" "0")
- (renlay "Border (ISO)" "13 Border")
- (renlay "Title (ISO)" "13 Border")
- (princ)(princ "Layers renamed and merged")
- )
|