找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 431|回复: 0

[VBA函数]:CAD的颜色号转成RGB值

[复制链接]

已领礼包: 181个

财富等级: 日进斗金

发表于 2002-12-24 16:25:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×

  1.   [FONT=courier new]
  2. ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  3. '
  4. 'Returns RGB equivalent to passed acad color index (ACI)
  5. '
  6. Public Function AcadToRGB(ByVal Col As Long) As Variant

  7.     Dim R As Long, G As Long, B As Long
  8.    
  9.     Select Case Col
  10.         Case 1: AcadToRGB = 255: Exit Function
  11.         Case 2: AcadToRGB = 65535: Exit Function
  12.         Case 3: AcadToRGB = 65280: Exit Function
  13.         Case 4: AcadToRGB = 16776960: Exit Function
  14.         Case 5: AcadToRGB = 16711680: Exit Function
  15.         Case 6: AcadToRGB = 16711935: Exit Function
  16.         Case 7: AcadToRGB = 16777215: Exit Function
  17.         Case 8: AcadToRGB = 8355711: Exit Function
  18.         Case 9: AcadToRGB = 12566463: Exit Function
  19.         Case 10: AcadToRGB = 255: Exit Function
  20.         Case 11: AcadToRGB = 8355839: Exit Function
  21.         Case 12: AcadToRGB = 207: Exit Function
  22.         Case 13: AcadToRGB = 6316239: Exit Function
  23.         Case 14: AcadToRGB = 144: Exit Function
  24.         Case 15: AcadToRGB = 5197712: Exit Function
  25.         Case 16: AcadToRGB = 127: Exit Function
  26.         Case 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, _
  27.             120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, _
  28.             150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178: R = 0
  29.         Case 88, 188: R = 15
  30.         Case 86, 186: R = 31
  31.         Case 78, 84, 99, 109, 119, 129, 139, 149, 159, 169, 179, 184, 198: R = 32
  32.         Case 82, 89, 182, 189, 250: R = 47
  33.         Case 68, 79, 199, 208: R = 48
  34.         Case 69, 76, 80, 97, 107, 117, 127, 137, 147, 157, 167, 177, 180, 196, 209: R = 63
  35.         Case 18, 19, 28, 29, 38, 39, 48, 49, 58, 59, 74, 87, 95, 105, 115, 125, 135, _
  36.             145, 155, 165, 175, 187, 194, 218, 219, 228, 229, 238, 239, 248, 249: R = 79
  37.         Case 66, 77, 185, 197, 206: R = 95
  38.         Case 72, 85, 93, 103, 113, 123, 133, 143, 153, 163, 173, 192: R = 96
  39.         Case 64, 67, 75, 195, 204, 207: R = 111
  40.         Case 17, 26, 27, 36, 37, 46, 47, 56, 57, 70, 83, 91, 101, 111, 121, 131, _
  41.             141, 151, 161, 171, 183, 190, 216, 217, 226, 227, 236, 237, 246, 247: R = 127
  42.         Case 65, 205, 252: R = 128
  43.         Case 24, 25, 34, 35, 44, 45, 54, 55, 62, 73, 193, 202, 214, 215, 224, 225, _
  44.             234, 235, 244, 245: R = 144
  45.         Case 81, 181: R = 159
  46.         Case 63, 203, 253: R = 175
  47.         Case 60, 71, 191, 200: R = 191
  48.         Case 22, 23, 32, 33, 42, 43, 52, 53, 212, 213, 222, 223, 232, 233, 242, 243: R = 207
  49.         Case 61, 201: R = 223
  50.         Case 20, 21, 30, 31, 40, 41, 50, 51, 210, 211, 220, 221, 230, 231, 240, 241, 255: R = 255
  51.         Case 251: R = 80: G = 80: B = 80
  52.         Case 254: R = 208: G = 208: B = 208
  53.     End Select
  54.    
  55.     Select Case Col
  56.         Case 18, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, _
  57.             196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, _
  58.             226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248: G = 0
  59.         Case 28, 168: G = 15
  60.         Case 26, 166: G = 31
  61.         Case 19, 24, 38, 158, 164, 179, 189, 199, 209, 219, 229, 239, 249: G = 32
  62.         Case 22, 29, 162, 169, 250: G = 47
  63.         Case 39, 48, 148, 159: G = 48
  64.         Case 17, 20, 36, 49, 149, 156, 160, 177, 187, 197, 207, 217, 227, 237, 247: G = 63
  65.         Case 18, 27, 34, 58, 59, 68, 69, 78, 79, 88, 89, 98, 99, 108, 109, 118, 119, _
  66.             128, 129, 138, 139, 154, 167, 175, 185, 195, 205, 215, 225, 235, 245: G = 79
  67.         Case 152: G = 86
  68.         Case 25, 37, 46, 146, 157, 165: G = 95
  69.         Case 32, 173, 183, 193, 203, 213, 223, 233, 243: G = 96
  70.         Case 35, 44, 47, 144, 147, 155: G = 111
  71.         Case 23, 30, 56, 57, 66, 67, 76, 77, 86, 87, 96, 97, 106, 107, 116, 117, _
  72.             126, 127, 136, 137, 150, 163, 171, 181, 191, 201, 211, 221, 231, 241: G = 127
  73.         Case 45, 145, 252: G = 128
  74.         Case 33, 42, 54, 55, 64, 65, 74, 75, 84, 85, 94, 95, 104, 105, 114, 115, _
  75.             124, 125, 134, 135, 142, 153: G = 144
  76.         Case 21, 161: G = 159
  77.         Case 43, 143, 253: G = 175
  78.         Case 31, 40, 140, 151: G = 191
  79.         Case 52, 53, 62, 63, 72, 73, 82, 83, 92, 93, 102, 103, 112, 113, 122, 123, _
  80.             132, 133: G = 207
  81.         Case 41, 141: G = 223
  82.         Case 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101, 110, 111, 120, 121, _
  83.             130, 131, 255: G = 255
  84.     End Select
  85.    
  86.     Select Case Col
  87.         Case 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, _
  88.             54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, _
  89.             92, 94, 96, 98: B = 0
  90.         Case 108, 248: B = 15
  91.         Case 106, 246: B = 31
  92.         Case 19, 29, 39, 49, 59, 69, 79, 89, 99, 104, 118, 238, 244: B = 32
  93.         Case 102, 109, 242, 249, 250: B = 47
  94.         Case 119, 128, 228, 239: B = 48
  95.         Case 17, 27, 37, 47, 57, 67, 77, 87, 97, 100, 116, 129, 229, 236, 240: B = 63
  96.         Case 25, 35, 45, 55, 65, 75, 85, 95, 107, 114, 138, 139, 148, 149, 158, 159, _
  97.             168, 169, 178, 179, 188, 189, 198, 199, 208, 209, 218, 219, 234, 247: B = 79
  98.         Case 105, 117, 126, 226, 237, 245: B = 95
  99.         Case 23, 33, 43, 53, 63, 73, 83, 93, 112, 232: B = 96
  100.         Case 115, 124, 127, 224, 227, 235: B = 111
  101.         Case 21, 31, 41, 51, 61, 71, 81, 91, 103, 110, 136, 137, 146, 147, 156, 157, _
  102.             166, 167, 176, 177, 186, 187, 196, 197, 206, 207, 216, 217, 230, 243: B = 127
  103.         Case 125, 225, 252: B = 128
  104.         Case 113, 122, 134, 135, 144, 145, 154, 155, 164, 165, 174, 175, 184, 185, _
  105.             194, 195, 204, 205, 214, 215, 222, 233: B = 144
  106.         Case 101, 241: B = 159
  107.         Case 123, 223, 253: G = 175
  108.         Case 111, 120, 220, 231: B = 191
  109.         Case 132, 133, 142, 143, 152, 153, 162, 163, 172, 173, 182, 183, 192, 193, _
  110.             202, 203, 212, 213: B = 207
  111.         Case 121: B = 223
  112.         Case 130, 131, 140, 141, 150, 151, 160, 161, 170, 171, 180, 181, 190, 191, _
  113.             200, 201, 210, 211, 221, 255: B = 255
  114.     End Select
  115.    
  116.     AcadToRGB = RGB(R, G, B)
  117.    
  118. End Function
  119.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 07:18 , Processed in 0.176071 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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