handasa 发表于 2022-7-5 18:13:34

lisp将所有实体移动到l

大家好
我有这个Lisp程序的程序
(vl-load-com)
(defun c:COMBINELAYERS(/ doc blocks blk eo layers lay)
;CHANGE BY LAYER COLOR TO OVERRIDE COLOR
;; Get the ActiveX object of the current dwg
(setq doc    (vla-get-ActiveDocument (vlax-get-acad-object))
       blocks (vla-get-Blocks doc) ;Get the blocks collection
       layers (vla-get-Layers doc) ;Get the layers collection
) ;_ end of setq

;; Step through all blocks (including Model Space & Layouts)
(vlax-for blk blocks
   ;; Step through all contained entities in block
   (vlax-for eo blk
   ;; Get the layer the entity is placed on
   (setq lay (vla-Item layers (vla-get-Layer eo)))
   (vla-put-Layer eo (getvar "CLAYER")) ;Change the entity to the current layer
   (if (= (vla-get-Color eo) 256)
       ;;If its colour bylayer, change it to overridden color to match
       (vla-put-Color eo (vla-get-color lay))
   ) ;_ end of if
   (if (= (strcase (vla-get-Linetype eo)) "BYLAYER")
       ;;If its linetype bylayer, change it to overridden linetype to match
       (vla-put-Linetype eo (vla-get-Linetype lay))
   ) ;_ end of if
   (if (= (vla-get-Lineweight eo) -1)
       ;;If its lineweight bylayer, change it to overridden lineweigth to match
       (vla-put-Lineweight eo (vla-get-Lineweight lay))
   ) ;_ end of if
   ) ;_ end of vlax-for
) ;_ end of vlax-for
(princ)
) ;_ end of defun
将所有对象(包括块子图元)移动到第0层或当前层。。并将所有bylayer颜色的对象更改为不考虑颜色
 
但我申请了所有的图纸,没有选择
 
我希望lisp要求用户选择要应用到的对象。。。提前感谢

satishrajdev 发表于 2022-7-5 18:45:28

试试这个:-
您只能更改选定对象。。。
注意-块内的对象不会更改,只会更改块颜色(如果已设置为“按块”)和图层。不能更改块实体,因为它将更改块定义,并反映对远离选定块的其他块的影响。希望你明白我的意思
(defun c:test (/ a b i)
(if (setq a (ssget))
   (repeat (setq i (sslength a))
   (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
   (vla-put-layer b "sat")                ;Replace "0" with (getvar "CLAYER") for current layer
   (vla-put-color b 256)
   )
)
(princ)
)

handasa 发表于 2022-7-5 19:30:33

@satishrajdev感谢您的回复。。。您可以修改我的lisp,让用户从图形中选择对象吗?我对lisps及其编码相当陌生。。。
谢谢你的支持
页: [1]
查看完整版本: lisp将所有实体移动到l