明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1149|回复: 7

二种写法,改变线型颜色,命令1~257

  [复制链接]
发表于 2024-2-18 12:42:48 | 显示全部楼层 |阅读模式
本帖最后由 lxf20190917 于 2024-2-18 12:49 编辑

下面说下二种更改线型的代码写法


一、常规的写法,先定义一个函数,再逐行写命令,从1~257。

演示方法一:


  1. ;定义函数 ($lxf:chang-color$ "bylayer")      
  2. ;程序开始
  3. (defun $lxf:chang-color$ (color_number / ss)
  4.   (setvar "cmdecho" 0)
  5.   (setq ss (ssget))
  6.   (while ss
  7.     (if ss (progn(vl-cmdf "_.CHANGE" ss "" "PROPERTIES" "C" color_number "")
  8.     (princ (strcat "\n *颜色改为<" color_number "> _BY 糯米88*"))
  9.     (setq ss (ssget))))(princ)
  10.   )
  11.   (princ)
  12. )
快捷命令为1~257,可以根据自己习惯修改。
  1. (defun c:1()($lxf:chang-color$ "1"))
  2. (defun c:2()($lxf:chang-color$ "2"))
  3. (defun c:3()($lxf:chang-color$ "3"))
  4. (defun c:4()($lxf:chang-color$ "4"))
  5. (defun c:5()($lxf:chang-color$ "5"))
  6. (defun c:6()($lxf:chang-color$ "6"))
  7. (defun c:7()($lxf:chang-color$ "7"))
  8. (defun c:8()($lxf:chang-color$ "8"))
  9. (defun c:9()($lxf:chang-color$ "9"))
  10. (defun c:10()($lxf:chang-color$ "10"))
  11. (defun c:11()($lxf:chang-color$ "11"))
  12. (defun c:12()($lxf:chang-color$ "12"))
  13. (defun c:13()($lxf:chang-color$ "13"))
  14. (defun c:14()($lxf:chang-color$ "14"))
  15. (defun c:15()($lxf:chang-color$ "15"))
  16. (defun c:16()($lxf:chang-color$ "16"))
  17. (defun c:17()($lxf:chang-color$ "17"))
  18. (defun c:18()($lxf:chang-color$ "18"))
  19. (defun c:19()($lxf:chang-color$ "19"))
  20. (defun c:20()($lxf:chang-color$ "20"))
  21. (defun c:21()($lxf:chang-color$ "21"))
  22. (defun c:22()($lxf:chang-color$ "22"))
  23. (defun c:23()($lxf:chang-color$ "23"))
  24. (defun c:24()($lxf:chang-color$ "24"))
  25. (defun c:25()($lxf:chang-color$ "25"))
  26. (defun c:26()($lxf:chang-color$ "26"))
  27. (defun c:27()($lxf:chang-color$ "27"))
  28. (defun c:28()($lxf:chang-color$ "28"))
  29. (defun c:29()($lxf:chang-color$ "29"))
  30. (defun c:30()($lxf:chang-color$ "30"))
  31. (defun c:31()($lxf:chang-color$ "31"))
  32. (defun c:32()($lxf:chang-color$ "32"))
  33. (defun c:33()($lxf:chang-color$ "33"))
  34. (defun c:34()($lxf:chang-color$ "34"))
  35. (defun c:35()($lxf:chang-color$ "35"))
  36. (defun c:36()($lxf:chang-color$ "36"))
  37. (defun c:37()($lxf:chang-color$ "37"))
  38. (defun c:38()($lxf:chang-color$ "38"))
  39. (defun c:39()($lxf:chang-color$ "39"))
  40. (defun c:40()($lxf:chang-color$ "40"))
  41. (defun c:41()($lxf:chang-color$ "41"))
  42. (defun c:42()($lxf:chang-color$ "42"))
  43. (defun c:43()($lxf:chang-color$ "43"))
  44. (defun c:44()($lxf:chang-color$ "44"))
  45. (defun c:45()($lxf:chang-color$ "45"))
  46. (defun c:46()($lxf:chang-color$ "46"))
  47. (defun c:47()($lxf:chang-color$ "47"))
  48. (defun c:48()($lxf:chang-color$ "48"))
  49. (defun c:49()($lxf:chang-color$ "49"))
  50. (defun c:50()($lxf:chang-color$ "50"))
  51. (defun c:51()($lxf:chang-color$ "51"))
  52. (defun c:52()($lxf:chang-color$ "52"))
  53. (defun c:53()($lxf:chang-color$ "53"))
  54. (defun c:54()($lxf:chang-color$ "54"))
  55. (defun c:55()($lxf:chang-color$ "55"))
  56. (defun c:56()($lxf:chang-color$ "56"))
  57. (defun c:57()($lxf:chang-color$ "57"))
  58. (defun c:58()($lxf:chang-color$ "58"))
  59. (defun c:59()($lxf:chang-color$ "59"))
  60. (defun c:60()($lxf:chang-color$ "60"))
  61. (defun c:61()($lxf:chang-color$ "61"))
  62. (defun c:62()($lxf:chang-color$ "62"))
  63. (defun c:63()($lxf:chang-color$ "63"))
  64. (defun c:64()($lxf:chang-color$ "64"))
  65. (defun c:65()($lxf:chang-color$ "65"))
  66. (defun c:66()($lxf:chang-color$ "66"))
  67. (defun c:67()($lxf:chang-color$ "67"))
  68. (defun c:68()($lxf:chang-color$ "68"))
  69. (defun c:69()($lxf:chang-color$ "69"))
  70. (defun c:70()($lxf:chang-color$ "70"))
  71. (defun c:71()($lxf:chang-color$ "71"))
  72. (defun c:72()($lxf:chang-color$ "72"))
  73. (defun c:73()($lxf:chang-color$ "73"))
  74. (defun c:74()($lxf:chang-color$ "74"))
  75. (defun c:75()($lxf:chang-color$ "75"))
  76. (defun c:76()($lxf:chang-color$ "76"))
  77. (defun c:77()($lxf:chang-color$ "77"))
  78. (defun c:78()($lxf:chang-color$ "78"))
  79. (defun c:79()($lxf:chang-color$ "79"))
  80. (defun c:80()($lxf:chang-color$ "80"))
  81. (defun c:81()($lxf:chang-color$ "81"))
  82. (defun c:82()($lxf:chang-color$ "82"))
  83. (defun c:83()($lxf:chang-color$ "83"))
  84. (defun c:84()($lxf:chang-color$ "84"))
  85. (defun c:85()($lxf:chang-color$ "85"))
  86. (defun c:86()($lxf:chang-color$ "86"))
  87. (defun c:87()($lxf:chang-color$ "87"))
  88. (defun c:88()($lxf:chang-color$ "88"))
  89. (defun c:89()($lxf:chang-color$ "89"))
  90. (defun c:90()($lxf:chang-color$ "90"))
  91. (defun c:91()($lxf:chang-color$ "91"))
  92. (defun c:92()($lxf:chang-color$ "92"))
  93. (defun c:93()($lxf:chang-color$ "93"))
  94. (defun c:94()($lxf:chang-color$ "94"))
  95. (defun c:95()($lxf:chang-color$ "95"))
  96. (defun c:96()($lxf:chang-color$ "96"))
  97. (defun c:97()($lxf:chang-color$ "97"))
  98. (defun c:98()($lxf:chang-color$ "98"))
  99. (defun c:99()($lxf:chang-color$ "99"))
  100. (defun c:100()($lxf:chang-color$ "100"))
  101. (defun c:101()($lxf:chang-color$ "101"))
  102. (defun c:102()($lxf:chang-color$ "102"))
  103. (defun c:103()($lxf:chang-color$ "103"))
  104. (defun c:104()($lxf:chang-color$ "104"))
  105. (defun c:105()($lxf:chang-color$ "105"))
  106. (defun c:106()($lxf:chang-color$ "106"))
  107. (defun c:107()($lxf:chang-color$ "107"))
  108. (defun c:108()($lxf:chang-color$ "108"))
  109. (defun c:109()($lxf:chang-color$ "109"))
  110. (defun c:110()($lxf:chang-color$ "110"))
  111. (defun c:111()($lxf:chang-color$ "111"))
  112. (defun c:112()($lxf:chang-color$ "112"))
  113. (defun c:113()($lxf:chang-color$ "113"))
  114. (defun c:114()($lxf:chang-color$ "114"))
  115. (defun c:115()($lxf:chang-color$ "115"))
  116. (defun c:116()($lxf:chang-color$ "116"))
  117. (defun c:117()($lxf:chang-color$ "117"))
  118. (defun c:118()($lxf:chang-color$ "118"))
  119. (defun c:119()($lxf:chang-color$ "119"))
  120. (defun c:120()($lxf:chang-color$ "120"))
  121. (defun c:121()($lxf:chang-color$ "121"))
  122. (defun c:122()($lxf:chang-color$ "122"))
  123. (defun c:123()($lxf:chang-color$ "123"))
  124. (defun c:124()($lxf:chang-color$ "124"))
  125. (defun c:125()($lxf:chang-color$ "125"))
  126. (defun c:126()($lxf:chang-color$ "126"))
  127. (defun c:127()($lxf:chang-color$ "127"))
  128. (defun c:128()($lxf:chang-color$ "128"))
  129. (defun c:129()($lxf:chang-color$ "129"))
  130. (defun c:130()($lxf:chang-color$ "130"))
  131. (defun c:131()($lxf:chang-color$ "131"))
  132. (defun c:132()($lxf:chang-color$ "132"))
  133. (defun c:133()($lxf:chang-color$ "133"))
  134. (defun c:134()($lxf:chang-color$ "134"))
  135. (defun c:135()($lxf:chang-color$ "135"))
  136. (defun c:136()($lxf:chang-color$ "136"))
  137. (defun c:137()($lxf:chang-color$ "137"))
  138. (defun c:138()($lxf:chang-color$ "138"))
  139. (defun c:139()($lxf:chang-color$ "139"))
  140. (defun c:140()($lxf:chang-color$ "140"))
  141. (defun c:141()($lxf:chang-color$ "141"))
  142. (defun c:142()($lxf:chang-color$ "142"))
  143. (defun c:143()($lxf:chang-color$ "143"))
  144. (defun c:144()($lxf:chang-color$ "144"))
  145. (defun c:145()($lxf:chang-color$ "145"))
  146. (defun c:146()($lxf:chang-color$ "146"))
  147. (defun c:147()($lxf:chang-color$ "147"))
  148. (defun c:148()($lxf:chang-color$ "148"))
  149. (defun c:149()($lxf:chang-color$ "149"))
  150. (defun c:150()($lxf:chang-color$ "150"))
  151. (defun c:151()($lxf:chang-color$ "151"))
  152. (defun c:152()($lxf:chang-color$ "152"))
  153. (defun c:153()($lxf:chang-color$ "153"))
  154. (defun c:154()($lxf:chang-color$ "154"))
  155. (defun c:155()($lxf:chang-color$ "155"))
  156. (defun c:156()($lxf:chang-color$ "156"))
  157. (defun c:157()($lxf:chang-color$ "157"))
  158. (defun c:158()($lxf:chang-color$ "158"))
  159. (defun c:159()($lxf:chang-color$ "159"))
  160. (defun c:160()($lxf:chang-color$ "160"))
  161. (defun c:161()($lxf:chang-color$ "161"))
  162. (defun c:162()($lxf:chang-color$ "162"))
  163. (defun c:163()($lxf:chang-color$ "163"))
  164. (defun c:164()($lxf:chang-color$ "164"))
  165. (defun c:165()($lxf:chang-color$ "165"))
  166. (defun c:166()($lxf:chang-color$ "166"))
  167. (defun c:167()($lxf:chang-color$ "167"))
  168. (defun c:168()($lxf:chang-color$ "168"))
  169. (defun c:169()($lxf:chang-color$ "169"))
  170. (defun c:170()($lxf:chang-color$ "170"))
  171. (defun c:171()($lxf:chang-color$ "171"))
  172. (defun c:172()($lxf:chang-color$ "172"))
  173. (defun c:173()($lxf:chang-color$ "173"))
  174. (defun c:174()($lxf:chang-color$ "174"))
  175. (defun c:175()($lxf:chang-color$ "175"))
  176. (defun c:176()($lxf:chang-color$ "176"))
  177. (defun c:177()($lxf:chang-color$ "177"))
  178. (defun c:178()($lxf:chang-color$ "178"))
  179. (defun c:179()($lxf:chang-color$ "179"))
  180. (defun c:180()($lxf:chang-color$ "180"))
  181. (defun c:181()($lxf:chang-color$ "181"))
  182. (defun c:182()($lxf:chang-color$ "182"))
  183. (defun c:183()($lxf:chang-color$ "183"))
  184. (defun c:184()($lxf:chang-color$ "184"))
  185. (defun c:185()($lxf:chang-color$ "185"))
  186. (defun c:186()($lxf:chang-color$ "186"))
  187. (defun c:187()($lxf:chang-color$ "187"))
  188. (defun c:188()($lxf:chang-color$ "188"))
  189. (defun c:189()($lxf:chang-color$ "189"))
  190. (defun c:190()($lxf:chang-color$ "190"))
  191. (defun c:191()($lxf:chang-color$ "191"))
  192. (defun c:192()($lxf:chang-color$ "192"))
  193. (defun c:193()($lxf:chang-color$ "193"))
  194. (defun c:194()($lxf:chang-color$ "194"))
  195. (defun c:195()($lxf:chang-color$ "195"))
  196. (defun c:196()($lxf:chang-color$ "196"))
  197. (defun c:197()($lxf:chang-color$ "197"))
  198. (defun c:198()($lxf:chang-color$ "198"))
  199. (defun c:199()($lxf:chang-color$ "199"))
  200. (defun c:200()($lxf:chang-color$ "200"))
  201. (defun c:201()($lxf:chang-color$ "201"))
  202. (defun c:202()($lxf:chang-color$ "202"))
  203. (defun c:203()($lxf:chang-color$ "203"))
  204. (defun c:204()($lxf:chang-color$ "204"))
  205. (defun c:205()($lxf:chang-color$ "205"))
  206. (defun c:206()($lxf:chang-color$ "206"))
  207. (defun c:207()($lxf:chang-color$ "207"))
  208. (defun c:208()($lxf:chang-color$ "208"))
  209. (defun c:209()($lxf:chang-color$ "209"))
  210. (defun c:210()($lxf:chang-color$ "210"))
  211. (defun c:211()($lxf:chang-color$ "211"))
  212. (defun c:212()($lxf:chang-color$ "212"))
  213. (defun c:213()($lxf:chang-color$ "213"))
  214. (defun c:214()($lxf:chang-color$ "214"))
  215. (defun c:215()($lxf:chang-color$ "215"))
  216. (defun c:216()($lxf:chang-color$ "216"))
  217. (defun c:217()($lxf:chang-color$ "217"))
  218. (defun c:218()($lxf:chang-color$ "218"))
  219. (defun c:219()($lxf:chang-color$ "219"))
  220. (defun c:220()($lxf:chang-color$ "220"))
  221. (defun c:221()($lxf:chang-color$ "221"))
  222. (defun c:222()($lxf:chang-color$ "222"))
  223. (defun c:223()($lxf:chang-color$ "223"))
  224. (defun c:224()($lxf:chang-color$ "224"))
  225. (defun c:225()($lxf:chang-color$ "225"))
  226. (defun c:226()($lxf:chang-color$ "226"))
  227. (defun c:227()($lxf:chang-color$ "227"))
  228. (defun c:228()($lxf:chang-color$ "228"))
  229. (defun c:229()($lxf:chang-color$ "229"))
  230. (defun c:230()($lxf:chang-color$ "230"))
  231. (defun c:231()($lxf:chang-color$ "231"))
  232. (defun c:232()($lxf:chang-color$ "232"))
  233. (defun c:233()($lxf:chang-color$ "233"))
  234. (defun c:234()($lxf:chang-color$ "234"))
  235. (defun c:235()($lxf:chang-color$ "235"))
  236. (defun c:236()($lxf:chang-color$ "236"))
  237. (defun c:237()($lxf:chang-color$ "237"))
  238. (defun c:238()($lxf:chang-color$ "238"))
  239. (defun c:239()($lxf:chang-color$ "239"))
  240. (defun c:240()($lxf:chang-color$ "240"))
  241. (defun c:241()($lxf:chang-color$ "241"))
  242. (defun c:242()($lxf:chang-color$ "242"))
  243. (defun c:243()($lxf:chang-color$ "243"))
  244. (defun c:244()($lxf:chang-color$ "244"))
  245. (defun c:245()($lxf:chang-color$ "245"))
  246. (defun c:246()($lxf:chang-color$ "246"))
  247. (defun c:247()($lxf:chang-color$ "247"))
  248. (defun c:248()($lxf:chang-color$ "248"))
  249. (defun c:249()($lxf:chang-color$ "249"))
  250. (defun c:250()($lxf:chang-color$ "250"))
  251. (defun c:251()($lxf:chang-color$ "251"))
  252. (defun c:252()($lxf:chang-color$ "252"))
  253. (defun c:253()($lxf:chang-color$ "253"))
  254. (defun c:254()($lxf:chang-color$ "254"))
  255. (defun c:255()($lxf:chang-color$ "255"))
  256. (defun c:256()($lxf:chang-color$ "bylayer"))
  257. (defun c:257()($lxf:chang-color$ "Byblock"))
  258. (princ)

二、简易写法

  1. (DEFUN $dfg:lxf_numcolor$ (/ I X)
  2. (setq I 1)
  3. (REPEAT 257
  4. (cond ((= i 256)
  5.        (progn (setq X
  6.          (STRCAT "(defun c:"
  7.            (ITOA I)
  8.            "()(setvar "cmdecho" 0)(princ " "
  9.            (STRCAT
  10.              " 颜色改为< "
  11.              "随层"
  12.              " >号色 ")(if (setq ss (ssget))"
  13.              "(vl-cmdf "change" ss "" "properties" "c" ""
  14.              "bylayer"
  15.              "" "")))"
  16.             )
  17.            "(princ)"
  18.          )
  19.         )
  20.         (if X
  21.     (PROGN (EVAL (READ X)))
  22.         )
  23.        )
  24.       )
  25.       ((= i 257)
  26.        (progn (setq X
  27.          (STRCAT "(defun c:"
  28.            (ITOA I)
  29.            "()(setvar "cmdecho" 0)(princ " "
  30.            (STRCAT
  31.              " 颜色改为< "
  32.              "随层"
  33.              " >号色 ")(if (setq ss (ssget))"
  34.              "(vl-cmdf "change" ss "" "properties" "c" ""
  35.              "Byblock"
  36.              "" "")))"
  37.             )
  38.            "(princ)"
  39.          )
  40.         )
  41.         (if X
  42.     (PROGN (EVAL (READ X)))
  43.         )
  44.        )
  45.       )
  46.       (t
  47.        (progn (setq X
  48.          (STRCAT
  49.            "(defun c:"
  50.            (ITOA I)
  51.            "()(setvar "cmdecho" 0)(princ " "
  52.            (STRCAT " 颜色改为< "
  53.              (ITOA I)
  54.              " >号色 ")(if (setq ss (ssget))"
  55.              "(vl-cmdf "change" ss "" "properties" "c" ""
  56.              (ITOA I)
  57.              "" "")))"
  58.            )
  59.            "(princ)"
  60.          )
  61.         )
  62.         (if X
  63.     (PROGN (EVAL (READ X)))
  64.         )
  65.        )
  66.       )
  67. )
  68.     (setq I (1+ I))
  69.   )
  70. )
  1. (defun c:jzys();加载颜色 更改颜色快捷命令为1~257
  2.   ($dfg:lxf_numcolor$))



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 3明经币 +3 收起 理由
zhoupeng220 + 1 很给力!
bssurvey + 1 赞一个!
ssyfeng + 1 赞一个!

查看全部评分

发表于 2024-2-19 17:42:44 | 显示全部楼层
颜色是0~256,没有257
发表于 2024-2-19 17:49:50 | 显示全部楼层
学习了,感谢楼主分享
 楼主| 发表于 2024-2-19 21:13:31 | 显示全部楼层
437271963 发表于 2024-2-19 17:42
颜色是0~256,没有257

257,我加了一个随块。
发表于 2024-2-22 22:10:51 | 显示全部楼层
  1. ;一次定义N个命令1~255
  2. (defun c:tt (/ i)
  3.   (setq i 1)
  4.   (repeat 255
  5.     (eval (read (strcat "(defun c:" (itoa i) "()($lxf:chang-color$ \"" (itoa i) "\"))")))
  6.     (setq i (1+ i))
  7.   )
  8.   (princ)
  9. )

发表于 2024-6-2 23:15:39 | 显示全部楼层
谢谢分享 方便好用
发表于 2024-6-3 14:34:02 | 显示全部楼层
学习了,感谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 04:31 , Processed in 0.182428 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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