乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 81|回复: 5

[编程交流] 使用Entmake创建层wi

[复制链接]

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-5 23:43:58 | 显示全部楼层 |阅读模式
如何将图层颜色设置为truecolour?当我尝试使用cons 62时,我总是会出错。我试着创建一个新的变量,设置为truecolour,然后将cons 62设置为该值,但没有乐趣。
回复

使用道具 举报

15

主题

209

帖子

121

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 00:04:20 | 显示全部楼层
 
以下是一些可能有用的信息
 
  1. ;;;    Copyright (C) 2003 by Autodesk, Inc.
  2. ;;;
  3. ;;;    Permission to use, copy, modify, and distribute this software
  4. ;;;    for any purpose and without fee is hereby granted, provided
  5. ;;;    that the above copyright notice appears in all copies and
  6. ;;;    that both that copyright notice and the limited warranty and
  7. ;;;    restricted rights notice below appear in all supporting
  8. ;;;    documentation.
  9. ;;;
  10. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  11. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  12. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  13. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  14. ;;;    UNINTERRUPTED OR ERROR FREE.
  15. ;;;
  16. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  17. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  18. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
  19. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  20. ;;;
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;; This file contains lisp utilities for dealing with true color in AutoCAD.
  24. ;;
  25. ;; AutoCAD describes true color with 24 bit integer values where
  26. ;;  - blue is the first byte
  27. ;;  - green is the second and
  28. ;;  - red is the third byte
  29. ;;
  30. ;;  (Careful... This is not exactly a RGB value. It is a BGR.)
  31. ;;
  32. ;; Within the scope of this file, the term "TrueColor" refers to one of these 24 bit
  33. ;; values. The term "ColorIndex" will be used to refer to the traditional AutoCAD
  34. ;; colors that range from 0 through 256 (where 0 and 256 have the special meanings of
  35. ;; "ByBlock" and "ByLayer" respectively)
  36. ;;
  37. ;;-------------------------------------
  38. ;; Entity lists and dxf group codes:
  39. ;;-------------------------------------
  40. ;; DXF
  41. ;;  62  - ColorIndex values are still represented with the 62 dxf group code (same as in
  42. ;;        previous AutoCAD releases).
  43. ;;
  44. ;;  420 - TrueColor values are associated with the new 420 dxf group code.
  45. ;;        For example: You might find (420 . 255) within the entity list of a blue entity.
  46. ;;
  47. ;;  430 - Contains a color book and color name description string. This is used only for
  48. ;;        informational purposes. Actual entity color is governed by 62 and/or 420 group
  49. ;;        codes.
  50. ;;
  51. ;;Entity lists...
  52. ;;
  53. ;; Entget:
  54. ;;  No 62 pair present - If no 62 group code is present then the object's color is assumed to be
  55. ;;                       ByLayer. In other words; No behavior change from previous releases.
  56. ;;                       (The 420 and 430 pairs will not be present either)
  57. ;;
  58. ;;  62 only            - Object's color is by ColorIndex (also refered to as ByACI)
  59. ;;
  60. ;;  62 and 420         - Object's color is TrueColor and is fully described by the 420 group code.
  61. ;;                       The 62 pair will contain the colorindex that most closely matches the true
  62. ;;                       color.
  63. ;;
  64. ;;  62, 420 and 430    - Object color was chosen from a color book. The 430 contains a textual description
  65. ;;                       of the form "'colorbook$colorname". The 420 pair describes the
  66. ;;                       corresponding truecolor and the 62 contains the closest matching color
  67. ;;                       index.
  68. ;;                       
  69. ;;
  70. ;; Entmod and Entmake:
  71. ;;  The 420 group code takes precedence over the 62 group code. That is; entmake or entmod will
  72. ;;  use the 420 group code if it is present and will ignore the 62 group code in the provided
  73. ;;  entity list. If a 420 is _not_ present in the entity list, then the 62 group code will
  74. ;;  be used. The 430 group code is for informational purposes only and does not have
  75. ;;  any effect on displayed color.
  76. ;;
  77. ;;-------------------------------------
  78. ;; Two new built in lisp functions:  Acad_TrueColorDlg and Acad_TrueColorCli
  79. ;;-------------------------------------
  80. ;;
  81. ;;  Acad_TrueColorDlg is somewhat similar to the existing acad_colordlg function.
  82. ;;        Signature:
  83. ;;          (acad_truecolordlg color [allowbylayer] [currentlayercolor])
  84. ;;
  85. ;;            Where "color" is a dotted pair that describes the default color. The first element
  86. ;;            of the dotted pair must be one of the color dxf group codes (62, 420, or 430).
  87. ;;            For example:
  88. ;;              (62 . ColorIndex)
  89. ;;              (420 . TrueColor)
  90. ;;              (430 . "colorbook$colorname")
  91. ;;
  92. ;;            If the optional [allowbylayer] parameter is present and non-nil, then the bylayer and
  93. ;;            byblock buttons will be enabled. If this parameter is missing, the value defaults to
  94. ;;            T and the bylayer/bylbock buttons will be enabled.
  95. ;;
  96. ;;            The optional [curLayerColor] parameter controls the color of the bylayer/byblock color
  97. ;;            in the dialog. This parameter is also a dotted pair like the first color parameter.
  98. ;;            
  99. ;;            Returns nil if the user canceled.
  100. ;;            On success, the function returns a list of one or more dotted pairs that fully describe the
  101. ;;            chosen color. The last dotted pair in this list indicates, specifically, the color that was
  102. ;;            chosen. Additional details on the return list follow...
  103. ;;
  104. ;;            ColorBook color - If the last item in the returned list is a 430 pair, then the specified
  105. ;;                              color originates from a colorbook. (This returned list will also contain
  106. ;;                              a 420 pair that describes the corresponding truecolor and a 62 pair that
  107. ;;                              describes the closest matching colorindex value.)
  108. ;;
  109. ;;            True Color      - If the returned list contains a 420 pair as the last item, then
  110. ;;                              a true color was specified (as "Red,Green,Blue"). The list will
  111. ;;                              also contain a 62 pair that indicates the closest matching colorindex.
  112. ;;                              (No 430 pair will be present)
  113. ;;
  114. ;;            Color Index     - If the last item in the list is a 62 pair, then a colorindex was chosen.
  115. ;;                              (no other dotted pairs will be present in the returned list)
  116. ;;
  117. ;;         Examples of usage:
  118. ;;                 (acad_truecolordlg '(62 . 1))
  119. ;;                 (acad_truecolordlg '(420 . 2686760))
  120. ;;                 (acad_truecolordlg '(430 . "Color Book Sample File$Sample 0C"))
  121. ;;                 (acad_truecolordlg '(420 . 2686760) nil)
  122. ;;
  123. ;;            
  124. ;;
  125. ;;  Acad_TrueColorCli is the command line counterpart to acad_truecolordlg. It prompts at the command line
  126. ;;                    for a color.
  127. ;;        Signature:
  128. ;;          (acad_truecolorcli color [allowbylayer] [alternatePrompt])
  129. ;;
  130. ;;            The first two parameters are identical to acad_truecolordlg, and the third parameter
  131. ;;            is an optional prompt string. If this string is omited, the default value is "New color ".
  132. ;;
  133. ;;            Some examples of lists returned by acad_truecolordlg and acad_truecolorcli:
  134. ;;             Color book color:  ((62 . 80) (420 . 2686760) (430 . "Color Book Sample File$Sample 0B"))
  135. ;;                   True color:  ((62 . 162) (420 . 2114527))
  136. ;;                  color index:  ((62 . 110))
  137. ;;
  138. ;;
  139. ;;
  140. ;;
  141. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  142. ;; Get the red component of a TrueColor number
  143. ;;
  144. (defun TrueColor-red-value ( c / )
  145. (lsh (fix c) -16)
  146. );defun TrueColor-red-value
  147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  148. ;; Get the green component of a TrueColor number
  149. ;;
  150. (defun TrueColor-green-value ( c / r )
  151. (lsh (lsh (fix c) 16) -24)
  152. );defun TrueColor-green-value
  153. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  154. ;; Get the blue component of a TrueColor number
  155. ;;
  156. (defun TrueColor-blue-value ( c / )
  157. (lsh (lsh (fix c) 24) -24)
  158. );defun TrueColor-blue-value
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;; TrueColor-split - takes a TrueColor number and returns a list of integers the form '(red green blue)
  161. ;;
  162. (defun TrueColor-split ( c / )
  163. (list (lsh (fix c) -16)
  164.       (lsh (lsh (fix c) 16) -24)
  165.       (lsh (lsh (fix c) 24) -24)
  166. )
  167. );defun TrueColor-split
  168. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  169. ;; TrueColor-make - takes TrueColor components (red green blue) and creates a single TrueColor integer
  170. ;;
  171. (defun TrueColor-make ( r g b /  )
  172. (+ (lsh (fix r) 16)
  173.    (lsh (fix g)  
  174.    (fix b)
  175. )
  176. );defun TrueColor-make
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. ;; TrueColor-to-ColorIndex - takes a TrueColor value and returns the closest AutoCAD color index (1-255)
  179. ;; NOTE: This is an approximation. The return color index is the AutoCAD color index that most
  180. ;;       closely matches the provided TrueColor.
  181. ;;
  182. (defun TrueColor-to-ColorIndex ( TrueColor / colorObj ci )
  183. (vl-load-com)
  184. (and (setq colorObj (vla-getinterfaceobject (vlax-get-acad-object) "AutoCAD.AcCmColor.16"))
  185.      (not (vl-catch-all-error-p
  186.            (vl-catch-all-apply 'vla-setRGB (cons colorObj (TrueColor-split TrueColor)))
  187.           )
  188.      )
  189.      (setq ci (vla-get-ColorIndex colorObj))
  190. );and
  191. ci
  192. );defun TrueColor-to-ColorIndex
  193. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194. ;; ColorIndex-to-TrueColor - takes an AutoCAD color index (1 through 255) and returns the equivalent
  195. ;; TrueColor value.
  196. ;;
  197. (defun ColorIndex-to-TrueColor ( ci / colorObj TrueColor )
  198. (vl-load-com)
  199. (and (setq colorObj (vla-getinterfaceobject (vlax-get-acad-object) "AutoCAD.AcCmColor.16"))
  200.      (>= ci 1)
  201.      (<= ci 255)
  202.      (not (vl-catch-all-error-p
  203.            (vl-catch-all-apply 'vla-put-ColorIndex (list colorObj ci))
  204.           )
  205.      )
  206.      (setq TrueColor (TrueColor-make
  207.                          (vla-get-red   colorObj)
  208.                          (vla-get-green colorObj)
  209.                          (vla-get-blue  colorObj)
  210.                      )
  211.      );setq
  212. );and
  213. TrueColor
  214. );defun ColorIndex-to-TrueColor
  215. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  216. ;; colorname-to-truecolor - converts a string of the form "colorbook$colorname" to a TrueColor value.
  217. ;;
  218. (defun colorname-to-truecolor ( colorbookandname / pos colorbook colorname colorObj TrueColor )
  219. (vl-load-com)
  220. (and (equal (type colorbookandname) 'STR)
  221.      (setq pos (vl-string-search "$" colorbookandname))
  222.      (setq colorbook (substr colorbookandname 1 pos)
  223.            colorname (substr colorbookandname (+ pos 2))
  224.      );setq
  225.      (setq colorObj (vla-getinterfaceobject (vlax-get-acad-object) "AutoCAD.AcCmColor.16"))
  226.      (not (vl-catch-all-error-p
  227.            (vl-catch-all-apply 'vla-SetColorBookColor (list colorObj colorbook colorname))
  228.           )
  229.      )
  230.      (setq TrueColor (TrueColor-make
  231.                          (vla-get-red   colorObj)
  232.                          (vla-get-green colorObj)
  233.                          (vla-get-blue  colorObj)
  234.                      )
  235.      );setq
  236. );and
  237. TrueColor
  238. );defun colorname-to-truecolor
  239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  240. ;; TrueColor-to-RGBstring - Takes a TrueColor (24 bit value) and returns a string of the
  241. ;;                          form: "Red,Green,Blue"
  242. ;;
  243. (defun TrueColor-to-RGBstring ( TrueColor / rgb )
  244. (and truecolor
  245.      (setq rgb (mapcar 'itoa (truecolor-split truecolor)))
  246.      (setq rgb (strcat (car rgb) "," (cadr rgb) "," (caddr rgb)))
  247. )
  248. rgb
  249. );defun TrueColor-to-RGBstring
  250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  251. ;; ssget-ColorIndex-filter -
  252. ;; Takes an AutoCAD color index  (0 through 256) and
  253. ;; returns a dxf group code list that can be used with (ssget ...) to
  254. ;; select all objects that "exactly" match the specified AutoCAD ColorIndex.
  255. ;; This allows you to filter for objects that are of a specific AutoCAD
  256. ;; ColorIndex (0-256) but are not assigned a true-color value.
  257. ;;
  258. ;; For example:
  259. ;;  The following will return a selection set that contains "red" objects
  260. ;;  _and_ objects that are assigned a true color that is merely "close" to red.
  261. ;;
  262. ;;   (setq ss (ssget "_x" '((62 . 1))))
  263. ;;
  264. ;; If you do not want true-color objects and only want to select objects that are
  265. ;; explicitly set to color number 1 ("red") then you can use the following code.
  266. ;; This will return a selection set of all non-true-color entities that are color 1.
  267. ;;
  268. ;;   (setq ss (ssget "_x" (ssget-ColorIndex-filter 1)))
  269. ;;
  270. ;;
  271. ;;
  272. (defun ssget-ColorIndex-filter ( ColorIndex / )
  273. (list (cons 62 ColorIndex) '(-4 . "<NOT") '(-4 . "*") '(420 . 0) '(-4 . "NOT>"))
  274. )
  275. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  276. ;; entlist-set-ColorIndex
  277. ;; Takes an entity list and an AutoCAD ColorIndex (0 through 256)
  278. ;; Returns the entity list with the specified color setting applied.
  279. ;; This returned list can then be used with (entmake ...) or (entmod ...).
  280. ;; NOTE: This function does _not_ call entnake or entmod. It only manipulates
  281. ;;       the provided list and returns the resulting list.
  282. ;;
  283. ;; Backround:
  284. ;;  If a 420 group code pair (true color) is present in an entity list, entmake and entmod
  285. ;; will ignore the 62 group code (AutoCAD ColorIndex). In order to set a color index
  286. ;; using entmod or entmake, the provided list must not contain a 420 group code.
  287. ;;  This function allows you to apply a specific AutoCAD ColorIndex value to an entity list
  288. ;; by removing the 420 group code (if present) and inserting the specified ColorIndex with
  289. ;; a 62 group code pair.
  290. ;;
  291. ;; (provide a ColorIndex of 0 for ByBlock and 256 for ByLayer)
  292. ;;
  293. (defun entlist-set-ColorIndex ( entlist ColorIndex / ci )
  294. (setq entlist (vl-remove (assoc 420 entlist) entlist))
  295. (if (setq ci (assoc 62 entlist))
  296.      (setq entlist (subst (cons 62 ColorIndex) ci entlist))
  297.      (setq entlist (append entlist (list (cons 62 ColorIndex))))
  298. );if
  299. );defun entlist-set-ColorIndex
  300. (princ)

 
但图层颜色最终为147100196。有人有什么想法吗?
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 00:16:54 | 显示全部楼层
这不可能是正确的Woodman,因为127100100大于TrueColour最大值16777215(=255x65536+255x256+255)
 
使用
 
  1.      (cons 0 "LAYER")
  2.        (cons 100 "AcDbSymbolTableRecord")
  3.        (cons 100 "AcDbLayerTableRecord")
  4.        (cons 2 b)
  5.        (cons 6 a)
  6.        (cons 62 1)
  7.        (cons 420 127100100)
  8.        (cons 70 0)
  9.        (cons 370 lw))))

 
以获得正确的颜色代码。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:20:24 | 显示全部楼层
首先,你可以像李·麦克说的那样得到真彩色数字。
那么,这对我来说很有用:
 
  1. (defun TrueColor-make ( r g b /  )
  2. (+ (lsh (fix r) 16)
  3.    (lsh (fix g)  
  4.    (fix b)
  5. )
  6. )
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 00:39:17 | 显示全部楼层
我来到这个线程,试图将RGB颜色添加到伟大的TimSpangler的图层创建程序中。但是我的编程技巧是无用的。
蒂姆,你会更新你的lisp来支持RGB颜色吗?
那你呢
回复

使用道具 举报

6

主题

22

帖子

16

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 00:55:50 | 显示全部楼层
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:36 , Processed in 0.384613 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表