本帖最后由 183017064 于 2025-4-29 14:29 编辑
 - ;; 自定义颜色命令
- (defun c:C1 () (setcolor 6)) ; 洋红
- (defun c:C2 () (setcolor 1)) ; 红色
- (defun c:C3 () (setcolor 2)) ; 黄色
- (defun c:C4 () (setcolor 3)) ; 绿色
- (defun c:C5 () (setcolor 4)) ; 青色
- (defun c:C6 () (setcolor 5)) ; 蓝色
- (defun c:C7 () (setcolor 11)) ; 棕色
- (defun c:C8 () (setcolor 190)) ; 紫色
- (defun c:CC () (setcolor 256)) ; 随层
- ;;; ======================================================
- (defun setcolor (colorcode / color-palette color-name ss cnt ent)
- ;; 颜色名称对照表
- (setq color-palette
- '(
- (1 . "红色") (2 . "黄色") (3 . "绿色")
- (4 . "青色") (5 . "蓝色") (6 . "洋红")
- (11 . "棕色") (190 . "紫色") (256 . "随层")
- )
- )
-
- ;; 获取颜色名称
- (setq color-name
- (if (setq temp (assoc colorcode color-palette))
- (cdr temp)
- "未知颜色"
- )
- )
-
- ;; 显示颜色设置提示
- (princ
- (strcat
- "\n当前颜色: "
- color-name
- " (代码 "
- (itoa colorcode)
- ")"
- )
- )
-
- ;; 实体选择
- (if (setq ss (ssget))
- (progn
- (setq cnt 0)
- (repeat (sslength ss)
- (setq ent (ssname ss cnt))
- (entmod
- (append
- (entget ent)
- (list (cons 62 colorcode))
- )
- )
- (setq cnt (1+ cnt))
- )
- ;; 显示修改结果
- (princ
- (strcat
- "\n成功修改 "
- (itoa cnt)
- " 个实体颜色为 "
- color-name
- )
- )
- )
- ;; 空选择提示
- (princ "\n未选择任何实体,颜色已设置但未应用")
- )
- (princ) ; 静默退出
- )
- ;;; ======================================================
- (princ "\n颜色快捷命令加载成功 (C1-C8/CC)")
- (princ)
 - (defun RandomColor (/ ent color-list) ; 随机颜色命令
- (setq color-list '(
- 40 ;
- 201 ;
- 11 ;
- 110 ;
- 160 ;
- 212 ;
- )) ; 预置颜色
- (while (setq ent (car (entsel "\n选实体: ")))
- (entmod ; 关键修改语句
- (append
- (entget ent)
- (list (cons 62 (nth (rem (getvar "MILLISECS") (length color-list)) color-list)))
 - (defun RandomColorall (/ ent) ; 随机颜色命令
- (while (setq ent (car (entsel "\n选实体: ")))
- (entmod
- (append
- (entget ent)
- (list (cons 62 (1+ (rem (getvar "MILLISECS") 255))))
- )
- )
- )
- (princ)
- )
作为一个子程序用,当选用一个元素作为基准的话,可以清楚的表达一下。实用性可有可无,添加一点制图的趣味性。(PS:个人认为)
|