yu888yu 发表于 2014-11-21 17:27:57

求代码,如何读取当前图纸的所有图层?

请教如何读取当前图纸的所有图层,并达到下面效果?
"S-text\nS-colun\nS-hatch"这种字符串!!!

819534890 发表于 2014-11-21 17:35:11

(defun all_layers (/ ly l d) ;返回全部图层列表
(setq d (TBLNEXT "LAYER" 't) l nil)
(while d
    (setq ly (cdr(assoc 2 d)))
    (setq l (append l(list ly)))
    (setq d (TBLNEXT "layer"))
)
    l
)

yu888yu 发表于 2014-11-21 17:56:04

谢谢您的解答,请问该如何用啊 我加载了 是不是查询!L呢???

xyp1964 发表于 2014-11-21 19:22:55

vla-get-layers

冰与火之歌 发表于 2014-11-22 11:40:52

(Defun c:tt        ()
    (Vl-Load-Com)
    (Setq Mylayers (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) 'Activedocument) 'Layers))
        (Setq i 0 lyname_lst '())
        (Repeat        (Vla-Get-Count Mylayers)
          (setq lyname (Vla-Get-Name (Vla-Item Mylayers i)))
          (setq lyname_lst (Append lyname_lst (List lyname)))
          (setq i (1+ i))
        )
(vl-sort lyname_lst '<)
)

xyp1964 发表于 2014-11-22 12:06:09

(defun c:tt ()
(setq        lay (vlax-get (vlax-get (vlax-get-acad-object) 'activedocument)
                      'layers
          )
        lst '()
)
(vlax-for la lay
    (setq lst (cons (vlax-get la 'name) lst))
)
lst
)

冰与火之歌 发表于 2014-11-22 12:15:30

xyp1964 发表于 2014-11-22 12:06 static/image/common/back.gif


namezg 发表于 2014-11-22 20:11:38

;Lisp方法
(defun zg-GetAllLayerList (/ dxf LayerNameList)
        (while (setq dxf (tblnext "layer" (not dxf)))
                (setq LayerNameList (cons (cdr (assoc 2 dxf)) LayerNameList))
        )
        ;(reverse LayerNameList)
)
;VLisp方法
(defun zg-GetAllLayerList (/ LayerNameList)
        (vlax-for x (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
                (setq LayerNameList (cons (vla-get-Name x) LayerNameList))
        )
        ;(reverse LayerNameList)
)
页: [1]
查看完整版本: 求代码,如何读取当前图纸的所有图层?