找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 3715|回复: 26

[每日一码] 提供三个纯LISP写的图像处理函数

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2016-5-23 22:51:32 | 显示全部楼层 |阅读模式

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

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

×
三个函数: (imgunload <imgname>), (imgreload <imgname>), (imgdetach<imgname>)

卸载、重载、DETACH

问题:
How can I call the IMAGE command from Visual LISP using (command "-IMAGE") in
AutoCAD?


方案解决


To use the RELOAD, UNLOAD and DETACH options of the IMAGE command, it is not
possible to use the AutoCAD ActiveX inte**ce. 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.

(imgreload "image1")
(imgunload "i*")
(imgdetach "?abc?ef*")

  1. ;
  2. ;;; Use the function 'imgunload' instead of
  3. ;;; calling the command
  4. ;;; -IMAGE _Unload
  5. ;;;
  6. (defun imgunload (imgname)
  7.    (imgloadstat (strcase imgname) 0)
  8.    (princ)
  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. );;; Use the function 'imgdetach' instead of
  17. ;;; calling the command
  18. ;;; -IMAGE _Detach
  19. ;;;
  20. (defun imgdetach (imgname / imgDict imgDictId dictLength counter
  21.                   dictName imgDefIds selSet imgDefId)   ;; Iterate all dictionary entries and remove
  22.    ;; the entries which matches 'imgname'.   (setq imgname (strcase imgname)
  23.          imgDict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")
  24.    )
  25.    (if (equal imgDict nil)
  26.       (princ "\nNo images loaded.")
  27.       (progn
  28.          ;; Image dictionary is available.
  29.          (setq imgDictId  (cdr (car imgDict))
  30.                dictLength (length imgdict)
  31.                counter   0
  32.          )
  33.          (while (< counter dictLength)
  34.             (if (equal (car (nth counter imgDict)) 3)
  35.                ;; Entry name found. Get it.
  36.                (progn
  37.                   (setq dictName (strcase (cdr (nth counter imgDict))))
  38.                   ;; Compare the entry name.
  39.                   (if (wcmatch dictName imgname)
  40.                      (progn
  41.                         ;; Remove the dictionary entry...
  42.                         (dictremove imgDictId dictName)
  43.                         ;; ...and store the entity name of
  44.                         ;; the raster image definition object.
  45.                         (setq imgDefIds
  46.                            (append imgDefIds
  47.                                    (list (cdr (nth (1+ counter) imgDict)))
  48.                            )
  49.                         )
  50.                      )
  51.                   )
  52.                )
  53.             )
  54.             (setq counter (1+ counter))
  55.          )
  56.          ;; Finished iterating the dictionary.
  57.          ;; Do we have to remove some raster image entities?
  58.          (if (/= (length imgDefIds) 0)
  59.             ;; Yes, we have to remove some raster image entities
  60.             ;; (because the related image definition objects
  61.             ;; have been removed).
  62.             (progn
  63.                ;; Select all image entities.
  64.                (setq selSet  (ssget "X" '((0 . "IMAGE")))
  65.                      counter 0
  66.                )
  67.                (if (/= selSet nil)
  68.                   (progn
  69.                      ;; Iterate all image entities
  70.                      (while (< counter (sslength selSet))
  71.                         ;; Get the entity name of the referenced
  72.                         ;; image definition object.
  73.                         (setq imgDefId
  74.                            (cdr (assoc 340 (entget (ssname selSet counter))))
  75.                         )
  76.                         ;; Is the referenced definition object gone?
  77.                         (if (member imgDefId imgDefIds)
  78.                            ;; The definition for this image entity
  79.                            ;; have been removed, so let us remove
  80.                            ;; the image entity, as well.
  81.                            (entdel (cdr (car (entget (ssname selSet counter)))))
  82.                         )
  83.                         (setq counter (1+ counter))
  84.                      )
  85.                      ;; Empty the selection set
  86.                      (setq selSet nil)
  87.                   )
  88.                )
  89.             )
  90.          )
  91.       )
  92.    )
  93.    (princ)
  94. );;; Internal function.
  95. ;;; This function is called by 'imgunload'
  96. ;;; and 'imgreload'.
  97. ;;;
  98. (defun imgloadstat (imgname status / imgDict imgDictId
  99.                     dictLength counter dictName dictEntry next)   ;; Get the image dictionary
  100.    (setq imgDict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
  101.    (if (equal imgDict nil)
  102.       (princ "\nNo images loaded.")
  103.       (progn
  104.          ;; Image dictionary is available.
  105.          (setq imgDictId  (cdr (car imgDict))
  106.                dictLength (length imgdict)
  107.                counter   0
  108.                next   T
  109.          )
  110.          (while (< counter dictLength)
  111.             (if (equal (car (nth counter imgDict)) 3)
  112.                ;; Entry name found. Get it.
  113.                (progn
  114.                   ;; Get dictionary entry name
  115.                   ;; and the dictionary entry
  116.                   (setq dictName (strcase (cdr (nth counter imgDict)))
  117.                         dictEntry (dictnext imgDictId next)
  118.                         next   nil
  119.                   )
  120.                   ;; Compare the entry name with the given name.
  121.                   (if (wcmatch dictName imgname)
  122.                      (progn
  123.                         ;; Entry found. Set the 'loaded' flag
  124.                         (setq dictEntry (subst (cons 280 status)
  125.                                                (assoc 280 dictEntry)
  126.                                                dictEntry
  127.                                         )
  128.                         )
  129.                         ;; There is a problem in AutoCAD which is fixed by 'fixlist'.
  130.                         ;; Some entities / objects should return on 'entget' 2D points,
  131.                         ;; but VisualLisp gets 3D points. The (wrong) z value of thereturned
  132.                         ;; point contains a random value which can break 'entmod'.
  133.                         ;; In case of an image definition object we have to remove the
  134.                         ;; z value of group code 10 and 11 before we can use 'entmod'.
  135.                         (entmod (fixlist dictEntry))
  136.                      )
  137.                   )
  138.                )
  139.             )
  140.             (setq counter (1+ counter))
  141.          )
  142.       )
  143.    )
  144. );

游客,如果您要查看本帖隐藏内容请回复

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

已领礼包: 3198个

财富等级: 富可敌国

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

使用道具 举报

已领礼包: 5583个

财富等级: 富甲天下

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

使用道具 举报

已领礼包: 2963个

财富等级: 家财万贯

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

使用道具 举报

已领礼包: 6881个

财富等级: 富甲天下

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

使用道具 举报

已领礼包: 604个

财富等级: 财运亨通

发表于 2016-5-24 11:46:57 | 显示全部楼层
用cad来处理图像,N版很有艺术细胞嘛
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 13个

财富等级: 恭喜发财

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

使用道具 举报

已领礼包: 20个

财富等级: 恭喜发财

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

使用道具 举报

已领礼包: 2409个

财富等级: 金玉满堂

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

使用道具 举报

已领礼包: 620个

财富等级: 财运亨通

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

使用道具 举报

已领礼包: 1999个

财富等级: 堆金积玉

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

使用道具 举报

已领礼包: 3715个

财富等级: 富可敌国

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

使用道具 举报

已领礼包: 6468个

财富等级: 富甲天下

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

使用道具 举报

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

使用道具 举报

已领礼包: 432个

财富等级: 日进斗金

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 03:45 , Processed in 0.430877 second(s), 56 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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