乐筑天下

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

[编程交流] Editing text directly (without

[复制链接]

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:13:29 | 显示全部楼层 |阅读模式
I'm creating a code that edits my text objects in the same way.
I have a string with 9 characters, for example
"P01 12x34"
 
And all I wanna do to begin is adding a parentesis in the end and in the beginning of the numbers, like this
 
"P01 (12x34)"
 
and then convert this to mtext.
 
I've already found a way to convert to mtext, what i'm having problem with is editing the string, however I've found some code that actually reads the text of the object i select (which i need in this case):
 
(defun c:mtval( / ent objmtext stroldval
strnewval)
  (setq
ent (car (entsel))
objMText
(vlax-ename->vla-object ent)
strOldval (vlax-get-property objMText
"TEXTSTRING")
strnewval (getstring T (strcat "\nNew text value
stroldval ">: "))
)
  (if
strnewval
(vlax-put-property objmtext "TEXTSTRING"
strnewval)
)
  (vlax-release-object objmtext)
 
)
 
However, it prompts me, with the previous text in the object, to change it. I've tried to edit the "\nNew text value
 
(please note i've started with lisp 1 hour ago)
 
Thanks for any help
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:24:22 | 显示全部楼层
I've finally done it,
 
  1. (defun c:epp( / ent objmtext stroldval strnewval pname pnamee) (  setq ent (car (entsel)) objmtext (vlax-ename->vla-object ent)  strOldval (vlax-get-property objMText "TEXTSTRING")pname (substr strOldval 1 3)pnamee (substr strOldval 5 9 )   strnewval (strcat "\n" pname " (" pnamee ")" ))(prin1 pname)(prin1 pnamee)(vlax-put-property objmtext "TEXTSTRING" strnewval) (vlax-release-object objmtext) )
 
This effectively adds 2 parentesis where I wanted, without any kind of prompt.
 
However another problem has ocurred, it doesn't work if I have a object already selected.
Ideally it would convert all of the texts I have, adding 2 parentesis and converting to multiline. There's a code that converts multiple text objects into the same number of objects but as multiline.
 
 
  1. (defun c:t2m ()(setq Tset (ssget '((0 . "*TEXT")))) ;filter text in selection set(setq        Setlen (sslength Tset) ;setq number of entties in selection set, setq count(er) to 0Count 0) ;setq(repeat SetLen ;repeat setlen times(setq Ename (ssname Tset Count)) ;setq ename to be the "0..." entity in selection set Tset(command "_txt2mtxt" Ename "")(setq Count (+ 1 Count)) ; add 1 to Count(er))        ; Repeat        (princ))
 
Is it possible to combine both? In a way that multiple single text objects will get the brackets as in the 1st code, and get converted into multiline objects?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:28:19 | 显示全部楼层
Try the following:
  1. (defun c:fixtxt ( / a e o s x )   (if (setq s (ssget "_:L" '((0 . "TEXT"))))       (repeat (setq i (sslength s))           (setq e (ssname s (setq i (1- i)))                 x (entget e)                 a (assoc 1 x)           )           (entmod (subst (cons 1 (strcat (substr (cdr a) 1 4) "(" (substr (cdr a) 5) ")")) a x))           (command "_.txt2mtxt" e "")       )   )   (princ))
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:37:10 | 显示全部楼层
wow.. flawless.. i will now try to match the properties of one object to all those selected, brb, thank you very much
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:40:20 | 显示全部楼层
You're welcome! - Good luck with your coding.
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:48:42 | 显示全部楼层
@Lee Mac
Would something like this be possible to do in DIESEL or with a macro? I've noticed I will use LT soon, and lisp will not be compatible with it. Also, I couldn't find anything like a text editing possibility in macros.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:55:50 | 显示全部楼层
 
Unfortunately not - a macro could perform the selection of the text object and subsequent modification to the text content, but there would be no way to retrieve the existing content of the text object and therefore no way to construct the new text string.
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 19:05:59 | 显示全部楼层
There's actually a diesel code that retrieves the current text
 
191330xjzcu4zjaciit82a.png
 
So I would only have to edit it, how can i modify the text via the command line?
 
Also I tought of using find and replace function, with wildcards. Most of my elements are "25x25" or "25x40" so i could make a few scripts and run trought all of them. However, the find option opens a windows, and I'm not able to define the search and replace parameters in the command line.
 
I've created a more appropriate topic here:
http://www.cadtutor.net/forum/showthread.php?95151-Edit-the-text-of-a-text-object-using-a-macro-diesel
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:11:55 | 显示全部楼层
 
Is there?
 
 
The FIND command is out of the question, as you cannot use a macro to send information to a GUI.
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 19:13:56 | 显示全部楼层
damn.. stuck on lisp :\
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 19:55 , Processed in 0.418325 second(s), 74 queries .

© 2020-2025 乐筑天下

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