乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 55|回复: 3

[编程交流] 使用Nil

[复制链接]

15

主题

64

帖子

49

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 16:20:29 | 显示全部楼层 |阅读模式
大家好,
 
我正在使用在线找到的LiSP作为我正在构建的更大LiSP的一部分。该例程查找未找到/未引用/孤立/卸载的图像并将其删除。当图像出现时,它工作。现在LiSP的问题是,如果没有图像,它就会出错;错误:错误的参数类型:lselsetp nil。
 
如果没有图像,我该如何修改它以在代码中继续?如果我什么都不做。此外,它似乎也删除了有效的图像。我希望它只是删除未找到/未引用/孤立/卸载的图像(如果存在)。
 
谢谢
 
  1. ;|***********************---wiz24MAR09---**************************
  2. ;lisproutine for detaching not_found/unreferenced/orphaned/unloaded
  3. ;images,not yet tested on nested images|;
  4. (defun c:imgdet2 (/
  5.                 imgpath_lst
  6.                 img_dep
  7.                 img_info
  8.                 img_info340
  9.                 img_path
  10.                 img_set
  11.                 im_dict
  12.                 im_ent
  13.                 im_ent_1
  14.                 im_lst
  15.                 im_lst_1
  16.                 wiz_cnt
  17.                )
  18.    (vl-load-com)
  19. ;;;------------------------------------------------------------
  20.    ;;List all images which are present in the drawing in var = im_lst_1
  21.    (setq img_set (ssget "_x" '((0 . "IMAGE"))))
  22.    (setq i (sslength img_set))
  23.    (while (not (minusp (setq i (1- i))))
  24.        (setq im_ent_1 (ssname img_set i))
  25.        (setq img_info (entget im_ent_1))
  26.        (setq img_info340 (entget (cdr (assoc 340 img_info))))
  27.        (setq img_path (cdr (assoc 1 img_info340)))
  28.        (if (not (member img_path im_lst_1))
  29.            (setq im_lst_1 (cons img_path im_lst_1))
  30.        ) ;_ {if
  31.    ) ;_ {while
  32. ;;;------------------------------------------------------------  
  33.    ;;List all images saved in the file_dependencies in var = imgpath_lst
  34.    (setq imgpath_lst '())
  35.    (vlax-for
  36.             i
  37.              (setq img_dep
  38.                       (vla-get-FileDependencies
  39.                           (vla-get-ActiveDocument
  40.                               (vlax-get-Acad-Object)
  41.                           ) ;_ {vla-get-ActiveDocument
  42.                       ) ;_ {vla-get-FileDependencies
  43.              ) ;_ {vla-get-FileDependencies
  44.        (if (= (vla-get-Feature i) "Acad:Image")
  45.            (setq imgpath_lst
  46.                     (cons
  47.                         (vl-catch-all-apply
  48.                             (function
  49.                                 (lambda ()
  50.                                     (vla-get-FullFileName i)
  51.                                 ) ;_ {lambda
  52.                             ) ;_ {function
  53.                         ) ;_ {VL-CATCH-ALL-APPLY
  54.                         imgpath_lst
  55.                     ) ;_ {cons
  56.            ) ;_ {setq
  57.        ) ;_ {if
  58.    ) ;_ {vlax-for
  59.                    ;(vlax-release-object img_dep)
  60. ;;;------------------------------------------------------------  
  61.    ;;List all images saved in the image_dictionary in var im_lst
  62.    (setq im_dict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
  63.    (setq wiz_cnt -1)
  64.    (setq im_lst '())
  65.    (while
  66.        (setq im_ent
  67.                 (nth
  68.                     (setq wiz_cnt (1+ wiz_cnt))
  69.                     im_dict
  70.                 ) ;_ {nth
  71.        ) ;_ {setq
  72.           (if (eq (car im_ent) 3)
  73.               (setq im_lst ;_Image list to process below
  74.                        (cons
  75.                            (cons
  76.                                (cdr im_ent)
  77.                                (cdr
  78.                                    (nth
  79.                                        (setq wiz_cnt (+ wiz_cnt 1))
  80.                                        im_dict
  81.                                    ) ;_ {nth
  82.                                ) ;_ {cdr
  83.                            ) ;_ {cons
  84.                            im_lst
  85.                        ) ;_ {cons
  86.               ) ;_ {setq
  87.           ) ;_ {if
  88.    ) ;_ end_while
  89. ;;;------------------------------------------------------------  
  90.    ;;Begin Process
  91.    ;;Check if im_lst is present in im_lst_1 and imgpath_lst
  92.    ;;
  93.    (mapcar
  94.        (function
  95.            (lambda (x)
  96.                (if
  97.                    (or
  98.                        ;;If im_lst is not member of im_lst_1
  99.                        ;;then it is orphaned/unreferenced
  100.                        (not (member (cdr (assoc 1 (entget (cdr x)))) im_lst_1))
  101.                        ;;if im_list is not member of imgpath_lst
  102.                        ;;then it is not found
  103.                        (not (member (cdr (assoc 1 (entget (cdr x))))
  104.                                     imgpath_lst
  105.                             ) ;_ {member
  106.                        ) ;_ {not
  107.                        ;;if assoc 280 is 0 then it is unloaded
  108.                        (zerop (cdr (assoc 280 (entget (cdr x)))))
  109.                    ) ;_ {or
  110.                       (vl-catch-all-apply
  111.                           (function
  112.                               (lambda ()
  113.                                   (vla-delete (vlax-ename->vla-object (cdr x)))
  114.                               ) ;_ {lambda
  115.                           ) ;_ {function
  116.                       ) ;_ {vl-catch-all-apply
  117.                ) ;_ {if
  118.            ) ;_ {lamda
  119.        ) ;_ {function
  120.        im_lst
  121.    ) ;_ {mapcar
  122.    (princ)
  123. ) ;_ {defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:54:13 | 显示全部楼层
粗略地看一眼后,改变:
  1.     (setq img_set (ssget "_x" '((0 . "IMAGE"))))
  2.    (setq i (sslength img_set))
  3.    (while (not (minusp (setq i (1- i))))
  4.        (setq im_ent_1 (ssname img_set i))
  5.        (setq img_info (entget im_ent_1))
  6.        (setq img_info340 (entget (cdr (assoc 340 img_info))))
  7.        (setq img_path (cdr (assoc 1 img_info340)))
  8.        (if (not (member img_path im_lst_1))
  9.            (setq im_lst_1 (cons img_path im_lst_1))
  10.        ) ;_ {if
  11.    ) ;_ {while
至:
  1.     (if (setq img_set (ssget "_x" '((0 . "IMAGE"))))
  2.        (progn
  3.            (setq i (sslength img_set))
  4.            (while (not (minusp (setq i (1- i))))
  5.                (setq im_ent_1 (ssname img_set i))
  6.                (setq img_info (entget im_ent_1))
  7.                (setq img_info340 (entget (cdr (assoc 340 img_info))))
  8.                (setq img_path (cdr (assoc 1 img_info340)))
  9.                (if (not (member img_path im_lst_1))
  10.                    (setq im_lst_1 (cons img_path im_lst_1))
  11.                ) ;_ {if
  12.            ) ;_ {while
  13.        )
  14.    )
回复

使用道具 举报

15

主题

64

帖子

49

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-5 17:09:08 | 显示全部楼层
李,
 
成功了,非常感谢!我觉得自己像个白痴,我离得太近了,我有(如果)并且忘了添加(程序。再次感谢你。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:34:54 | 显示全部楼层
不客气!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-6 11:18 , Processed in 0.381766 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表