乐筑天下

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

[编程交流] Coding Help - Adding numbers t

[复制链接]

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:17:08 | 显示全部楼层 |阅读模式
Here's what I have:
 
  1. ;;===================================================================(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +0'*")     (vla-put-textstring obj (Replace "EL +0" "EL +845" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +1'*")     (vla-put-textstring obj (Replace "EL +1" "EL +846" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +2'*")     (vla-put-textstring obj (Replace "EL +2" "EL +847" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +3'*")     (vla-put-textstring obj (Replace "EL +3" "EL +848" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +4'*")     (vla-put-textstring obj (Replace "EL +4" "EL +849" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +5'*")     (vla-put-textstring obj (Replace "EL +5" "EL +850" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +6'*")     (vla-put-textstring obj (Replace "EL +6" "EL +851" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +7'*")     (vla-put-textstring obj (Replace "EL +7" "EL +852" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +8'*")     (vla-put-textstring obj (Replace "EL +8" "EL +853" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +9'*")     (vla-put-textstring obj (Replace "EL +9" "EL +854" st))   ))(if (eq "AcDbText" (vla-get-objectname obj))   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +10'*")     (vla-put-textstring obj (Replace "EL +10" "EL +855" st))   ));;===================================================================
 
What I am trying to accomplish is this:
 
I want it to find EL +10' for example and add 845' to it, or more specifically.  Find x' and add x'+845' to it.  
 
Also, I want the new text to be placed on a layer called 'ISOMOD'
 
Thanks for your help.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 15:23:02 | 显示全部楼层
Maybe something along these lines - doesn't work well with MText formatting
 
http://www.cadtutor.net/forum/showthread.php?t=46697
 
Or there's this one:
 
http://www.cadtutor.net/forum/showthread.php?t=46688
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-5 15:24:04 | 显示全部楼层
 
  1. (defun c:Test (/ ss ent s) (and   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))   ((lambda (i)      (while (setq e (ssname ss (setq i (1+ i))))        (setq ent (entget e))        (foreach n '(0 1 2 3 4 5 6 7 8 9 10)          (if (vl-string-search (setq s (strcat "EL +" (itoa n) "'")) (cdr (assoc 1 ent)))            (entmod              (subst                (cons 1                      (vl-string-subst (strcat "EL +" (itoa (+ n 845)) "'") s (cdr (assoc 1 ent)))                )                (assoc 1 ent)                ent              )            )          )        )      )    )     -1   ) ) (princ))
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:28:05 | 显示全部楼层
 
This didn't work. My text is in the format: EL +27'-0 15/16 for example (It appears your code tries to add 845 to 27'-0 15/16" which doesnt work). I'm guessing it needs to find the 27 in the string and add 845 to it. What I did above is to search for EL +1'* to EL +99'* and add 845' to it, but another LISP I have needs 845'-6" added to the number. Also, After the operation is complete, I need it placed on the 'ISOMOD' layer.  
 
Basically, I'm looking for a way to simplify the code so I don't have to search for EL +1'*, EL +2'*, EL +3'*, etc (I'm always replacing values at the beginning of the string if that helps)... Plus trying to move the updated text value to the 'ISOMOD' layer.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-5 15:32:32 | 显示全部楼层
 

It works based on the information you provided.
If you could construct the above coding, you should be able to take what I have and run with it. Give it a shot instead of rudely telling me that my help doesn't work.
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:35:05 | 显示全部楼层
My apologies, being percieved as rude was not the intention.  Thanks for your help.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-5 15:37:15 | 显示全部楼层
 
Apology accepted. However, if you want proper help, you have to give ALL the information up front.
 
Give this a try...
  1. (defun c:Test (/ ss ent s num) (and   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))   ((lambda (i)      (while (setq e (ssname ss (setq i (1+ i))))        (setq ent (entget e)              s   (cdr (assoc 1 ent))              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))        )        (entmod (subst (cons 1 (vl-string-subst (itoa (+ 845 (atoi num))) num s))                       (assoc 1 ent)                       ent                )        )      )    )     -1   ) ) (princ))
回复

使用道具 举报

6

主题

249

帖子

247

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 15:40:20 | 显示全部楼层
 
Nice work:
EL +50'-6" +845 >> EL +895'-6" fine
but
EL +50.5' +845 >> +895' ??
 
help us carpenter challenged measurement guys out !!
civils don't use those dumb rulers !!
give me a hint to revise prog
Steve
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:44:59 | 显示全部楼层
I'd think you could change this:
 
(vl-string-search "'" s)
 
To this:
 
(vl-string-search "." s)
 
But, I haven't tested it and I've just started learning recently...
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-5 15:47:31 | 显示全部楼层
I'm such a retard. I was converting to an integer instead of a real.
 
Untested...
  1. (defun c:Test (/ ss ent s num) (and   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))   ((lambda (i)      (while (setq e (ssname ss (setq i (1+ i))))        (setq ent (entget e)              s   (cdr (assoc 1 ent))              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))        )        (entmod (subst (cons 1 (vl-string-subst (rtos (+ 845. (atof num))) num s))                       (assoc 1 ent)                       ent                )        )      )    )     -1   ) ) (princ))
You might have to play with the units...
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 13:04 , Processed in 0.907706 second(s), 73 queries .

© 2020-2025 乐筑天下

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