乐筑天下

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

[编程交流] 用于图像的LISP

[复制链接]

8

主题

20

帖子

12

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 18:41:47 | 显示全部楼层 |阅读模式
大家好,
 
我想知道是否有可能创建一个lisp,可以同时将多个图像附加到AutoCAD 2010,并创建一个新层,该层的名称与每个图像的名称相同。
 
我下载了georefimg应用程序,该应用程序基于world文件将图像放置在AutoCAD中的特定位置,但有必要对每个图像分别执行此操作。在这个应用程序的情况下,首先要做的是附加一个图像到CAD,然后我可以使用georefimg选择一个图像(之前插入的),以便把它放在适当的部分。但是,如果我在随机位置均匀地附加许多图像,然后对所有图像使用此georefimg,则速度更快、效率更高。
 
如果有人知道如何准备这样的东西,我将不胜感激。
 
最美好的祝福,
雅库布
回复

使用道具 举报

6

主题

62

帖子

57

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 18:48:39 | 显示全部楼层
你好
 
 
ABC AutoCAD的“光栅管理器”允许选择多个图像并对其进行地理参考,但不适用于单个图层。如果你是AutoCAD 2010,应该没问题。
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 18:54:05 | 显示全部楼层
将目录路径更改为您想要的路径和要附加的扩展映像,它们必须位于目录路径中。
 
  1. (defun c:Test (/ fld p en e lst p files nm l r)
  2. ;; Tharwat 20.08.2015        ;;
  3. (if (and (findfile
  4.             (setq fld [color="red"]"C:\\\New folder"[/color])
  5.             )
  6.           (setq p     '(0. 0. 0.)
  7.                 en    (entlast)
  8.                 files (vl-directory-files fld "*.[color="red"]jpg[/color]" 1)
  9.                 )
  10.           )
  11.    (mapcar
  12.      '(lambda (im)
  13.         (vl-cmdf "_.-attach" (strcat fld "\" im) "_none" p "" "")
  14.         (if (not (eq en (setq e (entlast))))
  15.           (progn
  16.             (vla-getboundingbox
  17.               (setq o (vlax-ename->vla-object e))
  18.               'l
  19.               'r
  20.               )
  21.             (setq lst (mapcar 'vlax-safearray->list (list r l))
  22.                   p   (list (caar lst) (cadr (cadr lst)) 0.)
  23.                   en  e
  24.                   )
  25.             (if
  26.               (not (tblsearch "LAYER" (setq nm (vl-filename-base im))))
  27.                (progn
  28.                  (entmake (list '(0 . "LAYER")
  29.                                 '(100 . "AcDbSymbolTableRecord")
  30.                                 '(100 . "AcDbLayerTableRecord")
  31.                                 (cons 2 nm)
  32.                                 '(70 . 0)
  33.                                 )
  34.                           )
  35.                  (vla-put-layer o nm)
  36.                  )
  37.                )
  38.             )
  39.           )
  40.         )
  41.      files
  42.      )
  43.    )
  44. (princ)
  45. )(vl-load-com)
回复

使用道具 举报

8

主题

20

帖子

12

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 18:59:21 | 显示全部楼层
谢谢塔瓦的回复。我很好奇是否可以用这种方式修改下面的lisp,以获得与您发送给我的类似的结果。
 
使用上面的代码,我可以将许多图像插入CAD,但这些图像的名称有问题。我需要插入具有原始名称(无需修改)的图像,并为每个图像创建一个新层,其名称为前缀为xxx的图像:
 
图:1_2。jpg公司
层:xxx\u 1\u 2
 
我知道如果没有lisp编程的基本知识,帮助别人可能会很沮丧,但我想尽快开始学习。
 
谢谢你的帮助。
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
260
发表于 2022-7-5 19:04:20 | 显示全部楼层
如果你需要georefimg应用程序根据世界文件代码放置图像,将选定的图像放置在具有相同名称的层上,或者使用默认前缀将它们组合在一起,可能会更有帮助。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:06:50 | 显示全部楼层
我们使用Georgef lsp并手动拾取图像,通常情况下,lsp会更新所有3个图像,因此很容易对所有图像进行highlite处理,然后运行lisp。唯一的限制条件是jpg和jgw必须在一个目录中,否则它将要求选择目录。忽略对tiff的引用,我们使用jpg
 
  1. ;;;Reads world tiff file (.jgw) to scale and place image correctly in autocad.
  2. ;;;First insert all tiff images into drawing at whatever scale and insertion point.
  3. ;;;If the jgw exists in same directory and is named the same as the image selected,
  4. ;;;it will automatically be found and the image will be scaled and placed. If it is
  5. ;;;not in the same directory, the user can browse for the file.
  6. ;;;03.23.2011 Added support to create jgw files as well as support rotated images
  7. ;;;Needs a file with 6 lines (ScaleX Rotation -Rotation -ScaleY TopLeftXCoord TopLeftYCoord)
  8. ;  « Last Edit: April 12, 2011, 09:43:43 am by ronjonp »  
  9. (vl-load-com)
  10. (defun ss->lst (ss / e n out)
  11.    (setq n -1)
  12.    (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out)))
  13. )
  14. (defun _writefile (filename lst / file result)
  15.    (cond ((and (eq 'str (type filename)) (setq file (open filename "w")))
  16.    (foreach x lst
  17.      (write-line
  18.        (cond ((= (type x) 'str) x)
  19.              ((= (type x) 'int) (itoa x))
  20.              ((= (type x) 'real) (rtos x 2 6))
  21.              ((vl-prin1-to-string x))
  22.        )
  23.        file
  24.      )
  25.    )
  26.    (close file)
  27.    filename
  28.   )
  29.    )
  30. )
  31. (defun _readfile (filename / file result)
  32.    (cond
  33.      ((and (eq 'str (type filename)) (setq file (open filename "r")))
  34.       (while (setq line (read-line file)) (setq result (cons (vl-string-trim " " line) result)))
  35.       (close file)
  36.       (reverse result)
  37.      )
  38.    )
  39. )
  40. (setq opt "ReadIt")
  41. ;  (initget 0 "ReadIt WriteIt")
  42. ;  (setq        opt (cond ((getkword (strcat "\nImage World File [ReadIt/WriteIt] <" opt ">: ")))
  43. ;                  (opt)
  44. ;            )
  45. ; )
  46. (princ "\nSelect image(s): ")
  47. (setq pre (getvar 'dwgprefix))
  48. (if (and (setq ss (ssget '((0 . "image")))) (setq ss (ss->lst ss)))
  49.    (foreach image ss
  50.      (setq name    (vlax-get image 'name)
  51.     hgt            (vlax-get image 'height)
  52.     wdth    (vlax-get image 'width)
  53.     imhgt   (vlax-get image 'imageheight)
  54.     imwdth  (vlax-get image 'imagewidth)
  55.     rot            (vlax-get image 'rotation)
  56.     bpt            (vlax-get image 'origin)
  57.     imgpath (vl-filename-directory (vlax-get image 'imagefile))
  58.     jgw            (strcat imgpath "\" name ".jgw")
  59.      )
  60.      (if (= opt "ReadIt")
  61. (progn
  62.   (if (and (or (setq jgw (findfile (strcat pre name ".jgw")))
  63.                (setq jgw (findfile (strcat imgpath "\" name ".jgw")))
  64.                (setq jgw (getfiled (strcat "***Select <<" name ".jgw>>***") pre "jgw" 16))
  65.            )
  66.            (setq pre (strcat (vl-filename-directory jgw) "\"))
  67.            (setq data (mapcar 'atof (_readfile jgw)))
  68.            (> (length data) 5)
  69.            (setq l1 (car data))
  70.            (setq mvpt (list (nth 4 data) (nth 5 data) 0.0))
  71.       )
  72.     (progn (vla-put-imageheight image (* hgt l1))
  73.            (vla-put-imagewidth image (* wdth l1))
  74.            (vla-put-rotation image (cadr data))
  75.            (setq rot (vlax-get image 'rotation))
  76.            (setq bpt (polar bpt (+ (/ pi 2.) rot) (* hgt l1)))
  77.            (vlax-invoke image 'move bpt mvpt)
  78.            (princ (strcat "\njgw File Read - " jgw))
  79.     )
  80.     (princ "\njgw file NOT found or not correctly formatted!")
  81.   )
  82. )
  83. (progn (setq bpt (polar bpt (+ (/ pi 2.) rot) imhgt))
  84.        (if (setq jgw (_writefile
  85.                        (strcat imgpath "\" name ".jgw")
  86.                        (list (/ imhgt hgt)
  87.                              rot
  88.                              (strcat "-" (rtos (abs rot) 2 6))
  89.                              (strcat "-" (rtos (abs (/ imwdth wdth)) 2 6))
  90.                              (rtos (car bpt) 2 6)
  91.                              (rtos (cadr bpt) 2 6)
  92.                        )
  93.                      )
  94.            )
  95.         (print jgw)
  96.         (princ "\nError writing file...")
  97.        )
  98. )
  99.      )
  100.    )
  101. )
  102. (princ)
  103. ;;;Reads world tiff file (.jgw) to scale and place image correctly in autocad.
  104. ;;;First insert all tiff images into drawing at whatever scale and insertion point.
  105. ;;;If the jgw exists in same directory and is named the same as the image selected,
  106. ;;;it will automatically be found and the image will be scaled and placed. If it is
  107. ;;;not in the same directory, the user can browse for the file.
  108. ;;;03.23.2011 Added support to create jgw files as well as support rotated images
  109. ;;;Needs a file with 6 lines (ScaleX Rotation -Rotation -ScaleY TopLeftXCoord TopLeftYCoord)
  110. ;  « Last Edit: April 12, 2011, 09:43:43 am by ronjonp »  
  111. (vl-load-com)
  112. (defun ss->lst (ss / e n out)
  113.    (setq n -1)
  114.    (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out)))
  115. )
  116. (defun _writefile (filename lst / file result)
  117.    (cond ((and (eq 'str (type filename)) (setq file (open filename "w")))
  118.    (foreach x lst
  119.      (write-line
  120.        (cond ((= (type x) 'str) x)
  121.              ((= (type x) 'int) (itoa x))
  122.              ((= (type x) 'real) (rtos x 2 6))
  123.              ((vl-prin1-to-string x))
  124.        )
  125.        file
  126.      )
  127.    )
  128.    (close file)
  129.    filename
  130.   )
  131.    )
  132. )
  133. (defun _readfile (filename / file result)
  134.    (cond
  135.      ((and (eq 'str (type filename)) (setq file (open filename "r")))
  136.       (while (setq line (read-line file)) (setq result (cons (vl-string-trim " " line) result)))
  137.       (close file)
  138.       (reverse result)
  139.      )
  140.    )
  141. )
  142. (setq opt "ReadIt")
  143. ;  (initget 0 "ReadIt WriteIt")
  144. ;  (setq        opt (cond ((getkword (strcat "\nImage World File [ReadIt/WriteIt] <" opt ">: ")))
  145. ;                  (opt)
  146. ;            )
  147. ; )
  148. (princ "\nSelect image(s): ")
  149. (setq pre (getvar 'dwgprefix))
  150. (if (and (setq ss (ssget '((0 . "image")))) (setq ss (ss->lst ss)))
  151.    (foreach image ss
  152.      (setq name    (vlax-get image 'name)
  153.     hgt            (vlax-get image 'height)
  154.     wdth    (vlax-get image 'width)
  155.     imhgt   (vlax-get image 'imageheight)
  156.     imwdth  (vlax-get image 'imagewidth)
  157.     rot            (vlax-get image 'rotation)
  158.     bpt            (vlax-get image 'origin)
  159.     imgpath (vl-filename-directory (vlax-get image 'imagefile))
  160.     jgw            (strcat imgpath "\" name ".jgw")
  161.      )
  162.      (if (= opt "ReadIt")
  163. (progn
  164.   (if (and (or (setq jgw (findfile (strcat pre name ".jgw")))
  165.                (setq jgw (findfile (strcat imgpath "\" name ".jgw")))
  166.                (setq jgw (getfiled (strcat "***Select <<" name ".jgw>>***") pre "jgw" 16))
  167.            )
  168.            (setq pre (strcat (vl-filename-directory jgw) "\"))
  169.            (setq data (mapcar 'atof (_readfile jgw)))
  170.            (> (length data) 5)
  171.            (setq l1 (car data))
  172.            (setq mvpt (list (nth 4 data) (nth 5 data) 0.0))
  173.       )
  174.     (progn (vla-put-imageheight image (* hgt l1))
  175.            (vla-put-imagewidth image (* wdth l1))
  176.            (vla-put-rotation image (cadr data))
  177.            (setq rot (vlax-get image 'rotation))
  178.            (setq bpt (polar bpt (+ (/ pi 2.) rot) (* hgt l1)))
  179.            (vlax-invoke image 'move bpt mvpt)
  180.            (princ (strcat "\njgw File Read - " jgw))
  181.     )
  182.     (princ "\njgw file NOT found or not correctly formatted!")
  183.   )
  184. )
  185. (progn (setq bpt (polar bpt (+ (/ pi 2.) rot) imhgt))
  186.        (if (setq jgw (_writefile
  187.                        (strcat imgpath "\" name ".jgw")
  188.                        (list (/ imhgt hgt)
  189.                              rot
  190.                              (strcat "-" (rtos (abs rot) 2 6))
  191.                              (strcat "-" (rtos (abs (/ imwdth wdth)) 2 6))
  192.                              (rtos (car bpt) 2 6)
  193.                              (rtos (cadr bpt) 2 6)
  194.                        )
  195.                      )
  196.            )
  197.         (print jgw)
  198.         (princ "\nError writing file...")
  199.        )
  200. )
  201.      )
  202.    )
  203. )
  204. (princ)
回复

使用道具 举报

8

主题

20

帖子

12

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 19:12:59 | 显示全部楼层
我想知道是否有可能创建一个lisp例程,为图像创建一个新层。我会尽量详细解释这一点。
 
例如:我在Autocad中随机插入了一组图像。我想运行一个lisp例程,我会选择这些图像(这些图像的一个区域),按下“回车”键后,获得与每个图像同名的新层,并将此图像传输到每个创建的层中。
 
我有两张图片:图片1。jpg,图2。在这个过程之后,我会得到名称为:image1和image2的层,每个层都有这个图像。
 
有人知道怎么做吗?
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
260
发表于 2022-7-5 19:15:12 | 显示全部楼层
这应该做到:
  1. (vl-load-com)
  2. (defun c:Image2Lay (/ ss ent el Elay)
  3. (setq ss (ssget "+.:E:S" '((0 . "image"))))
  4. (if ss
  5.     (progn
  6.             (setq EOBJ (vlax-ename->vla-object (ssname SS 0))        ; Entity object
  7.                   Elay (vlax-get-property EOBJ 'Name )        ; Object layer
  8.             )
  9.             (or (tblsearch "layer" Elay)(command "-LAYER" "N" Elay ""))
  10.             (vlax-put-property EOBJ 'Layer Elay)
  11.     )
  12.     (princ "\nNo SS!")
  13. )
  14. )
回复

使用道具 举报

8

主题

20

帖子

12

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-5 19:21:38 | 显示全部楼层
当我使用这个例程时,我得到一条消息,其中“ssget”函数有一个错误(“+:E:S”)。为什么会弹出?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:24:59 | 显示全部楼层
尝试将“+:E:S”更改为“+:E:S”
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 13:50 , Processed in 0.423064 second(s), 72 queries .

© 2020-2025 乐筑天下

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