明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1217|回复: 10

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

[复制链接]
发表于 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轮廓实线层")
)

发表于 2021-11-23 06:33:46 来自手机 | 显示全部楼层
(vla-put-layer (vlax-ename->vla-object (car(entsel)) "1轮廓实线层")
 楼主| 发表于 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这个选择对象语句要调整?
发表于 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轮廓实线层")
)
发表于 2021-11-23 10:15:31 | 显示全部楼层
(command "CHANGE" (ssget ":S") "" "p" "la"  "1轮廓实线层" "")
 楼主| 发表于 2021-11-23 12:28:39 | 显示全部楼层
谢谢各位!我想用下面的代码,怎么运行不了呢?
(defun c:T1 ()
    (vl-load-com)   
   (entsel "选择一条直线:"))
(vla-put-layer (vlax-ename->vla-object (car(entsel)) "1轮廓实线层")
)
发表于 2021-11-23 12:38:29 | 显示全部楼层
(defun c:T1 ()
        (vl-load-com)   
        (vla-put-layer (vlax-ename->vla-object (car(entsel "\n选择一条直线:"))) "1轮廓实线层")
)
发表于 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)
)
发表于 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)
)
 楼主| 发表于 2021-11-23 14:15:48 | 显示全部楼层
各位大侠,本小菜鸟有礼了,多谢多谢,论坛真的太温暖了,太给力了!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 21:29 , Processed in 0.156697 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表