找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1445|回复: 5

[求助]:有人知道Excel中的Color和ColorIndex同AutoCAD的ACI/TrueColor之间的转换关系

[复制链接]
发表于 2003-8-26 11:06:51 | 显示全部楼层 |阅读模式

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

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

×
有人知道Excel中的Color和ColorIndex同AutoCAD的ACI/TrueColor之间的转换关系吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 593个

财富等级: 财运亨通

发表于 2003-8-26 12:38:14 | 显示全部楼层
DSX 网站有个程序,改屏幕颜色,里面有对应表。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 23个

财富等级: 恭喜发财

发表于 2003-8-26 12:47:00 | 显示全部楼层
明经那里有
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2003-8-27 09:20:08 | 显示全部楼层
都没有找到,请提供具体链接地址,谢谢
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 593个

财富等级: 财运亨通

发表于 2003-8-27 22:57:35 | 显示全部楼层
最初由 mmmm 发布
[B]都没有找到,请提供具体链接地址,谢谢 [/B]

  1. <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" height="498">
  2.   <tr>
  3.     <td width="100%" height="489">
  4.       <iframe name="I1" width="100%" height="100%" src="http://www.jtbworld.com/?/lisp/DisplayColorProperties.htm">
  5. 浏览器不支持嵌入式框架或配置为不显示嵌入式框架
  6.       </iframe>
  7.     </td>
  8.   </tr>
  9. </table>
复制代码


  1. <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" height="498">
  2.   <tr>
  3.     <td width="100%" height="489">
  4.       <iframe name="I1" width="100%" height="100%" src="http://www.menziengineering.ch/Downloads/Download.htm#13">
  5. 浏览器不支持嵌入式框架或配置为不显示嵌入式框架
  6.       </iframe>
  7.     </td>
  8.   </tr>
  9. </table>
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 181个

财富等级: 日进斗金

发表于 2003-9-25 20:12:00 | 显示全部楼层
重新将代码整理在下面:

  1.   [FONT=courier new]
  2. ;;; DisplayColorProperties.LSP
  3. ;;; Miscellaneous commands related to Colors on the Display tab on the Options dialog
  4. ;;; By Jimmy Bergmark
  5. ;;; Copyright (C) 1997-2003 JTB World, All Rights Reserved
  6. ;;; Website: [url]www.jtbworld.com[/url] / [url]http://jtbworld.vze.com[/url]
  7. ;;; E-mail: [email]info@jtbworld.com[/email] / [email]jtbworld@hotmail.com[/email]
  8. ;;; 2000-03-29 - First release
  9. ;;; 2003-03-07 - Now for AutoCAD 2004
  10. ;;; 2003-05-14 - Added ACI to RGB conversion
  11. ;;; Tested on AutoCAD 2000, 2000i, 2002 and 2004
  12. ;;; Some bugs exist with the conversions of colors from RGB to ACI.

  13. (vl-load-com)

  14. (setq pref (vla-get-preferences (vlax-get-acad-object)))

  15. (setq display (vla-get-display pref))

  16. ;;; Set the ModelColor using the color dialog box
  17. (defun c:SetModelColor(/ col oldcol)
  18.   (setq oldcol (getGraphicsWinModelBackgrndColor))
  19.   (if (= oldcol nil) (setq oldcol 0))
  20.   (if (= oldcol 0) (setq oldcol 1))
  21.   (setq col (acad_colordlg oldcol nil))
  22.   (if (and (= oldcol 7) (= col 7)) (setq col 0))
  23.   (if (/= col nil) (putGraphicsWinModelBackgrndColor col))
  24.   (princ)
  25. )
  26. (defun c:SetModelColor2004(/ col oldcol)
  27.   (setq oldcol (getGraphicsWinModelBackgrndColor2004))
  28.   (if (= oldcol nil) (setq oldcol 0))
  29.   (if (= oldcol 0) (setq oldcol 1))
  30.   (setq col (acad_colordlg oldcol nil))
  31.   (if (and (= oldcol 7) (= col 7)) (setq col 0))
  32.   (if (/= col nil) (putGraphicsWinModelBackgrndColor col))
  33.   (princ)
  34. )

  35. ;;; Set the LayoutColor using the color dialog box
  36. (defun c:SetLayoutColor(/ col oldcol)
  37.   (setq oldcol (getGraphicsWinLayoutBackgrndColor))
  38.   (if (= oldcol nil) (setq oldcol 0))
  39.   (if (= oldcol 0) (setq oldcol 1))
  40.   (setq col (acad_colordlg oldcol nil))
  41.   (if (and (= oldcol 7) (= col 7)) (setq col 0))
  42.   (if (/= col nil) (putGraphicsWinLayoutBackgrndColor col))
  43.   (princ)
  44. )

  45. (defun getGraphicsWinModelBackgrndColor()
  46.   (OLE_color->ACI_color
  47.     (vla-get-GraphicsWinModelBackgrndColor
  48.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  49. )

  50. (defun getGraphicsWinModelBackgrndColor2004 ()
  51.   (OLE_colorToACI
  52.     (vlax-variant-value
  53.       (vlax-variant-change-type
  54.         (vla-get-GraphicsWinModelBackgrndColor
  55.           (vla-get-display
  56.             (vla-get-preferences (vlax-get-acad-object))
  57.           )
  58.         )
  59.         vlax-vbLong
  60.       )
  61.     )
  62.   )
  63. )

  64. (defun putGraphicsWinModelBackgrndColor(col)
  65.   (vla-put-GraphicsWinModelBackgrndColor
  66.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  67.     (ACI_color->OLE_color col)
  68.   )
  69. )

  70. (defun getGraphicsWinLayoutBackgrndColor()
  71.   (OLE_color->ACI_color
  72.     (vla-get-GraphicsWinLayoutBackgrndColor
  73.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  74. )

  75. (defun putGraphicsWinLayoutBackgrndColor(col)
  76.   (vla-put-GraphicsWinLayoutBackgrndColor
  77.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  78.     (ACI_color->OLE_color col)
  79.   )
  80. )

  81. (defun getModelCrosshairColor()
  82.   (OLE_color->ACI_color
  83.     (vla-get-ModelCrosshairColor
  84.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  85. )

  86. (defun putModelCrosshairColor(col)
  87.   (vla-put-ModelCrosshairColor
  88.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  89.     (ACI_color->OLE_color col)
  90.   )
  91. )

  92. (defun getLayoutCrosshairColor()
  93.   (OLE_color->ACI_color
  94.     (vla-get-LayoutCrosshairColor
  95.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  96. )

  97. (defun putLayoutCrosshairColor(col)
  98.   (vla-put-LayoutCrosshairColor
  99.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  100.     (ACI_color->OLE_color col)
  101.   )
  102. )

  103. (defun getTextWinBackgrndColor()
  104.   (OLE_color->ACI_color
  105.     (vla-get-TextWinBackgrndColor
  106.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  107. )

  108. (defun putTextWinBackgrndColor(col)
  109.   (vla-put-TextWinBackgrndColor
  110.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  111.     (ACI_color->OLE_color col)
  112.   )
  113. )

  114. (defun getTextWinTextColor()
  115.   (OLE_color->ACI_color
  116.     (vla-get-TextWinTextColor
  117.       (vla-get-display (vla-get-preferences (vlax-get-acad-object)))))
  118. )

  119. (defun putTextWinTextColor(col)
  120.   (vla-put-TextWinTextColor
  121.     (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  122.     (ACI_color->OLE_color col)
  123.   )
  124. )

  125. (defun getAutoTrackingVecColor()
  126.   (OLE_color->ACI_color
  127.     (vla-get-AutoTrackingVecColor
  128.       display))
  129. )

  130. (defun putAutoTrackingVecColor(col)
  131.   (vla-put-AutoTrackingVecColor
  132.     display
  133.     (ACI_color->OLE_color col)
  134.   )
  135. )

  136. (defun OLE_color->ACI_color (olec)
  137.   (vl-position
  138.     (boole 1
  139.            (vlax-variant-value
  140.              (vlax-variant-change-type olec vlax-vbLong)
  141.            )
  142.            16777215
  143.     )
  144.     OLE_COLOR_LIST
  145.   )
  146. )


  147. (defun ACI_color->OLE_color (aci)
  148.   ; black is 0
  149.   ; white is 7
  150.   (if (and (>= aci 0) (<= 255))
  151.     (setq aci (nth aci OLE_COLOR_LIST)
  152.     )
  153.   )
  154. )

  155. (setq OLE_COLOR_LIST
  156.        '(0          255        65535      65280      16776960
  157.          16711680   16711935   16777215   8421504    12632256
  158.          255        8421631    166        5460902    128
  159.          4210816    76         2500172    38         1250086
  160.          16639      8429567    10662      5466278    8320
  161.          4214912    4940       2502732    2598       1251366
  162.          33023      8437759    21414      5471398    16512
  163.          4219008    9804       2505036    4902       1252646
  164.          49151      8445951    31910      5476774    24704
  165.          4223104    14668      2507596    7462       1253670
  166.          65535      8454143    42662      5482150    32896
  167.          4227200    19532      2509900    9766       1254950
  168.          65471      8454111    42620      5482129    32864
  169.          4227184    19513      2509891    9757       1254945
  170.          65408      8454079    42579      5482108    32832
  171.          4227168    19494      2509881    9747       1254941
  172.          65344      8454047    42537      5482088    32800
  173.          4227152    19475      2509872    9738       1254936
  174.          65280      8454016    42496      5482067    32768
  175.          4227136    19456      2509862    9728       1254931
  176.          4259584    10485632   2729472    6858323    2129920
  177.          5275712    1264640    3165222    665088     1582611
  178.          8453888    12582784   5481984    8169043    4227072
  179.          6324288    2509824    3755046    1254912    1910291
  180.          12582656   14679936   8168960    9545299    6324224
  181.          7372864    3755008    4410406    1910272    2172435
  182.          16776960   16777088   10921472   10921555   8421376
  183.          8421440    5000192    5000230    2500096    2500115
  184.          16760576   16768896   10910720   10916179   8413184
  185.          8417344    4995328    4997926    2497792    2498835
  186.          16744448   16760704   10900224   10910803   8404992
  187.          8413248    4990464    4995366    2495232    2497811
  188.          16728064   16752512   10889472   10905683   8396800
  189.          8409152    4985600    4993062    2492928    2496531
  190.          16711680   16744576   10878976   10900307   8388608
  191.          8405056    4980736    4990502    2490368    2495251
  192.          16711744   16744607   10879017   10900328   8388640
  193.          8405072    4980755    4990512    2490378    2495256
  194.          16711808   16744639   10879059   10900348   8388672
  195.          8405088    4980774    4990521    2490387    2495261
  196.          16711871   16744671   10879100   10900369   8388704
  197.          8405104    4980793    4990531    2490397    2495265
  198.          16711935   16744703   10879142   10900390   8388736
  199.          8405120    4980812    4990540    2490406    2495270
  200.          12517631   14647551   8126630    9524134    6291584
  201.          7356544    3735628    4400716    1900582    2167590
  202.          8388863    12550399   5439654    8147878    4194432
  203.          6307968    2490444    3745356    1245222    1905446
  204.          4194559    10453247   2687142    6837158    2097280
  205.          5259392    1245260    3155532    655398     1577766
  206.          5526612    5987163    10000536   12303291   14540253
  207.          16777215
  208.         )
  209. )

  210. ;;; Only for AutoCAD 2004
  211. (defun RGBtoACI (RGB-codes)
  212.    (vl-load-com)
  213.    (setq ColorObj (vla-GetInterfaceObject
  214.       (vlax-get-acad-object)
  215.       "AutoCAD.AcCmColor.16"
  216.     )
  217.    )
  218.    (vla-setRGB ColorObj (car RGB-codes) (cadr RGB-codes) (caddr RGB-codes))
  219.    ; alternatively done as below
  220.    ; (vlax-invoke-method  ColorObj 'setRGB (car RGB-codes) (cadr RGB-codes) (caddr RGB-codes))
  221.    (vla-get-ColorIndex ColorObj)
  222. )

  223. (defun RGBtoOLE_color2 (RGB-codes)
  224.    (+ (* (car RGB-codes) 65536)
  225.       (* (cadr RGB-codes) 256)
  226.       (caddr RGB-codes)
  227.    )
  228. )

  229. (defun OLEtoRGB_color2 (OLE_color / a b c)
  230.    (setq a (fix (/ OLE_color 65536.0)))
  231.    (setq b (fix (/ (- OLE_color (* a 65536)) 256.0)))
  232.    (setq c (- OLE_color (* a 65536) (* b 256)))
  233.    (list a b c)
  234. )

  235. ;; Convert TrueColor into a list of RGB
  236. (defun OLEtoRGB_color (OLE_color / r g b)
  237.   (setq r (lsh OLE_color -16))
  238.   (setq g (lsh (lsh OLE_color 16) -24))
  239.   (setq b (lsh (lsh OLE_color 24) -24))
  240.   (list r g b)
  241. )

  242. ;; Convert a list of RGB to TrueColor
  243. ;;; (RGBtoOLE_color '(118 118 118))
  244. (defun RGBtoOLE_color (RGB-codes)
  245.   (setq r (lsh (car RGB-codes) 16))
  246.   (setq g (lsh (cadr RGB-codes) 8))
  247.   (setq b (caddr RGB-codes))
  248.   (+ (+ r g) b)
  249. )

  250. ; For AutoCAD 2004
  251. ; (OLE_colorToACI 5987163) returns 251
  252. (defun OLE_colorToACI (OLE_color)
  253.   (RGBtoACI (OLEtoRGB_color OLE_color))
  254. )

  255. (defun C:getColor(/)
  256.   (setq ename (car (entsel "\nPick an object with true color:")))
  257.   (setq edata (entget ename))
  258.   ;; we have a true color.
  259.   (setq tcol (cdr (assoc 420 edata)))
  260.   (princ "\n true color = ")(princ tcol)
  261.   ;; convert it to a list of RGB.
  262.   (setq rgb (OLEtoRGB_color tcol))
  263.   (princ "\n rgb = ")(princ rgb)
  264.   (princ)
  265. )

  266. (defun C:setColor(/)
  267.   (setq ename (car (entsel "\nPick an object to set a true color:")))
  268.   (setq edata (entget ename))
  269.   ;; set a true color from a list of rgb values.(R=10 G=100 B=200)
  270.   (setq rgb (list 10 100 200))
  271.   (setq tcol (RGBtoOLE_color rgb))
  272.   ;; and set it.  
  273.   (setq edata (subst (cons 420 tcol) (assoc 420 edata) edata))
  274.   (entmod edata)
  275.   (princ "\n rgb = ")(princ rgb)
  276.   (princ "\n true color = ")(princ tcol)
  277.   (princ)
  278. )


  279. ;;; (ACItoRGB 123)
  280. (defun ACItoRGB (aci)
  281.   (if (and (>= aci 0) (<= 255))
  282.     (nth aci RGB_list)
  283.   )
  284. )

  285. (setq RGB_list '(
  286.                  (0 0 0)
  287.                  (255 0 0)
  288.                  (255 255 0)
  289.                  (0 255 0)
  290.                  (0 255 255)
  291.                  (0 0 255)
  292.                  (255 0 255)
  293.                  (255 255 255)
  294.                  (128 128 128)
  295.                  (192 192 192)
  296.                  (255 0 0)
  297.                  (255 127 127)
  298.                  (165 0 0)
  299.                  (165 82 82)
  300.                  (127 0 0)
  301.                  (127 63 63)
  302.                  (76 0 0)
  303.                  (76 38 38)
  304.                  (38 0 0)
  305.                  (38 19 19)
  306.                  (255 63 0)
  307.                  (255 159 127)
  308.                  (165 41 0)
  309.                  (165 103 82)
  310.                  (127 31 0)
  311.                  (127 79 63)
  312.                  (76 19 0)
  313.                  (76 47 38)
  314.                  (38 9 0)
  315.                  (38 23 19)
  316.                  (255 127 0)
  317.                  (255 191 127)
  318.                  (165 82 0)
  319.                  (165 124 82)
  320.                  (127 63 0)
  321.                  (127 95 63)
  322.                  (76 38 0)
  323.                  (76 57 38)
  324.                  (38 19 0)
  325.                  (38 28 19)
  326.                  (255 191 0)
  327.                  (255 223 127)
  328.                  (165 124 0)
  329.                  (165 145 82)
  330.                  (127 95 0)
  331.                  (127 111 63)
  332.                  (76 57 0)
  333.                  (76 66 38)
  334.                  (38 28 0)
  335.                  (38 33 19)
  336.                  (255 255 0)
  337.                  (255 255 127)
  338.                  (165 165 0)
  339.                  (165 165 82)
  340.                  (127 127 0)
  341.                  (127 127 63)
  342.                  (76 76 0)
  343.                  (76 76 38)
  344.                  (38 38 0)
  345.                  (38 38 19)
  346.                  (191 255 0)
  347.                  (223 255 127)
  348.                  (124 165 0)
  349.                  (145 165 82)
  350.                  (95 127 0)
  351.                  (111 127 63)
  352.                  (57 76 0)
  353.                  (66 76 38)
  354.                  (28 38 0)
  355.                  (33 38 19)
  356.                  (127 255 0)
  357.                  (191 255 127)
  358.                  (82 165 0)
  359.                  (124 165 82)
  360.                  (63 127 0)
  361.                  (95 127 63)
  362.                  (38 76 0)
  363.                  (57 76 38)
  364.                  (19 38 0)
  365.                  (28 38 19)
  366.                  (63 255 0)
  367.                  (159 255 127)
  368.                  (41 165 0)
  369.                  (103 165 82)
  370.                  (31 127 0)
  371.                  (79 127 63)
  372.                  (19 76 0)
  373.                  (47 76 38)
  374.                  (9 38 0)
  375.                  (23 38 19)
  376.                  (0 255 0)
  377.                  (127 255 127)
  378.                  (0 165 0)
  379.                  (82 165 82)
  380.                  (0 127 0)
  381.                  (63 127 63)
  382.                  (0 76 0)
  383.                  (38 76 38)
  384.                  (0 38 0)
  385.                  (19 38 19)
  386.                  (0 255 63)
  387.                  (127 255 159)
  388.                  (0 165 41)
  389.                  (82 165 103)
  390.                  (0 127 31)
  391.                  (63 127 79)
  392.                  (0 76 19)
  393.                  (38 76 47)
  394.                  (0 38 9)
  395.                  (19 38 23)
  396.                  (0 255 127)
  397.                  (127 255 191)
  398.                  (0 165 82)
  399.                  (82 165 124)
  400.                  (0 127 63)
  401.                  (63 127 95)
  402.                  (0 76 38)
  403.                  (38 76 57)
  404.                  (0 38 19)
  405.                  (19 38 28)
  406.                  (0 255 191)
  407.                  (127 255 223)
  408.                  (0 165 124)
  409.                  (82 165 145)
  410.                  (0 127 95)
  411.                  (63 127 111)
  412.                  (0 76 57)
  413.                  (38 76 66)
  414.                  (0 38 28)
  415.                  (19 38 33)
  416.                  (0 255 255)
  417.                  (127 255 255)
  418.                  (0 165 165)
  419.                  (82 165 165)
  420.                  (0 127 127)
  421.                  (63 127 127)
  422.                  (0 76 76)
  423.                  (38 76 76)
  424.                  (0 38 38)
  425.                  (19 38 38)
  426.                  (0 191 255)
  427.                  (127 223 255)
  428.                  (0 124 165)
  429.                  (82 145 165)
  430.                  (0 95 127)
  431.                  (63 111 127)
  432.                  (0 57 76)
  433.                  (38 66 76)
  434.                  (0 28 38)
  435.                  (19 33 38)
  436.                  (0 127 255)
  437.                  (127 191 255)
  438.                  (0 82 165)
  439.                  (82 124 165)
  440.                  (0 63 127)
  441.                  (63 95 127)
  442.                  (0 38 76)
  443.                  (38 57 76)
  444.                  (0 19 38)
  445.                  (19 28 38)
  446.                  (0 63 255)
  447.                  (127 159 255)
  448.                  (0 41 165)
  449.                  (82 103 165)
  450.                  (0 31 127)
  451.                  (63 79 127)
  452.                  (0 19 76)
  453.                  (38 47 76)
  454.                  (0 9 38)
  455.                  (19 23 38)
  456.                  (0 0 255)
  457.                  (127 127 255)
  458.                  (0 0 165)
  459.                  (82 82 165)
  460.                  (0 0 127)
  461.                  (63 63 127)
  462.                  (0 0 76)
  463.                  (38 38 76)
  464.                  (0 0 38)
  465.                  (19 19 38)
  466.                  (63 0 255)
  467.                  (159 127 255)
  468.                  (41 0 165)
  469.                  (103 82 165)
  470.                  (31 0 127)
  471.                  (79 63 127)
  472.                  (19 0 76)
  473.                  (47 38 76)
  474.                  (9 0 38)
  475.                  (23 19 38)
  476.                  (127 0 255)
  477.                  (191 127 255)
  478.                  (82 0 165)
  479.                  (124 82 165)
  480.                  (63 0 127)
  481.                  (95 63 127)
  482.                  (38 0 76)
  483.                  (57 38 76)
  484.                  (19 0 38)
  485.                  (28 19 38)
  486.                  (191 0 255)
  487.                  (223 127 255)
  488.                  (124 0 165)
  489.                  (145 82 165)
  490.                  (95 0 127)
  491.                  (111 63 127)
  492.                  (57 0 76)
  493.                  (66 38 76)
  494.                  (28 0 38)
  495.                  (33 19 38)
  496.                  (255 0 255)
  497.                  (255 127 255)
  498.                  (165 0 165)
  499.                  (165 82 165)
  500.                  (127 0 127)
  501.                  (127 63 127)
  502.                  (76 0 76)
  503.                  (76 38 76)
  504.                  (38 0 38)
  505.                  (38 19 38)
  506.                  (255 0 191)
  507.                  (255 127 223)
  508.                  (165 0 124)
  509.                  (165 82 145)
  510.                  (127 0 95)
  511.                  (127 63 111)
  512.                  (76 0 57)
  513.                  (76 38 66)
  514.                  (38 0 28)
  515.                  (38 19 33)
  516.                  (255 0 127)
  517.                  (255 127 191)
  518.                  (165 0 82)
  519.                  (165 82 124)
  520.                  (127 0 63)
  521.                  (127 63 95)
  522.                  (76 0 38)
  523.                  (76 38 57)
  524.                  (38 0 19)
  525.                  (38 19 28)
  526.                  (255 0 63)
  527.                  (255 127 159)
  528.                  (165 0 41)
  529.                  (165 82 103)
  530.                  (127 0 31)
  531.                  (127 63 79)
  532.                  (76 0 19)
  533.                  (76 38 47)
  534.                  (38 0 9)
  535.                  (38 19 23)
  536.                  (0 0 0)
  537.                  (51 51 51)
  538.                  (102 102 102)
  539.                  (153 153 153)
  540.                  (204 204 204)
  541.                  (255 255 255)
  542.                 )
  543. )

  544. ;;; Examples
  545. ;;;
  546. ;;; (RGBtoACI '(91 91 91)) returns 251
  547. ;;; (RGBtoACI '(118 118 118)) returns 8
  548. ;;; (RGBtoOLE_color '(118 118 118)) gives OLE_color=7763574
  549. ;;; (OLEtoRGB_color 7763574) gives (118 118 118)
  550. ;;; (RGBtoOLE_color '(91 91 91)) gives OLE_color=5987163
  551. ;;; (OLEtoRGB_color 5987163) gives (91 91 91)
  552. ;;; (RGBtoACI '(101 101 101)) returns 8
  553. ;;; (OLEtoRGB_color 6645093) returns (101 101 101)
  554. ;;; (ACItoRGB 123)

  555. ;;; Missing is conversion from ACI to RGB or ACI to OLE_color
  556.   [/FONT]


  1.   [FONT=courier new]
  2. VxOleToAciCol - Converts a OLE- to a ACI-Colornumber


  3. ;
  4. ; -- Function VxOleToAciCol
  5. ; Converts a OLE- to a ACI-Colornumber
  6. ; Copyright:
  7. ;   ?000 Jimmy Bergmark
  8. ; Arguments [Typ]:
  9. ;   OleCol = OLE-Colornumber [INT]
  10. ; Return [Typ]:
  11. ;   > ACI-Colornumber [INT]
  12. ; Notes:
  13. ; Thanx Jimmy B. for his excellent color converter.
  14. ;
  15. (defun VxOleToAciCol (OleCol)
  16. (vl-position
  17.   (boole
  18.    1
  19.    (vlax-variant-value (vlax-variant-change-type OleCol vlax-vbLong))
  20.    16777215
  21.   )
  22. '(0        255      65535    65280    16776960
  23.    16711680 16711935 16777215 8421504  12632256
  24.    255      8421631  166      5460902  128
  25.    4210816  76       2500172  38       1250086
  26.    16639    8429567  10662    5466278  8320
  27.    4214912  4940     2502732  2598     1251366
  28.    33023    8437759  21414    5471398  16512
  29.    4219008  9804     2505036  4902     1252646
  30.    49151    8445951  31910    5476774  24704
  31.    4223104  14668    2507596  7462     1253670
  32.    65535    8454143  42662    5482150  32896
  33.    4227200  19532    2509900  9766     1254950
  34.    65471    8454111  42620    5482129  32864
  35.    4227184  19513    2509891  9757     1254945
  36.    65408    8454079  42579    5482108  32832
  37.    4227168  19494    2509881  9747     1254941
  38.    65344    8454047  42537    5482088  32800
  39.    4227152  19475    2509872  9738     1254936
  40.    65280    8454016  42496    5482067  32768
  41.    4227136  19456    2509862  9728     1254931
  42.    4259584  10485632 2729472  6858323  2129920
  43.    5275712  1264640  3165222  665088   1582611
  44.    8453888  12582784 5481984  8169043  4227072
  45.    6324288  2509824  3755046  1254912  1910291
  46.    12582656 14679936 8168960  9545299  6324224
  47.    7372864  3755008  4410406  1910272  2172435
  48.    16776960 16777088 10921472 10921555 8421376
  49.    8421440  5000192  5000230  2500096  2500115
  50.    16760576 16768896 10910720 10916179 8413184
  51.    8417344  4995328  4997926  2497792  2498835
  52.    16744448 16760704 10900224 10910803 8404992
  53.    8413248  4990464  4995366  2495232  2497811
  54.    16728064 16752512 10889472 10905683 8396800
  55.    8409152  4985600  4993062  2492928  2496531
  56.    16711680 16744576 10878976 10900307 8388608
  57.    8405056  4980736  4990502  2490368  2495251
  58.    16711744 16744607 10879017 10900328 8388640
  59.    8405072  4980755  4990512  2490378  2495256
  60.    16711808 16744639 10879059 10900348 8388672
  61.    8405088  4980774  4990521  2490387  2495261
  62.    16711871 16744671 10879100 10900369 8388704
  63.    8405104  4980793  4990531  2490397  2495265
  64.    16711935 16744703 10879142 10900390 8388736
  65.    8405120  4980812  4990540  2490406  2495270
  66.    12517631 14647551 8126630  9524134  6291584
  67.    7356544  3735628  4400716  1900582  2167590
  68.    8388863  12550399 5439654  8147878  4194432
  69.    6307968  2490444  3745356  1245222  1905446
  70.    4194559  10453247 2687142  6837158  2097280
  71.    5259392  1245260  3155532  655398   1577766
  72.    5526612  7763574  10000536 12303291 14540253
  73.    16777215
  74.   )
  75. )
  76. )


  77. Back

  78. VxDeleteGroup - Deletes a group by name


  79. ;
  80. ; -- Function VxDeleteGroup
  81. ; Deletes a group by name
  82. ; Copyright:
  83. ;   ?000 MENZI ENGINEERING GmbH, Switzerland
  84. ; Arguments [Typ]:
  85. ;   Nme = Group name [STR]
  86. ; Return [Typ]:
  87. ;   > Null
  88. ; Notes:
  89. ;   Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event
  90. ;   to release the Gb:AcO and Gb:AcD objects at the end of a
  91. ;   AutoCAD session - otherwise AutoCAD maybe crashes...
  92. ;
  93. (defun VxDeleteGroup (Nme)
  94. (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
  95.        Gb:AcD (cond (Gb:AcD) ((vla-get-activedocument Gb:AcO)))
  96. )
  97. (vl-catch-all-apply
  98. '(lambda ()
  99.    (vla-delete
  100.     (vla-item
  101.      (vla-get-groups Gb:AcD)
  102.      Nme
  103.     )
  104.    )
  105.   )
  106. )
  107. (princ)
  108. )


  109. Back

  110. VxGetGroupNames - Returns a list of all Group name(s) of the object


  111. ;
  112. ; -- Function VxGetGroupNames
  113. ; Returns a list of all Group name(s) of the object.
  114. ; Copyright:
  115. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  116. ; Arguments [Typ]:
  117. ;   Obj = Object [VLA-OBJECT]
  118. ; Return [Typ]:
  119. ;   > Group name(s) [LIST]
  120. ; Notes:
  121. ;   Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event
  122. ;   to release the Gb:AcO and Gb:AcD objects at the end of a
  123. ;   AutoCAD session - otherwise AutoCAD maybe crashes...
  124. ;
  125. (defun VxGetGroupNames (Obj / Cur_ID NmeLst)
  126. (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
  127.        Gb:AcD (cond (Gb:AcD) ((vla-get-activedocument Gb:AcO)))
  128.        Cur_ID (vla-get-ObjectID Obj)
  129. )
  130. (vlax-for Grp (vla-get-Groups Gb:AcD)
  131.   (vlax-for Ent Grp
  132.    (if (equal (vla-get-ObjectID Ent) Cur_ID)
  133.     (setq NmeLst (cons (vla-get-Name Grp) NmeLst))
  134.    )
  135.    (vlax-release-object Ent)
  136.   )
  137.   (vlax-release-object Grp)
  138. )
  139. (reverse NmeLst)
  140. )


  141. Back

  142. VxGetMassProps - Returns a list of all mass properties of the object


  143. ;
  144. ; -- Function VxGetMassProps
  145. ; Returns a list of all mass properties of the object.
  146. ; Copyright:
  147. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  148. ; Arguments [Typ]:
  149. ;   Obj = Object [VLA-OBJECT]
  150. ; Return [Typ]:
  151. ;   > Mass properties '(Centroid RadiiOfGyration PrincipalDirections
  152. ;                       PrincipalMoments MomentOfInertia ProductOfInertia
  153. ;                       {Area Perimeter} {Volume}) [LIST]
  154. ; Notes:
  155. ; - VxGetMassProps is designed to handle closed *Polylines,
  156. ;   Regions and 3dsolids.
  157. ; - *Polylines and Regions returns 2D-lists in some parameters.
  158. ; - 2D-objects returns '(. . . . . . Area Perimeter)
  159. ; - 3D-objects returns '(. . . . . . Volume)
  160. ; - Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event
  161. ;   to release the Gb:AcO and Gb:AcD objects at the end of a
  162. ;   AutoCAD session - otherwise AutoCAD maybe crashes...
  163. ;
  164. (defun VxGetMassProps (Obj / DelFlg ResLst TmpObj)
  165. (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
  166.        Gb:AcD (cond (Gb:AcD) ((vla-get-ActiveDocument Gb:AcO)))
  167. )
  168. (if (member (vla-get-ObjectName Obj) '("AcDb2dPolyline" "AcDbPolyline"))
  169.   (setq DelFlg T
  170.         TmpObj (vlax-safearray-get-element
  171.                 (vlax-variant-value
  172.                  (vla-AddRegion
  173.                   (vla-get-ModelSpace Gb:AcD)
  174.                   (VxListToArray (list Obj) vlax-vbObject)
  175.                  )
  176.                 )
  177.                 0
  178.                )
  179.   )
  180.   (setq TmpObj Obj)
  181. )
  182. (setq ResLst (append
  183.                (list
  184.                 (vlax-get TmpObj "Centroid")
  185.                 (vlax-get TmpObj "RadiiOfGyration")
  186.                 (vlax-get TmpObj "PrincipalDirections")
  187.                 (vlax-get TmpObj "PrincipalMoments")
  188.                 (vlax-get TmpObj "MomentOfInertia")
  189.                )
  190.                (if (= (vla-get-ObjectName TmpObj) "AcDbRegion")
  191.                 (list
  192.                  (vla-get-ProductOfInertia TmpObj)
  193.                  (vla-get-Area TmpObj)
  194.                  (vla-get-Perimeter TmpObj)
  195.                 )
  196.                 (list
  197.                  (vlax-get TmpObj "ProductOfInertia")
  198.                  (vla-get-Volume TmpObj)
  199.                  nil
  200.                 )
  201.                )
  202.               )
  203. )
  204. (if DelFlg (vla-delete TmpObj))
  205. ResLst
  206. )


  207. Back

  208. VxGetInters - Returns all intersection points between two objects


  209. ;
  210. ; -- Function VxGetInters
  211. ; Returns all intersection points between two objects.
  212. ; Copyright:
  213. ;   ?000 MENZI ENGINEERING GmbH, Switzerland
  214. ; Arguments [Typ]:
  215. ;   Fst = First object [VLA-OBJECT]
  216. ;   Nxt = Second object [VLA-OBJECT]
  217. ;   Mde = Intersection mode [INT]
  218. ;         Constants:
  219. ;         - acExtendNone           Does not extend either object.
  220. ;         - acExtendThisEntity     Extends the Fst object.
  221. ;         - acExtendOtherEntity    Extends the Nxt object.
  222. ;         - acExtendBoth           Extends both objects.
  223. ; Return [Typ]:
  224. ;   > list of points '((1.0 1.0 0.0)... [LIST]
  225. ;   > Nil if no intersection found
  226. ; Notes:
  227. ;   None
  228. ;
  229. (defun VxGetInters (Fst Nxt Mde / IntLst PntLst)
  230. (setq IntLst (vlax-invoke Fst "IntersectWith" Nxt Mde))
  231. (cond
  232.   (IntLst
  233.    (repeat (/ (length IntLst) 3)
  234.     (setq PntLst (cons
  235.                   (list
  236.                    (car IntLst)
  237.                    (cadr IntLst)
  238.                    (caddr IntLst)
  239.                   )
  240.                   PntLst
  241.                  )
  242.           IntLst (cdddr IntLst)
  243.     )
  244.    )
  245.    (reverse PntLst)
  246.   )
  247.   (T nil)
  248. )
  249. )

  250. Back

  251. VxGetBlockInters - Returns all intersection points between a block and an obj...


  252. ;
  253. ; -- Function VxGetBlockInters
  254. ; Returns all intersection points between a Block and an object.
  255. ; Copyright:
  256. ;   ?001-2002 MENZI ENGINEERING GmbH, Switzerland
  257. ; Arguments [Typ]:
  258. ;   Blk = Block object [VLA-OBJECT]
  259. ;   Obj = Object [VLA-OBJECT]
  260. ;   Mde = Intersection mode [INT]
  261. ;         Constants:
  262. ;         - acExtendNone           Does not extend either object.
  263. ;         - acExtendThisEntity     Extends the Fst object.
  264. ;         - acExtendOtherEntity    Extends the Nxt object.
  265. ;         - acExtendBoth           Extends both objects.
  266. ; Return [Typ]:
  267. ;   > list of points '((1.0 1.0 0.0)... [LIST]
  268. ;   > Nil if no intersection found
  269. ; Notes:
  270. ;   None
  271. ;
  272. (defun VxGetBlockInters (Blk Obj Mde / ObjNme PntLst TmpVal)
  273. (foreach memb (vlax-invoke Blk "Explode")
  274.   (setq ObjNme (vla-get-ObjectName memb))
  275.   (cond
  276.    ((or
  277.      (not (vlax-method-applicable-p memb 'IntersectWith))
  278.      (and
  279.       (eq ObjNme "AcDbHatch")
  280.       (eq (strcase (vla-get-PatternName memb)) "SOLID")
  281.      )
  282.      (eq ObjNme "AcDb3dSolid")
  283.     )
  284.    )
  285.    ((eq ObjNme "AcDbBlockReference")
  286.     (if (setq TmpVal (VxGetBlockInters memb Obj Mde))
  287.      (setq PntLst (append PntLst TmpVal))
  288.     )
  289.    )
  290.    (T
  291.     (if (setq TmpVal (VxGetInters memb Obj Mde))
  292.      (setq PntLst (append PntLst TmpVal))
  293.     )
  294.    )
  295.   )
  296.   (vla-Delete memb)
  297. )
  298. PntLst
  299. )


  300. Back

  301. VxGetObjLength - Returns the length of all kind of objects


  302. ;
  303. ; -- Function VxGetObjLength
  304. ; Returns the length of all kind of objects.
  305. ; Copyright:
  306. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  307. ; Arguments [Typ]:
  308. ;   Obj = Object [VLA-OBJECT]
  309. ; Return [Typ]:
  310. ;   > Length of the object [REAL]
  311. ; Notes:
  312. ; - Proceedes *Polylines, Splines, Lines, Arcs, Circles and Ellipses
  313. ;
  314. (defun VxGetObjLength (Obj)
  315. (vlax-curve-getDistAtParam Obj (vlax-curve-getEndParam Obj))
  316. )


  317. Back

  318. VxSsetSelect - ActiveX counterpart to 'ssget'


  319. ;
  320. ; -- Function VxSsetSelect
  321. ; ActiveX counterpart to 'ssget'.
  322. ; Copyright:
  323. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  324. ; Arguments [Typ]:
  325. ;   Nme = Selection set name [STR]
  326. ;   Mde = Select mode [INT] 1)
  327. ;         Constants:
  328. ;         - acSelectionSetWindow
  329. ;         - acSelectionSetCrossing
  330. ;         - acSelectionSetPrevious
  331. ;         - acSelectionSetLast
  332. ;         - acSelectionSetAll
  333. ;   Pt1 = First window corner [LIST] 2)
  334. ;   Pt2 = Next window corner [LIST]  2)
  335. ;   Flt = Dotted pair list '((0 . "Name")...(8 . "Layer")) [LIST] 3)
  336. ; Return [Typ]:
  337. ;   > New selection set [VLA-OBJECT]
  338. ; Notes:
  339. ;   1) If nil, SelectOnScreen is used
  340. ;   2) For select modes acSelectionSetWindow and acSelectionSetCrossing
  341. ;      only, else nil
  342. ;   3) Set to nil if not used
  343. ;
  344. (defun VxSsetSelect (Nme Mde Pt1 Pt2 Flt / CurSet FltLst FstPnt NxtPnt)
  345. (setq CurSet (VxSsetMake Nme)
  346.        FstPnt (cond (Pt1 (vlax-3d-point Pt1)) (T nil))
  347.        NxtPnt (cond (Pt2 (vlax-3d-point Pt2)) (T nil))
  348.        FltLst (cond (Flt (VxSsetFilter Flt)) (T nil))
  349. )
  350. (if Mde
  351.   (if FltLst
  352.    (vla-select CurSet Mde FstPnt NxtPnt (car FltLst) (cadr FltLst))
  353.    (vla-select CurSet Mde FstPnt NxtPnt)
  354.   )
  355.   (if FltLst
  356.    (vla-SelectOnScreen CurSet (car FltLst) (cadr FltLst))
  357.    (vla-SelectOnScreen CurSet)
  358.   )
  359. )
  360. CurSet
  361. )

  362. Back

  363. VxSsetMake - Creates a new selection set or clears an existing one


  364. ;
  365. ; -- Function VxSsetMake
  366. ; Creates a new selection set or clears an existing one.
  367. ; Copyright:
  368. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  369. ; Arguments [Typ]:
  370. ;   Nme = Selection set name [STR]
  371. ; Return [Typ]:
  372. ;   > New selection set [VLA-OBJECT]
  373. ; Notes:
  374. ;   Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event
  375. ;   to release the Gb:AcO and Gb:AcD objects at the end of a
  376. ;   AutoCAD session - otherwise AutoCAD maybe crashes...
  377. ;
  378. (defun VxSsetMake (Nme / SetCol)
  379. (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
  380.        Gb:AcD (cond (Gb:AcD) ((vla-get-activedocument Gb:AcO)))
  381.        SetCol (vla-get-SelectionSets Gb:AcD)
  382. )
  383. (if (vl-catch-all-error-p
  384.       (vl-catch-all-apply 'vla-add (list SetCol Nme))
  385.      )
  386.   (vla-clear (vla-Item SetCol Nme))
  387. )
  388. (vla-Item SetCol Nme)
  389. )


  390. Back

  391. VxSsetFilter - Creates a filter for the SelectXxx methodes


  392. ;
  393. ; -- Function VxSsetFilter
  394. ; Creates a filter for the SelectXxx methodes.
  395. ; Copyright:
  396. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  397. ; Arguments [Typ]:
  398. ;   Flt = Dotted pair list '((0 . "Name")...(8 . "Layer")) [LIST]
  399. ; Return [Typ]:
  400. ;   > List of two arrays '(TypArr DatArr) [LIST]
  401. ; Notes:
  402. ;   None
  403. ;
  404. (defun VxSsetFilter (Flt)
  405. (mapcar
  406. '(lambda (Typ Dat) (VxListToArray Typ Dat))
  407.   (list vlax-vbInteger vlax-vbVariant)
  408.   (list (mapcar 'car Flt) (mapcar 'cdr Flt))
  409. )
  410. )


  411. Back

  412. VxListToArray - Converts a list into an array


  413. ;
  414. ; -- Function VxListToArray
  415. ; Converts a list into an array.
  416. ; Copyright:
  417. ;   ?000 MENZI ENGINEERING GmbH, Switzerland
  418. ; Arguments [Typ]:
  419. ;   Lst = Standard list [LIST]
  420. ;   Typ = Datatype [INT]
  421. ;         Constants:
  422. ;         - vlax-vbBoolean
  423. ;         - vlax-vbDecimal *)
  424. ;         - vlax-vbDouble
  425. ;         - vlax-vbInteger
  426. ;         - vlax-vbLong
  427. ;         - vlax-vbObject
  428. ;         - vlax-vbSingle
  429. ;         - vlax-vbString
  430. ;         - vlax-vbVariant
  431. ; Return [Typ]:
  432. ;   > Array [VARIANT]
  433. ; Notes:
  434. ;   *)Missing datatype in Visual LISP, initialize it in your Autoloader.
  435. ;   - Can't be used for dotted pair or nested lists.
  436. ;
  437. (defun VxListToArray (Typ Lst)
  438. (vlax-make-variant
  439.   (vlax-safearray-fill
  440.    (vlax-make-safearray Typ (cons 0 (1- (length Lst))))
  441.    Lst
  442.   )
  443. )
  444. )

  445. Back

  446. VxArrayToList - Converts an array into a list


  447. ;
  448. ; -- Function VxArrayToList
  449. ; Converts an array into a list.
  450. ; Copyright:
  451. ;   ?000 MENZI ENGINEERING GmbH, Switzerland
  452. ; Arguments [Typ]:
  453. ;   Arr = Array [VARIANT]
  454. ; Return [Typ]:
  455. ;   > Standard List [LIST]
  456. ;   > nil if array is empty
  457. ; Notes:
  458. ;   - Can't be used for multidimensional arrays.
  459. ;
  460. (defun VxArrayToList (Arr / TmpVal)
  461. (setq TmpVal (vlax-variant-value Arr))
  462. (if (safearray-value TmpVal)
  463.   (vlax-safearray->list TmpVal)
  464.   '()
  465. )
  466. )

  467. Back

  468. VxStringSubst - Substitutes one string for another, within a string


  469. ;
  470. ; -- Function VxStringSubst
  471. ; Substitutes one string for another, within a string.
  472. ; Copyright:
  473. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  474. ; Arguments [Typ]:
  475. ;   Fnd = Pattern [STR]
  476. ;   Rep = Replace [STR]
  477. ;   Stg = String to search [STR]
  478. ; Return [Typ]:
  479. ;   > Modified string [STR]
  480. ; Notes:
  481. ;   None
  482. ;
  483. (defun VxStringSubst (Fnd Rep Stg / TmpStr)
  484. (setq TmpStr Stg)
  485. (while (vl-string-search Fnd TmpStr)
  486.   (setq TmpStr (vl-string-subst Rep Fnd TmpStr))
  487. )
  488. TmpStr
  489. )

  490. Back

  491. VxGetDriveInfos - Returns informations from the selected drive


  492. ;
  493. ; -- Function VxGetDriveInfos
  494. ; Returns informations from the selected drive.
  495. ; Copyright:
  496. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  497. ; Arguments [Typ]:
  498. ;   Drv = Drive character, eg. "C" or "C:" [STR]
  499. ; Return [Typ]:
  500. ;   > Drive infos '(TotalSize FreeSpace DriveType FileSystem SerialNumber
  501. ;                   ShareName VolumeName) [LIST]
  502. ;     Explanations:
  503. ;     - TotalSize (kB) [REAL]
  504. ;       Returns the total space of a drive or network share.
  505. ;     - FreeSpace (kB) [REAL]
  506. ;       Returns the amount of space available to a user on the specified drive
  507. ;       or network share.
  508. ;     - DriveType [INT]
  509. ;       0 = "Unknown"
  510. ;       1 = "Removable"
  511. ;       2 = "Fixed"
  512. ;       3 = "Network"
  513. ;       4 = "CD-ROM"
  514. ;       5 = "RAM Disk"
  515. ;     - FileSystem [STR]
  516. ;       Returns the type of file system in use for the specified drive, eg.
  517. ;       "FAT", "NTFS", "CDFS".
  518. ;     - SerialNumber [INT]
  519. ;       Returns the serial number used to uniquely identify a disk volume.
  520. ;     - ShareName [STR]
  521. ;       Returns the network share name (UNC) for the specified drive. If it's
  522. ;       not a network drive, ShareName returns a zero-length string ("").
  523. ;     - VolumeName [STR]
  524. ;       Returns the volume name of the specified drive.
  525. ;   >  0 The drive doesn't exist.
  526. ;   > -1 The drive is not ready. For removable-media drives and CD-ROM drives,
  527. ;        VxGetDriveInfos returns -1 when the appropriate media is not inserted
  528. ;        or not ready for access.
  529. ; Notes:
  530. ;   - Requires ScrRun.dll.
  531. ;
  532. (defun VxGetDriveInfos (Drv / DrvObj FilSys RetVal)
  533. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  534.        RetVal (cond
  535.                ((= (vlax-invoke FilSys "DriveExists" Drv) 0) 0)
  536.                ((setq DrvObj (vlax-invoke FilSys "GetDrive" Drv))
  537.                 (cond
  538.                  ((= (vlax-get DrvObj "IsReady") 0) -1)
  539.                  ((list
  540.                    (/ (vlax-get DrvObj "TotalSize") 1000.0)
  541.                    (/ (vlax-get DrvObj "FreeSpace") 1000.0)
  542.                    (vlax-get DrvObj "DriveType")
  543.                    (vlax-get DrvObj "FileSystem")
  544.                    (vlax-get DrvObj "SerialNumber")
  545.                    (vlax-get DrvObj "ShareName")
  546.                    (vlax-get DrvObj "VolumeName")
  547.                   )
  548.                  )
  549.                 )
  550.                )
  551.               )
  552. )
  553. (if DrvObj (vlax-release-object DrvObj))
  554. (vlax-release-object FilSys)
  555. RetVal
  556. )

  557. Back

  558. VxGetFileInfos - Returns informations from the selected file


  559. ;
  560. ; -- VxGetFileInfos
  561. ; Returns informations from the selected file.
  562. ; Copyright:
  563. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  564. ; Arguments [Typ]:
  565. ;   Fil = Filename "C:\\Temp\\MyTemp\\Scrap.dwg" [STR]
  566. ; Return [Typ]:
  567. ;   > File infos '(DateCreated DateLastModified DateLastAccessed
  568. ;                  Type Size Attributes) [LIST]
  569. ;     Explanations:
  570. ;     - DateCreated [REAL]
  571. ;       Returns serial date/time.
  572. ;     - DateLastModified [REAL]
  573. ;       Returns serial date/time.
  574. ;     - DateLastAccessed [REAL]
  575. ;       Returns serial date/time.
  576. ;     - Type [STR]
  577. ;       Returns the registered file tape, eg. "AutoCAD Drawing".
  578. ;     - Size (kB) [REAL]
  579. ;       Returns the size of the file in kB.
  580. ;     - Attributes [INT]
  581. ;         0 = Normal file, no attributes are set.
  582. ;         1 = Read-only file.
  583. ;         2 = Hidden file.
  584. ;         4 = System file.
  585. ;         8 = Disk drive volume label. (not available in VxGetFileInfos)
  586. ;        16 = Folder or directory. (not available in VxGetFileInfos)
  587. ;        32 = File has changed since last backup.
  588. ;        64 = Link or shortcut.
  589. ;       128 = Compressed file.
  590. ;   > nil If file doesn't exist
  591. ; Notes:
  592. ;   - Requires ScrRun.dll.
  593. ;
  594. (defun VxGetFileInfos (Fil / FilObj FilSys RetVal)
  595. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  596.        RetVal (cond
  597.                ((= (vlax-invoke FilSys "FileExists" Fil) 0) nil)
  598.                ((setq FilObj (vlax-invoke FilSys "GetFile" Fil))
  599.                 (list
  600.                  (vlax-get FilObj "DateCreated")
  601.                  (vlax-get FilObj "DateLastModified")
  602.                  (vlax-get FilObj "DateLastAccessed")
  603.                  (vlax-get FilObj "Type")
  604.                  (/ (vlax-get FilObj "Size") 1000.0)
  605.                  (vlax-get FilObj "Attributes")
  606.                 )
  607.                )
  608.                (T nil)
  609.               )
  610. )
  611. (if FilObj (vlax-release-object FilObj))
  612. (vlax-release-object FilSys)
  613. RetVal
  614. )


  615. Back

  616. VxCopyFiles - Copies the specified file(s)


  617. ;
  618. ; -- VxCopyFiles
  619. ; Copies the specified file(s).
  620. ; Copyright:
  621. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  622. ; Arguments [Typ]:
  623. ;   Src = Source file(s) to copy "C:\\Temp\\AllScrap.*" [STR]
  624. ;   Tar = Target directory/file "C:\\Scrap" [STR]
  625. ; Return [Typ]:
  626. ;   > T   VxCopyFiles succeed
  627. ;     nil Error on copy file(s)
  628. ; Notes:
  629. ;   - Requires ScrRun.dll.
  630. ;
  631. (defun VxCopyFiles (Src Tar / ErrObj FilSys RetVal)
  632. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  633.        ErrObj (vl-catch-all-apply
  634.               'vlax-invoke-method
  635.                (list FilSys 'CopyFile Src Tar :vlax-true)
  636.               )
  637.        RetVal (not (vl-catch-all-error-p ErrObj))
  638. )
  639. (vlax-release-object FilSys)
  640. RetVal
  641. )


  642. Back

  643. VxDeleteFiles - Deletes the specified file(s)


  644. ;
  645. ; -- VxDeleteFiles
  646. ; Deletes the specified file(s).
  647. ; Copyright:
  648. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  649. ; Arguments [Typ]:
  650. ;   Fil = File name(s) to delete "C:\\Temp\\AllScrap.*" [STR]
  651. ; Return [Typ]:
  652. ;   > T   VxDeleteFiles succeed
  653. ;     nil Error on delete file(s)
  654. ; Notes:
  655. ;   - Requires ScrRun.dll.
  656. ;
  657. (defun VxDeleteFiles (Fil / ErrObj FilSys RetVal)
  658. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  659.        ErrObj (vl-catch-all-apply
  660.               'vlax-invoke-method
  661.                (list FilSys 'DeleteFile Fil :vlax-true)
  662.               )
  663.        RetVal (not (vl-catch-all-error-p ErrObj))
  664. )
  665. (vlax-release-object FilSys)
  666. RetVal
  667. )

  668. Back

  669. VxCreateDirectory - Creates the specified directory(ies)


  670. ;
  671. ; -- VxMakeDirectory
  672. ; Creates the specified directory(ies).
  673. ; Copyright:
  674. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  675. ; Arguments [Typ]:
  676. ;   Dir = Folder to create, eg. "C:\\Temp\\MyTemp\\AllScrap" [STR]
  677. ; Return [Typ]:
  678. ;   > T   VxMakeDirectory succeed
  679. ;     nil Error on creating directory(ies)
  680. ; Notes:
  681. ;   - Requires ScrRun.dll.
  682. ;
  683. (defun VxMakeDirectory (Dir / CurDir DrvObj FilSys RetVal TmpLst TmpVal)
  684. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  685.        CurDir (vl-string-right-trim "\" (vl-string-right-trim "/" Dir))
  686. )
  687. (while (/= (setq TmpVal (vl-filename-directory CurDir)) CurDir)
  688.   (setq TmpLst (cons TmpVal TmpLst)
  689.         CurDir TmpVal
  690.   )
  691. )
  692. (setq RetVal (cond
  693.                ((= (vlax-invoke FilSys "DriveExists" TmpVal) 0) nil)
  694.                ((setq DrvObj (vlax-invoke FilSys "GetDrive" TmpVal))
  695.                 (cond
  696.                  ((= (vlax-get DrvObj "IsReady") 0) nil)
  697.                  (T
  698.                   (foreach memb TmpLst
  699.                    (cond
  700.                     ((= (vlax-invoke FilSys "FolderExists" memb) -1))
  701.                     ((vlax-invoke FilSys "CreateFolder" memb))
  702.                    )
  703.                   )
  704.                   (cond
  705.                    ((= (vlax-invoke FilSys "FolderExists" Dir) -1))
  706.                    ((vlax-invoke FilSys "CreateFolder" Dir) T)
  707.                    (T nil)
  708.                   )
  709.                  )
  710.                 )
  711.                )
  712.               )
  713. )
  714. (if DrvObj (vlax-release-object DrvObj))
  715. (vlax-release-object FilSys)
  716. RetVal
  717. )


  718. Back

  719. VxDelDirectory - Deletes the specified directory


  720. ;
  721. ; -- VxDelDirectory
  722. ; Deletes the specified directory.
  723. ; Copyright:
  724. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  725. ; Arguments [Typ]:
  726. ;   Dir = Folder to delete "C:\\Temp\\MyTemp\\AllScrap" [STR]
  727. ; Return [Typ]:
  728. ;   > T   VxDelDirectory succeed
  729. ;     nil Error on deleting directory
  730. ; Notes:
  731. ;   - Requires ScrRun.dll.
  732. ;
  733. (defun VxDelDirectory (Dir / FilSys RetVal)
  734. (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  735.        RetVal (cond
  736.                ((= (vlax-invoke FilSys "FolderExists" Dir) 0) nil)
  737.                (T (vlax-invoke FilSys "DeleteFolder" Dir :vlax-true) T)
  738.               )
  739. )
  740. (vlax-release-object FilSys)
  741. RetVal
  742. )


  743. Back

  744. VxReadTextFile - Reads a textfile and returns a line list (fast)


  745. ;
  746. ; -- VxReadTextFile
  747. ; Reads a textfile and returns a line list (fast).
  748. ; Copyright:
  749. ;   ?001 MENZI ENGINEERING GmbH, Switzerland
  750. ; Arguments [Typ]:
  751. ;   Fil = (Path)Filename [STR]
  752. ; Return [Typ]:
  753. ;   > List of lines [LIST]
  754. ;   > nil if file not found
  755. ; Notes:
  756. ;   - Requires ScrRun.dll.
  757. ;
  758. (defun VxReadTextFile (Fil / FilObj FilPth FilSys OpnFil RetVal)
  759. (if (setq FilPth (findfile Fil))
  760.   (progn
  761.    (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
  762.          FilObj (vlax-invoke FilSys "GetFile FilPth")
  763.          OpnFil (vlax-invoke FilObj "OpenAsTextStream" 1 0)
  764.    )
  765.    (while (= (vlax-get OpnFil "AtEndOfStream") 0)
  766.     (setq RetVal (cons (vlax-invoke OpnFil "ReadLine") RetVal))
  767.    )
  768.    (vlax-invoke OpnFil "Close")
  769.    (vlax-release-object OpnFil)
  770.    (vlax-release-object FilObj)
  771.    (vlax-release-object FilSys)
  772.    (reverse RetVal)
  773.   )
  774.   nil
  775. )
  776. )


  777. Back

  778. VxCreateShortCut - Creates a shortcut to AutoCAD with the appropriate...


  779. ;
  780. ; -- Function VxCreateShortCut
  781. ; Creates a shortcut to AutoCAD with the appropriate parameters on the desktop.
  782. ; Copyright:
  783. ;   ?002 MENZI ENGINEERING GmbH, Switzerland
  784. ; Arguments [Typ]:
  785. ;   Scn = Shortcut name, "MyShortCut" [STR]
  786. ;   Pro = Profile name, "MyProfile" [STR]
  787. ;   Icn = (Path)Filename of the icon, "c:\\MyPath\\MyIcon.ico" [STR] 1)
  788. ; Return [Typ]:
  789. ;   > Shortcutpath if suceed [STR]
  790. ;   > False on error
  791. ; Notes:
  792. ;   1) If nil, AutoCAD's first internal icon is used
  793. ;   - Requires ScrRun.dll.
  794. ;
  795. (defun VxCreateShortCut (Scn Pro Icn / DskPth IcnPar ExeFil RetVal ShoCut
  796.                                        SpcFld WscObj)
  797. (setq ExeFil (findfile "acad.exe")
  798.        IcnPar (cond (Icn) ((strcat ExeFil ", 0")))
  799.        WscObj (vlax-create-object "WScript.Shell")
  800.        RetVal (cond
  801.                ((setq SpcFld (vlax-get WscObj 'SpecialFolders))
  802.                 (setq DskPth (strcat
  803.                               (vla-Item SpcFld "Desktop")
  804.                               "\" Scn ".lnk"
  805.                              )
  806.                       ShoCut (vlax-invoke WscObj "CreateShortcut" DskPth)
  807.                 )
  808.                 (vlax-put-property ShoCut 'TargetPath ExeFil)
  809.                 (vlax-put-property ShoCut 'Arguments (strcat "/p " Pro))
  810.                 (vlax-put-property ShoCut 'IconLocation IcnPar)
  811.                 (vla-save ShoCut)
  812.                 (findfile DskPth)
  813.                )
  814.                (T Nil)
  815.               )
  816. )
  817. (vlax-release-object WscObj)
  818. RetVal
  819. )


  820. Back

  821. ACAD2000.lsp - Drawing Reactor sample


  822. ;
  823. ; -- ACAD2000.lsp
  824. ; Sets a DocManager Reactor to release the Gb:AcO and Gb:AcD objects at the
  825. ; end of a AutoCAD session.
  826. ; Copyright:
  827. ;   ?000 MENZI ENGINEERING GmbH, Switzerland
  828. ; Notes:
  829. ;   None
  830. ;
  831. (setq vlax-vbDecimal 14) ;Set missing Datatype

  832. (if s::startup
  833. (defun-q-list-set
  834. 's::startup
  835.   (append
  836.    (defun-q-list-ref 's::startup)
  837.    (cdr (defun-q-list-ref 'InitReactor))
  838.   )
  839. )
  840. (defun-q s::startup () (InitReactor) (princ))
  841. )

  842. (defun-q InitReactor ()
  843. (prompt "\n>Initialize Document Reactor...")
  844. (vl-load-com)
  845. (if (not Gb:DmR)
  846.   (setq Gb:DmR (vlr-DocManager-Reactor
  847.                 nil
  848.                '((:vlr-documentToBeDestroyed . CloseHandling))
  849.                )
  850.   )
  851. )
  852. (princ)
  853. )

  854. (defun CloseHandling (Rea Arg)
  855. (if Gb:AcO (vlax-release-object Gb:AcO))
  856. (if Gb:AcD (vlax-release-object Gb:AcD))
  857. (vlr-remove-all :vlr-DocManager-Reactor)
  858. (setq Gb:AcO nil
  859.        Gb:AcD nil
  860.        Gb:DmR nil
  861. )
  862. (princ)
  863. )

  864. (princ)
  865. ;
  866. ; -- End ACAD2000.lsp
  867.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-23 02:26 , Processed in 0.273496 second(s), 41 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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