明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 796|回复: 2

[源码] 批量拆离影像

[复制链接]
发表于 2018-6-16 16:29 | 显示全部楼层 |阅读模式
本帖最后由 yangqingchao 于 2018-6-19 15:27 编辑
  1. 有时修影像已经删除,但没有拆离,再次插入的时候会提示出错,本程序可以批量拆离已删除影像。本人刚接触autolisp,请不要见笑!
复制代码

  1. (prompt "本程序执行命令是: DetachIMG\n")
  2. (defun c:DetachIMG ( / imageDict ss1 ss2 num lst newlst n blkName fileList)
  3.   (setvar "cmdecho" 0)
  4.   (setq ss1 (X:flists))
  5.   (setq imageDict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
  6.   (setq num (length imageDict))
  7.   (setq lst (XD:ist:Nth++ imageDict 10 (- num 10)))
  8.   (setq newlst (XD:IST:Group-n lst 2))
  9.   (setq n (length newlst))
  10.   (while (< 0 n)
  11.     (setq blkName (cdr (car (nth (setq n (- n 1)) newlst))))
  12.     (setq fullName (cdr (assoc 1 (entget (cdr (car (cdr (nth n newlst))))))))
  13.     (setq fileName (strcat (vl-filename-base fullName) (vl-filename-extension fullName)))
  14.     (if (= nil ss1)
  15.       (progn
  16.         (setq fileList (cons fileName fileList))
  17.         (command "_image" "Detach" blkName)
  18.         (princ (strcat filename "在文档中已删除,因此被拆离!\n"))
  19.       )
  20.       (progn
  21.         (setq ss2 (vl-remove-if-not '(lambda (x) (= x fullName)) ss1))
  22.         (if (= nil ss2)
  23.           (progn
  24.             (setq fileList (cons fileName fileList))
  25.             (command "_image" "Detach" blkName)
  26.             (princ (strcat filename "在文档中已删除,因此被拆离!\n"))
  27.           )
  28.         )
  29.       )
  30.     )
  31.   )
  32.   (vl-sort fileList '<)
  33.   (if (/= nil fileList)
  34.     (princ (strcat "共拆离" (itoa (length fileList)) "张影像!\n"))
  35.    (princ "没有影像可以拆离!\n")
  36.   )
  37.   (princ)
  38. )
  39. (defun X:flists( / *fullName *fileName filelists)
  40.   (setq ss (ssget "X" '((0 . "IMAGE"))));;;全选所有光栅对象
  41.   (if (= nil ss);;;如果不存在
  42.     (setq filelists nil);;;没有对象,则返回nil
  43.     (progn
  44.     (setq i (sslength ss))
  45.       (while (< 0 i)
  46.         (setq ee (ssname ss (setq i (1- i))))
  47.         (setq vlaobj (vlax-ename->vla-object ee))
  48.         (setq *fullName (vla-get-ImageFile vlaobj))
  49.         ;(setq *fileName (strcat (vl-filename-base *fullName) (vl-filename-extension *fullName)))
  50.         (setq filelists (cons *fullName filelists))
  51.       )
  52.     )   
  53.   )
  54.   (vl-sort filelists '<);;;返回排序列表
  55. )
  56. ;;;此函数来自晓东CAD
  57. (defun XD:ist:Nth++ (l s n)
  58.     (repeat (/ s 4) (setq l (cddddr l)))
  59.     (repeat (rem s 4) (setq l (cdr l)))
  60.     (setq s nil)
  61.     (if (and l n)
  62.         (cond ((>= n (length l)) l)
  63.               ((< n (- (length l) n))
  64.                (repeat (/ n 4)
  65.                    (setq s (cons (cadddr l)
  66.                                  (cons (caddr l) (cons (cadr l) (cons (car l) s)))
  67.                            )
  68.                          l (cddddr l)
  69.                    )
  70.                )
  71.                (repeat (rem n 4)
  72.                    (setq s (cons (car l) s)
  73.                          l (cdr l)
  74.                    )
  75.                )
  76.                (reverse s)
  77.               )
  78.               (t
  79.                (setq l (reverse l)
  80.                      s (- (length l) n)
  81.                )
  82.                (repeat (/ s 4) (setq l (cddddr l)))
  83.                (repeat (rem s 4) (setq l (cdr l)))
  84.                (reverse l)
  85.               )
  86.         )
  87.         l
  88.     )
  89. )
  90. ;;;此函数来自晓东CAD
  91. (defun XD:IST:Group-n ( l n / a b )
  92.     (while l
  93.         (repeat n
  94.             (setq a (cons (car l) a)
  95.                   l (cdr l)
  96.             )
  97.         )
  98.         (setq b (cons (reverse a) b)
  99.               a nil
  100.         )
  101.     )
  102.     (reverse b)
  103. )



发表于 2022-7-26 19:15 | 显示全部楼层
不用command 用vlisp 怎样写呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 12:20 , Processed in 0.360614 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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