大家好!
我星期五做了一个代码,我没有立即在图像dict中看到多个assoc的可能性(顺便说一句,在你的代码中这是一个非常聪明的方法)。我刚回来看到李把我带到终点线。
考虑到用户可能不希望系统地将所有图片重命名为其文件名,并提示用户选择需要恢复参考名称的图像,我采取了一种稍微不同的方法。我本可以使用更少的变量和代码行,但选择了更好的可读性。
用法:启动,选择屏幕上的图像(加载或卸载),参考名称将恢复。图像的加载/卸载状态不会改变,不需要“手动”重新加载。
- (defun c:RES ( / img_enam img_entdesc img_hardrefEname image_hardref image_path image_dict img_newiname newiname_dxf newimage_dict)
- ;Restore image reference name by the name of the source image file (found at, without path/extension)
- ;made by Jef! on 2016 March 29.
- (setvar 'errno 0)
- (while (not (and (setq img_enam (car(entsel "\nSelect the image to restore path: ")))
- (eq "IMAGE" (cdr (assoc 0 (entget img_enam))))
- )
- )
- (cond
- ( (= 52 (getvar 'errno))
- (princ "\nYou must select an image object. Press "ESCAPE" to cancel")
- (setvar 'errno 0)
- )
- ( (null img_enam)
- (princ "\nYou missed, try again.")
- )
- ( (not (eq "IMAGE" (cdr (assoc 0 img_entdesc))))
- (princ "\nYou must select an image object.")
- )
- )
- )
- (setq img_entdesc (entget img_enam)
- img_hardrefEname (cdr (assoc 340 img_entdesc))
- image_hardref (entget img_hardrefEname)
- image_path (cdr (assoc 1 image_hardref))
- image_dict (entget (cdr (assoc 330 image_hardref)))
- img_newiname (substr image_path
- (+ 2 (vl-string-position 92 image_path 0 t))
- (- (vl-string-position 46 image_path 0 t)
- (vl-string-position 92 image_path 0 t)
- 1
- )
- )
- newiname_dxf (cons 3 img_newiname)
- newimage_dict (subst newiname_dxf (nth 1 (member (cons 350 img_hardrefEname) (reverse image_dict))) image_dict);massoc!!
- )
- (entmod newimage_dict)
- (entmod image_hardref)
- (princ)
- )
|