乐筑天下

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

[编程交流] 带matchprops的文本副本

[复制链接]

18

主题

59

帖子

41

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
90
发表于 2022-7-5 23:27:21 | 显示全部楼层 |阅读模式
大家好,
 
谁能告诉我怎么修改这个代码吗?它要求选择一个值,然后是应用一次还是多次。在多模式下,您仍然一次只能选择一个。我希望能够使用选择框一次应用于多个对象。
 
谢谢
-诺布尔
 
  1. ;;;;Realization {Smirnoff}
  2. ;;; TTCM - Text to Text copy whith Matchprop. Copy text from DIMENSION, TEXT,
  3. ;;;MTEXT, ATTRIB, ATTDEF, ACAD_TABLE to one
  4. (defun c:tt (/ actDoc vlaObj sObj sText curObj oldForm
  5.        oType oldMode conFlag errFlag *error* prop)
  6. (vl-load-com)
  7.      (setq actDoc(vla-get-ActiveDocument
  8.        (vlax-get-acad-object)))
  9.      (vla-StartUndoMark actDoc)
  10. (defun TTC_Paste(pasteStr / nslLst vlaObj hitPt
  11.                   hitRes Row Column)
  12.    (setq errFlag nil)
  13.    (if
  14.     (setq nslLst(nentsel "\nPaste text >"))
  15.      (progn
  16. (cond
  17.    (
  18.     (and
  19.       (= 4(length nslLst))
  20.       (= "DIMENSION"(cdr(assoc 0(entget(car(last nslLst))))))
  21.       ); end and
  22.     (setq vlaObj
  23.      (vlax-ename->vla-object
  24.        (cdr(assoc -1(entget(car(last nslLst)))))))
  25.     (if
  26.       (vl-catch-all-error-p
  27.         (vl-catch-all-apply
  28.     'vla-put-TextOverride(list vlaObj pasteStr)))
  29.         (progn
  30.         (princ "\n Can't paste. Object may be on locked layer. ")
  31.         (setq errFlag T)
  32.         ); end progn
  33.       ); end if
  34.     ); end condition #1
  35.    (
  36.     (and
  37.       (= 4(length nslLst))
  38.       (= "ACAD_TABLE"(cdr(assoc 0(entget(car(last nslLst))))))
  39.       ); end and
  40.     (setq vlaObj
  41.      (vlax-ename->vla-object
  42.        (cdr(assoc -1(entget(car(last nslLst))))))
  43.     hitPt(vlax-3D-Point(trans(cadr nslLst)1 0))
  44.     hitRes(vla-HitTest vlaObj hitPt
  45.        (vlax-3D-Point '(0.0 0.0 1.0)) 'Row 'Column)
  46.           ); end setq
  47.     (if(= :vlax-true hitRes)
  48.     (progn
  49.         (if
  50.     (vl-catch-all-error-p
  51.       (vl-catch-all-apply
  52.         'vla-SetText(list vlaObj Row Column pasteStr)))
  53.     (progn
  54.       (princ "\n Can't paste. Object may be on locked layer. ")
  55.       (setq errFlag T)
  56.       ); end progn
  57.     ); end if
  58.         ); end progn
  59.       ); end if
  60.     ); end condition # 2
  61.    (
  62.     (and
  63.       (= 4(length nslLst))
  64.       (= "INSERT"(cdr(assoc 0(entget(car(last nslLst))))))
  65.       ); end and
  66.     (princ "\nCan't paste to block's DText or MText. Select Attribute ")
  67.     (setq errFlag T)
  68.     ); end condition #3
  69.    (
  70.     (and
  71.       (= 2(length nslLst))
  72.         (member(cdr(assoc 0(entget(car nslLst))))
  73.           '("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))
  74.       ); end and
  75.     (setq vlaObj
  76.      (vlax-ename->vla-object(car nslLst)))
  77.        (if
  78.     (vl-catch-all-error-p
  79.       (vl-catch-all-apply
  80.         'vla-put-TextString(list vlaObj pasteStr)))
  81.    (progn
  82.       (princ "\nError. Can't pase text. ")
  83.      (setq errFlag T)
  84.      ); end progn
  85.     ); end if
  86.     ); end condition #4
  87.    (T
  88.     (princ "\nCan't paste. Invalid object. ")
  89.     (setq errFlag T)
  90.     ); end condition #5
  91.    ); end cond
  92.    (if (and (null errFlag)
  93.             (= (type vlaObj) 'VLA-OBJECT))
  94.    (mapcar '(lambda (x y) (vlax-put-property vlaObj x y))
  95.        '(Linetype LineWeight Color Layer)
  96.        prop
  97.        )
  98.      )
  99.             T
  100.      ); end progn
  101.            nil
  102.           ); end if
  103.    ); end of TTC_Paste
  104.    (defun TTC_MText_Clear(Mtext / Text Str)
  105.    (setq Text "")
  106.    (while(/= Mtext "")
  107.      (cond
  108. ((wcmatch
  109.     (strcase
  110.       (setq Str
  111.        (substr Mtext 1 2)))
  112.                     "[url="file://\"]\\[/url][\\{}`~]")
  113.   (setq Mtext(substr Mtext 3)
  114.         Text(strcat Text Str)
  115.   ); end setq
  116. ); end condition #1
  117. ((wcmatch(substr Mtext 1 1) "[{}]")
  118.    (setq Mtext
  119.     (substr Mtext 2))
  120. ); end condition #2
  121. (
  122.   (and
  123.   (wcmatch
  124.     (strcase
  125.       (substr Mtext 1 2)) "[url="file://\\P"]\\P[/url]")
  126.   (/=(substr Mtext 3 1) " ")
  127.    ); end and
  128.         (setq Mtext (substr Mtext 3)
  129.               Text (strcat Text " ")
  130.         ); end setq
  131.   ); end condition #3
  132. ((wcmatch
  133.     (strcase
  134.       (substr Mtext 1 2)) "[url="file://\"]\\[/url][LOP]")
  135.    (setq Mtext(substr Mtext 3))
  136. ); end condition #4
  137. ((wcmatch
  138.     (strcase
  139.       (substr Mtext 1 2)) "[url="file://\"]\\[/url][ACFHQTW]")
  140.    (setq Mtext
  141.     (substr Mtext
  142.       (+ 2
  143.          (vl-string-search ";" Mtext))))
  144. ); end condition #5
  145. ((wcmatch
  146.     (strcase (substr Mtext 1 2)) "[url="file://\\S"]\\S[/url]")
  147.    (setq Str(substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
  148.          Text(strcat Text (vl-string-translate "#^\" " " Str))
  149.          Mtext(substr Mtext (+ 4 (strlen Str)))
  150.   ); end setq
  151.   (print Str)
  152. ); end condition #6
  153. (T
  154.   (setq Text(strcat Text(substr Mtext 1 1))
  155.         Mtext (substr Mtext 2)
  156.   )
  157. ); end condition #7
  158.      ); end cond
  159.    ); end while
  160. Text
  161. ); end of TTC_MText_Clear
  162. (defun TTC_Copy (/ sObj sText tType actDoc)
  163.   (if
  164.    (and
  165.     (setq sObj(car(nentsel "\nCopy text... ")))
  166.     (member(setq tType(cdr(assoc 0(entget sObj))))
  167.      '("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))
  168.     ); end and
  169.    (progn
  170.      (setq actDoc(vla-get-ActiveDocument
  171.        (vlax-get-Acad-object))
  172.      sText(vla-get-TextString
  173.       (vlax-ename->vla-object sObj))
  174.      ); end setq
  175.      (if(= tType "MTEXT")
  176. (setq sText(TTC_MText_Clear sText))
  177. ); end if
  178.      ); end progn
  179.    ); end if
  180. (setq prop (mapcar '(lambda (x)
  181.             (vlax-get-property (vlax-ename->vla-object sObj)  x))
  182.      '(Linetype LineWeight Color Layer)
  183.          )
  184.        )
  185.    sText
  186.    ); end of TTC_Copy
  187. (defun CCT_Str_Echo(paseStr / comStr)
  188.    (if(< 20(strlen paseStr))
  189.      (setq comStr
  190.       (strcat
  191.         (substr paseStr 1 17)"..."))
  192.      (setq comStr paseStr)
  193.      ); end if
  194.    (princ
  195.      (strcat "\nText = "" comStr """))
  196.    (princ)
  197.    ); end of CCT_Str_Echo
  198.    (defun *error*(msg)
  199.    (vla-EndUndoMark
  200.      (vla-get-ActiveDocument
  201.        (vlax-get-acad-object)))
  202.    (princ "\nQuit TTCM")
  203.    (princ)
  204.    ); end of *error*
  205.    (if(not ttc:Mode)(setq ttc:Mode "Multiple"))
  206.    (initget "Multiple Pair-wise")
  207.    (setq oldMode ttc:Mode
  208.    ttc:Mode
  209.     (getkword
  210.       (strcat "\nSpecify mode [Multiple/Pair-wise] <" ttc:Mode ">: "))
  211.    conFlag T
  212.    paseStr ""
  213.     ); end setq
  214.    (if(null ttc:Mode)(setq ttc:Mode oldMode))
  215.    (if(= ttc:Mode "Multiple")
  216.      (progn
  217. (if(and(setq paseStr(TTC_Copy))conFlag)
  218.    (progn
  219.    (CCT_Str_Echo paseStr)
  220.    (while(setq conFlag(TTC_Paste paseStr))T
  221.      ); end while
  222.    ); end progn
  223.    ); end if
  224. ); end progn
  225.      (progn
  226. (while
  227.    (and conFlag paseStr)
  228.    (setq paseStr(TTC_Copy))
  229.    (if(and paseStr conFlag)
  230.      (progn
  231.    (CCT_Str_Echo paseStr)
  232.    (setq errFlag T)
  233.    (while errFlag
  234.    (setq conFlag(TTC_Paste paseStr))
  235.         );end while
  236.       ); end progn
  237.      ); end if
  238.    ); end while
  239. ); end progn
  240.      ); end if
  241.   (vla-EndUndoMark actDoc)
  242.   (princ "\nQuit TTCM")
  243. (princ)
  244. ); end c:ttc
  245. (princ "\n\t TTCM - Text to Text copy with matchprop.")
  246. (princ "\nCopy text from DIMENSION, TEXT, MTEXT, ATTRIB, ATTDEF, ACAD_TABLE to one")
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 23:47:49 | 显示全部楼层
这是我的一个老程序,它可能会有所帮助:复制或交换文本
回复

使用道具 举报

18

主题

59

帖子

41

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
90
发表于 2022-7-6 00:10:40 | 显示全部楼层
 
感谢更新的lisp。老的还可以,但你的就行了。荣誉
 
再次感谢,
-诺布尔
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:20:57 | 显示全部楼层
不客气,这也是一个老程序,但我很高兴它仍然有用
回复

使用道具 举报

18

主题

59

帖子

41

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
90
发表于 2022-7-6 00:32:48 | 显示全部楼层
 
这个Lisp程序一直都很好,但有两个调整会让这个Lisp程序真的让我和可能的几个同事感到震惊。
1.有没有办法默认“多个”粘贴功能,或者选择单粘贴,或者根本不选择?我一直在使用它,这相当重要,似乎我从来没有这个需要一次。
2.我似乎不能用它来粘贴替代维度?有没有办法做到这一点?例如,有时我需要将维度替换为“E.O.S.”,并在其周围放置一个云。如果我能这样做一次,并能够复制/粘贴其余的将非常好。
 
谢谢
-诺布尔
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 00:08 , Processed in 0.352690 second(s), 62 queries .

© 2020-2025 乐筑天下

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