乐筑天下

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

[编程交流] 修改块属性Lisp

[复制链接]

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 10:09:29 | 显示全部楼层 |阅读模式
你好
 
一段时间前,LeeMac为我编写了一个Lisp,用于从文本文件更新块attribs。块属性是项目名称和项目编号。来自文本文件中的同一行,因此该行如下所示:
L4535 Joe Bloggs道路改善方案。因此,TAG1 attrib变为“L4535 Joe Bloggs道路改善方案”,TAG2变为“L4535”。我想修改它,使TAG1在第一个空格之后成为一切,而TAG2保持原样。我不得不自己修改它很多次,但我迷失在其中。
 
如果有人能就此停下来,我将不胜感激。
 
谢谢
 
  1. project_names : dialog { key = "dctitle";
  2. spacer;  
  3. : list_box { label = "Choose a project name:"; key = "lst";
  4.               alignment = centered; fixed_height = true;
  5.               fixed_width = true; width = 60; height = 20; }
  6. spacer;
  7. ok_cancel;
  8. }

 
  1. (defun c:project_names (/ *error* _read
  2.                       BLOCKNAME
  3.                       DCFILENAME DCFLAG DCTAG
  4.                       ELST ENT I POS PTR SS STR
  5.                       STRFILENAME STRLST TAGSTRING TAGSTRING1 TAGSTRING2
  6.                     )
  7. (vl-load-com)
  8. ;; Lee Mac  ~  01.03.10
  9. (setq dcfilename  "project_names.dcl"   ;; DCL Filename
  10.        Strfilename "CCC_NNRDO_Project_Names.txt"   ;; Data Filename
  11.        BlockName   "CCC_Project_Names"    ;; Block Name
  12.        TagString1  "TAG1"             ;; Tag String
  13.        TagString2  "TAG2"             ;; Tag String
  14.   )
  15. (defun *error* (msg)
  16.    (and dcTag (unload_dialog dcTag))
  17.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  18.        (princ (strcat "\n** Error: " msg " **")))
  19.    (princ))
  20. (defun _read (file / ofile lst nl)
  21.    (cond (  (setq ofile (open file "r"))
  22.         
  23.             (while (setq nl (read-line ofile))
  24.               (setq lst (cons nl lst)))
  25.             (close ofile)))
  26.    (reverse lst))
  27. (cond (  (not (setq i -1 ss (ssget "_X" (list (cons 0 "INSERT")
  28.                                                (cons 2 BlockName) (cons 66 1)))))
  29.           (princ (strcat "\n** No Blocks with Name: " BlockName " Found **")))
  30.        (  (not (setq Strfilename (findfile Strfilename)))
  31.           (princ "\n** Data File not Found **"))
  32.        (  (not (setq StrLst (_read Strfilename)))
  33.           (princ "\n** Data File Empty **"))
  34.        (  (<= (setq dcTag (load_dialog dcfilename)) 0)
  35.           (princ "\n** Dialog Definition Not Found **"))
  36.        (  (not (new_dialog "project_names" dcTag))
  37.           (princ "\n** Dialog Could not be Loaded **"))
  38.        (t
  39.           (start_list "lst")
  40.           (mapcar (function add_list) StrLst)
  41.           (end_list)
  42.           (setq ptr (set_tile "lst" "0"))
  43.         
  44.           (action_tile  "lst" "(setq ptr $value)")
  45.           (setq dcFlag (start_dialog))
  46.           (setq dcTag (unload_dialog dcTag) TagString1 (strcase TagString1)
  47.                                             TagString2 (strcase TagString2)
  48.                 Str   (nth (atoi ptr) StrLst))
  49.           (if (= 1 dcFlag)
  50.             (while (setq ent (ssname ss (setq i (1+ i))))
  51.               (while (not (eq "SEQEND" (cdr (assoc 0 (setq eLst (entget (setq ent (entnext ent))))))))
  52.                 (cond (  (eq TagString1 (cdr (assoc 2 eLst)))
  53.                        
  54.                          (entupd
  55.                            (cdr (assoc -1 (entmod (subst (cons 1 Str)
  56.                                                          (assoc 1 eLst) eLst))))))
  57.                       (  (and (eq TagString2 (cdr (assoc 2 eLst)))
  58.                               (setq pos (vl-string-position 32 Str)))
  59.                          (entupd
  60.                            (cdr (assoc -1 (entmod (subst (cons 1 (substr str 1 pos))
  61.                                                          (assoc 1 eLst) eLst)))))))))
  62.             (princ "\n*Cancel*"))))
  63. (princ))
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:44:35 | 显示全部楼层
那么,未经测试的修改现在已经过测试,它的工作处理。谢谢你的帮助,伊尔内布。非常感谢。
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 11:07:21 | 显示全部楼层
不客气!很高兴我能在脑海里这样做。。。意味着我的大脑还有几年的时间
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 11:26:43 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 21:01 , Processed in 0.816473 second(s), 60 queries .

© 2020-2025 乐筑天下

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