找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1132|回复: 2

[他山之石] Visual LISP 使用 Image 命令

[复制链接]
发表于 2013-5-25 09:21:28 | 显示全部楼层 |阅读模式

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

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

×
Image command from visual LISP?By Augusto Goncalves
To use the RELOAD, UNLOAD and DETACH options of the IMAGE command, it is not possible to use the AutoCAD ActiveX interface. Instead, you have to 'rebuild' these options using AutoLISP and Visual LISP functions.
-IMAGE RELOAD:   
This command options works on the raster image definition object that is stored in the dictionary "ACAD_IMAGE_DICT". This object uses the DXFgroup code 280 as a 'loaded' flag. If the value of group code 280 is 1, the image file is currently loaded; if the value is 0, the image file is unloaded.
In order to get the correct entry in the image dictionary (to get the right image definition object) and set this flag to 1, use the IMAGERELOAD function (see below).
-IMAGE UNLOAD:   
This command options uses the flag previously mentioned. Set the value of group code 280 to 0 to unload the image file. The function IMGUNLOAD does this.
-IMAGE DETACH:   
This command options removes the specified image definition object and removes every raster image entity from the current drawing that uses the (deleted) image definition object. The IMGDETACH function does this.
You can use the following functions. They 'rebuild' the functionality of the IMAGE command options.  The functions (imgreload), (imgunload) and (imgdetach) need the image name as a parameter. For the image name, use the AutoCAD wildcard mechanism.
  1. ;;; Use the function 'imgunload' instead of
  2. ;;; calling the command
  3. ;;; -IMAGE _Unload
  4. ;;;
  5. (defun imgunload (imgname)
  6.   (imgloadstat (strcase imgname) 0)
  7.   (princ)
  8. )

  9. ;;; Use the function 'imgreload' instead of
  10. ;;; calling the command
  11. ;;; -IMAGE _Reload
  12. ;;;
  13. (defun imgreload (imgname)
  14.   (imgloadstat (strcase imgname) 1)
  15.   (princ)
  16. )

  17. ;;; Use the function 'imgdetach' instead of
  18. ;;; calling the command
  19. ;;; -IMAGE _Detach
  20. ;;;
  21. (defun imgdetach (imgname / imgDict imgDictId dictLength counter
  22.         dictName imgDefIds selSet imgDefId)

  23.   ;; Iterate all dictionary entries and remove
  24.   ;; the entries which matches 'imgname'.

  25.   (setq imgname (strcase imgname)
  26.     imgDict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")
  27.   )
  28.   (if (equal imgDict nil)
  29.    (princ "\nNo images loaded.")
  30.    (progn
  31.     ;; Image dictionary is available.
  32.     (setq imgDictId  (cdr (car imgDict))
  33.        dictLength (length imgdict)
  34.        counter  0
  35.     )
  36.     (while (< counter dictLength)
  37.       (if (equal (car (nth counter imgDict)) 3)
  38.        ;; Entry name found. Get it.
  39.        (progn
  40.         (setq dictName (strcase (cdr (nth counter imgDict))))
  41.         ;; Compare the entry name.
  42.         (if (wcmatch dictName imgname)
  43.           (progn
  44.            ;; Remove the dictionary entry...
  45.            (dictremove imgDictId dictName)
  46.            ;; ...and store the entity name of
  47.            ;; the raster image definition object.
  48.            (setq imgDefIds
  49.             (append imgDefIds
  50.                 (list (cdr (nth (1+ counter) imgDict)))
  51.             )
  52.            )
  53.           )
  54.         )
  55.        )
  56.       )
  57.       (setq counter (1+ counter))
  58.     )
  59.     ;; Finished iterating the dictionary.
  60.     ;; Do we have to remove some raster image entities?
  61.     (if (/= (length imgDefIds) 0)
  62.       ;; Yes, we have to remove some raster image entities
  63.       ;; (because the related image definition objects
  64.       ;; have been removed).
  65.       (progn
  66.        ;; Select all image entities.
  67.        (setq selSet  (ssget "X" '((0 . "IMAGE")))
  68.           counter 0
  69.        )
  70.        (if (/= selSet nil)
  71.         (progn
  72.           ;; Iterate all image entities
  73.           (while (< counter (sslength selSet))
  74.            ;; Get the entity name of the referenced
  75.            ;; image definition object.
  76.            (setq imgDefId
  77.             (cdr (assoc 340 (entget (ssname selSet counter))))
  78.            )
  79.            ;; Is the referenced definition object gone?
  80.            (if (member imgDefId imgDefIds)
  81.             ;; The definition for this image entity
  82.             ;; have been removed, so let us remove
  83.             ;; the image entity, as well.
  84.             (entdel (cdr (car (entget (ssname selSet counter)))))
  85.            )
  86.            (setq counter (1+ counter))
  87.           )
  88.           ;; Empty the selection set
  89.           (setq selSet nil)
  90.         )
  91.        )
  92.       )
  93.     )
  94.    )
  95.   )
  96.   (princ)
  97. )

  98. ;;; Internal function.
  99. ;;; This function is called by 'imgunload'
  100. ;;; and 'imgreload'.
  101. ;;;
  102. (defun imgloadstat (imgname status / imgDict imgDictId
  103.           dictLength counter dictName dictEntry next)

  104.   ;; Get the image dictionary
  105.   (setq imgDict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
  106.   (if (equal imgDict nil)
  107.    (princ "\nNo images loaded.")
  108.    (progn
  109.     ;; Image dictionary is available.
  110.     (setq imgDictId  (cdr (car imgDict))
  111.        dictLength (length imgdict)
  112.        counter  0
  113.        next  T
  114.     )
  115.     (while (< counter dictLength)
  116.       (if (equal (car (nth counter imgDict)) 3)
  117.        ;; Entry name found. Get it.
  118.        (progn
  119.         ;; Get dictionary entry name
  120.         ;; and the dictionary entry
  121.         (setq dictName (strcase (cdr (nth counter imgDict)))
  122.            dictEntry (dictnext imgDictId next)
  123.            next  nil
  124.         )
  125.         ;; Compare the entry name with the given name.
  126.         (if (wcmatch dictName imgname)
  127.           (progn
  128.            ;; Entry found. Set the 'loaded' flag
  129.            (setq dictEntry (subst (cons 280 status)
  130.                       (assoc 280 dictEntry)
  131.                       dictEntry
  132.                   )
  133.            )
  134.            ;; There is a problem in AutoCAD
  135.            ;; which is fixed by 'fixlist'.
  136.            ;; Some entities / objects should
  137.            ;; return on 'entget' 2D points,
  138.            ;; but VisualLisp gets 3D points.
  139.            ;; The (wrong) z value of thereturned
  140.            ;; point contains a random value
  141.            ;; which can break 'entmod'.
  142.            ;; In case of an image definition
  143.            ;; object we have to remove the
  144.            ;; z value of group code 10 and
  145.            ;; 11 before we can use 'entmod'.
  146.            (entmod (fixlist dictEntry))
  147.           )
  148.         )
  149.        )
  150.       )
  151.       (setq counter (1+ counter))
  152.     )
  153.    )
  154.   )
  155. )

  156. ;;; Internal function.
  157. ;;; This function avoids the problem with 2D / 3D points.
  158. ;;;
  159. (defun fixlist (imgDef /)
  160.   ;; Get the group code 10 and 11 list
  161.   (setq pt1 (assoc 10 imgDef)
  162.     pt2 (assoc 11 imgDef)
  163.   )
  164.   ;; Remove the z value of group code 10...
  165.   (setq imgDef (subst (list 10 (nth 1 pt1) (nth 2 pt1))
  166.            (assoc 10 imgDef)
  167.            imgDef
  168.         )
  169.   )
  170.   ;; ...and the z value of group code 11.
  171.   (setq imgDef (subst (list 11 (nth 1 pt2) (nth 2 pt2))
  172.            (assoc 11 imgDef)
  173.            imgDef
  174.         )
  175.   )
  176.   ;; Return the fixed list
  177.   imgDef
  178. )
  179. (princ "\nNew lisp functions:")
  180. (princ "\n(imgunload ), (imgreload ), (imgdetach)\n")
  181. (princ)

评分

参与人数 2D豆 +7 收起 理由
ScmTools + 2 资料分享奖!
牢固 + 5 很给力!经验;技术要点;资料分享奖!

查看全部评分

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

已领礼包: 685个

财富等级: 财运亨通

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

使用道具 举报

已领礼包: 329个

财富等级: 日进斗金

发表于 2014-8-31 14:07:27 | 显示全部楼层
从Visual LISP图像命令?由奥古斯托Goncalves



使用加载,卸载和脱离的图像命令选项,这是不可能使用AutoCAD ActiveX接口。相反,你要“重建”这些选项使用AutoLISP语言和Visual LISP函数。



图像加载:



这个命令选项的作品都存储在字典”的光栅图像定义对象acad_image_dict &quot;。这个对象使用dxfgroup代码280作为一个'装'标志。如果280组代码的值为1,图像文件是当前加载的;如果值为0,图像文件卸载。



为了在图像词典得到正确的入口(得到正确的图像定义对象)和设置此标志为1,使用imagereload函数(见下文)。



图像卸载:



这个命令选项使用国旗前面提到的。组的代码值280到0把图像文件。功能imgunload呢。



图像脱离:



此命令的选项删除指定的图像定义的对象和当前的绘图,以消除每一栅格图像的图像对象定义实体(删除)。该imgdetach功能呢。



你可以使用以下功能。他们“重建”的图像命令选项的功能。功能(imgreload),(imgunload)和(imgdetach)需要的图像的名称作为参数。对于图像的名称,使用AutoCAD通配符机制。



-本文出自晓东CAD家园-论坛,原文地址:http://bbs.xdcad.net/thread-668318-1-1.html
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-24 20:22 , Processed in 0.179098 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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