首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有使用AutoLISP脚本查找和替换文本的方法?

有没有使用AutoLISP脚本查找和替换文本的方法?
EN

Stack Overflow用户
提问于 2022-06-21 06:41:20
回答 2查看 598关注 0票数 1

我想以编程的方式使用VBA为AutoCAD生成代码。代码将在AutoCAD中找到并替换文本。我发现AutoLISP允许使用脚本在AutoCAD中调用命令。但是,由于"Find“命令将导致弹出窗口,因此它无法通过脚本完成该过程(即(命令"Find”文本“替换文本”)。

有没有使用AutoLISP脚本查找和替换文本的方法?

EN

Stack Overflow用户

发布于 2022-07-05 19:30:33

您要查找的AutoLsip中的特定命令是vl-string-subst。但是,在找到字符串中的第一个匹配项后,此操作将停止。如果你想通过整个字符串替换每一场比赛,那么Lee有一个简单的解决方案来解决这个问题。您可能需要在脚本中的某个地方添加vl-load-com才能使用vl-string-subst

代码语言:javascript
运行
复制
;;--------------------=={ String Subst }==--------------------;;
;;                                                            ;;
;;  Substitutes a string for all occurrences of another       ;;
;;  string within a string.                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  new - string to be substituted for 'old'                  ;;
;;  old - string to be replaced                               ;;
;;  str - the string to be searched                           ;;
;;------------------------------------------------------------;;
;;  Returns:  String with 'old' replaced with 'new'           ;;
;;------------------------------------------------------------;;

(defun LM:StringSubst ( new old str / inc len )
    (setq len (strlen new)
          inc 0
    )
    (while (setq inc (vl-string-search old str inc))
        (setq str (vl-string-subst new old str inc)
              inc (+ inc len)
        )
    )
    str
)
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72696324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档