fedd 发表于 2021-11-23 06:16:00

更改单个图元图层到指定图层的代码,求诊断

(defun c:test (/ ss)
    (vl-load-com)
    (setq entlay (entsel "\n选择目标图层:"))
    (setq objlay (vla-get-layer (vlax-ename->vla-object (car entlay))))
    (prompt "\n选择要移动的图元: ")
    (setq ss (ssget))
    (setq n 0)
    (while (< n (sslength ss))
    (vla-put-layer (vlax-ename->vla-object (ssname ss n)) objlay)
    (setq n (1+ n))
    )
)

上面是批量改变图元图层到指定图层的代码,我想去掉循环,每次只改变一个图元的图层,如何写之歌代码?下面是运行不了的代码:
(defun c:T1 (/ ss)
    (vl-load-com)
    (prompt "\n选择要移动的图元: ")
    (setq ss (ssget))
(vla-put-layer (vlax-ename->vla-object (ssname ss)) "1轮廓实线层")
)

Bao_lai 发表于 2021-11-23 06:33:46

(vla-put-layer (vlax-ename->vla-object (car(entsel)) "1轮廓实线层")

fedd 发表于 2021-11-23 06:50:57

大侠早啊~~~
(defun c:T1 (/ ss)
    (vl-load-com)
    (prompt "\n选择要移动的图元: ")
    (setq ss (ssget))

(vla-put-layer (vlax-ename->vla-object(car(entsel)) "1轮廓实线层")

)
-----------------
是这样吗?运行不了,估计是SS这个选择对象语句要调整?

fangmin723 发表于 2021-11-23 08:06:40

(defun c:T1 (/ ss)
    (vl-load-com)
    (prompt "\n选择要移动的图元: ")
    (setq ss (ssget))
    (vla-put-layer (vlax-ename->vla-object (ssname ss 0)) "1轮廓实线层")
)

start4444 发表于 2021-11-23 10:15:31

(command "CHANGE" (ssget ":S") "" "p" "la""1轮廓实线层" "")

fedd 发表于 2021-11-23 12:28:39

谢谢各位!我想用下面的代码,怎么运行不了呢?
(defun c:T1 ()
    (vl-load-com)   
   (entsel "选择一条直线:"))
(vla-put-layer (vlax-ename->vla-object (car(entsel)) "1轮廓实线层")
)

Bao_lai 发表于 2021-11-23 12:38:29

(defun c:T1 ()
        (vl-load-com)   
        (vla-put-layer (vlax-ename->vla-object (car(entsel "\n选择一条直线:"))) "1轮廓实线层")
)

yshf 发表于 2021-11-23 12:40:00

(defun c:T1 ()
    (vl-load-com)   
    (if (setq ent (entsel "\n选择一条直线:"))
        (vla-put-layer (vlax-ename->vla-object (car ent)) "1轮廓实线层")
    )
    (princ)
)

gaics 发表于 2021-11-23 13:14:34

fedd 发表于 2021-11-23 12:28
谢谢各位!我想用下面的代码,怎么运行不了呢?
(defun c:T1 ()
    (vl-load-com)   


(entsel "选择一条直线:"))后面多个括号。vla-put-layer括号不匹配
entsel一次就够了

(defun c:T1 ()
(vl-load-com)
(vla-put-layer
    (vlax-ename->vla-object(car (entsel "选择一条直线:")))
    "1轮廓实线层"
)
(princ)
)

fedd 发表于 2021-11-23 14:15:48

各位大侠,本小菜鸟有礼了,多谢多谢,论坛真的太温暖了,太给力了!!
页: [1] 2
查看完整版本: 更改单个图元图层到指定图层的代码,求诊断