乐筑天下

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

[编程交流] Modify current routine-block a

[复制链接]

8

主题

1647

帖子

1647

银币

初来乍到

Rank: 1

铜币
36
发表于 2022-7-6 11:32:47 | 显示全部楼层 |阅读模式
Ok guys, I've got a routine that I've been using for about 4 years. I can't remember who wrote it for me, it might have been CAB, but I need some extra functionality added to it.
 
This may be a little difficult to explain, but here's some background on the routine and why I need it to do what it does and why I need it modified. I design cemeteries, which sometimes involves laying out a field of grave spaces. These spaces are generally placed into blocks of 4 or 8 or 16 or whatever. Each block has an attribute block number and each space has an attribute text string indicating space number and block number.
 
So for example, I have a block of 4 grave spaces and the block is number 100. The number 100 is an attribute. Each individual space within the block is numbered with plain text 1, 2, 3 & 4, (This text does not need to change). Each individual space also has an attribute string indicating the block number and space number like this: 100-1, 100-2, 100-3 & 100-4.
 
So, whenever we need to renumber a field of blocks, all attributes within each block needs to update at once. So if block number 100 needs to be changed to 101, then the attribute strings also need to update to 101-1, 101-2, 101-3 & 101-4. My routine does this perfectly, but the problem is that I have to initiate the command, type in the new number and select the block to update. Then I have to repeat the process again and again and again for every block on the map. Not only is this tedious and time consuming, but it leaves room for error if I happen to type in the wrong number, which I have been known to do from time to time.
 
What I would like the routine to do is:
1. Ask me for the starting block number
2. Allow me to select the block to update
3. Update attributes as described above
4. Loop and increment +1
5. Allow me to select the next block to update
6. Update attributes as described above
7. Continue looping, incrementing and updating until I end the routine
 
Can one of you guys please take a look at the attached code and see if you can modify it to make this happen? It would save hours of tedious re-numbering. I have also included a dwg for you to run tests on.
 
If this explanation was confusing, let me know.  Thanks in advance.
 
  1. ;;;;Routine to modify all attributed crypt space numbers within a block simultaneously;;(defun c:AM (/ ss BlkObj tmpStr pos val) (vl-load-com) (or *prefix* (setq *prefix* "100")) (setq val (getstring (strcat "\nInput New *prefix*: : "))) (if (or (null val) (= val ""))   (setq val *prefix*)   (setq *prefix* val) ) (princ "\nSelect Block to update...") ; only blocks with attributes (if (setq ss (ssget ":S" (list (cons 0 "INSERT") '(66 . 1))))   (progn     (setq BlkObj (vlax-ename->vla-object (ssname ss 0)))     (foreach attrib (vlax-safearray->list (variant-value (vla-getattributes BlkObj)))       (setq tmpStr (vla-get-textstring attrib)             pos (vl-string-position 45 tmpStr) ; find the "-"       )       (if pos         (progn           (setq tmpStr (vl-string-subst *prefix* (substr tmpStr 1 pos) tmpStr))           (vla-put-textstring attrib tmpStr)         )         (vla-put-textstring attrib *prefix*)       )     )   ) ) (princ))(prompt "\nAttribute Updater loaded, Enter AM to run.")(princ)
LC-4.dwg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:37:59 | 显示全部楼层
I may have misunderstood, but was it something like this you were looking for?
 
  1. (defun c:AttInc (/ ss att str pos) (vl-load-com) (or *start (setq *start 100)) (setq *start (cond ((getint (strcat "\nSpecify Starting Number  : ")))                    (*start))) (princ "\nSelect Block to Increment: ") (while (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))   (foreach att (vlax-invoke                  (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)          (setq str (vla-get-TextString att))     (vla-put-TextString att       (if (setq pos (vl-string-position 45 str))         (strcat (itoa *start) (substr str (1+ pos)))         (itoa *start))))      (setq *start (1+ *start))) (princ))
回复

使用道具 举报

8

主题

1647

帖子

1647

银币

初来乍到

Rank: 1

铜币
36
发表于 2022-7-6 11:40:35 | 显示全部楼层
Thanks Lee, damn you're quick!  That's close but not quite. Your routine is only updating the individual space attribute strings. It needs to update the block number attribute as well.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:44:09 | 显示全部楼层
Just spotted that! Updated.
回复

使用道具 举报

8

主题

1647

帖子

1647

银币

初来乍到

Rank: 1

铜币
36
发表于 2022-7-6 11:47:10 | 显示全部楼层
Oh man, that's perfect! Thank you so much. This will make life much easier.
 
Thanks again.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:51:14 | 显示全部楼层
You're welcome Rod
回复

使用道具 举报

8

主题

1647

帖子

1647

银币

初来乍到

Rank: 1

铜币
36
发表于 2022-7-6 11:52:08 | 显示全部楼层
Hey Lee, I just discovered a small issue with the routine. Whenever I have a number smaller than 10 and I try to type in something like 06, it only displays 6. It discards the zero. I would like for it to display the zero in front of the number. Is there a way to make this happen?
 
Thanks
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:57:09 | 显示全部楼层
Hi Rod,
 
Yes, the issue arises as the program uses getint to retrieve an integer, and '06' is recognised as just '6'. To get around this issue I can use a string prompt, and convert it.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 11:58:25 | 显示全部楼层
What about this (untested)? I hope you don't mind Lee.
 
  1. (defun c:AttInc (/ _Fix ss att str pos) (vl-load-com) (setq _Fix (lambda (x)              (if (< *start 10)                (strcat "0" (itoa *start))                (itoa *start)              ) ;_ if            ) ;_ lambda ) ;_ setq (or *start (setq *start 100)) (setq *start (cond ((getint (strcat "\nSpecify Starting Number  : ")))                    (*start)              ) ;_ cond ) ;_ setq (princ "\nSelect Block to Increment: ") (while (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))   (foreach att (vlax-invoke                  (vlax-ename->vla-object (ssname ss 0))                  'GetAttributes                ) ;_ vlax-invoke     (setq str (vla-get-TextString att))     (vla-put-TextString       att       (if (setq pos (vl-string-position 45 str))         (strcat (_Fix *start) (substr str (1+ pos)))         (_Fix *start)       ) ;_ if     ) ;_ vla-put-TextString   ) ;_ foreach   (setq *start (1+ *start)) ) ;_ while (princ)) ;_ defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:03:55 | 显示全部楼层
Was just about to post this actually:
 
  1. (defun c:AttInc (/ MStr ss att str pos num) (vl-load-com) (setq mStr (lambda (string) (while (< (strlen string) len)                               (setq string (strcat "0" string))) string)) (or *start (setq *start "100")) (while   (not     (setq num        (distof         (setq *start           (cond ((/= "" (setq tmp (getstring (strcat "\nSpecify Starting Number  : ")))) tmp)                 (*start))))))) (setq len (strlen *start) num (fix num)) (princ "\nSelect Block to Increment: ") (while (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))   (foreach att (vlax-invoke                  (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)          (setq str  (vla-get-TextString att))          (vla-put-TextString att       (if (setq pos (vl-string-position 45 str))         (strcat (setq *start (mStr (itoa num))) (substr str (1+ pos)))         (setq *start (mStr (itoa num))))))      (setq num (1+ num))) (princ))
Updated to correct while loop.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:21 , Processed in 0.374325 second(s), 72 queries .

© 2020-2025 乐筑天下

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