乐筑天下

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

[编程交流] 带循环和/

[复制链接]

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:48:16 | 显示全部楼层 |阅读模式
希望我能很好地解释这一点,我已经在这几个星期了。我为块属性创建了一个自动编号lisp例程,该例程具有起始值、增量、正向或反向插入顺序,因此我可以使用特定方案对块进行自动编号。我从事布线和电气系统的工作。我现在的问题是,我为需要自动编号的设备创建了新的块,但它们需要类似于X3-1的方案,其中X3是别名,-1是导线位置。我可以在导线位置上有#1-24,然后下一个块需要从X4-1开始,再次通过24。我如何向lisp中添加循环和范围来实现这一点,或者有人有其他想法吗?我们使用数百种设备,所以像我这样用手数数是不现实的。如有任何意见,我们将不胜感激。谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:55:57 | 显示全部楼层
欢迎来到CADTutor niccoleleaf
 
我的增量编号套件对你有帮助吗?
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:56:47 | 显示全部楼层
李,谢谢你的回复,顺便说一句,我是一个超级粉丝。我确实试过了,但不幸的是,它不允许我编辑现有属性,也不允许我创建范围。让我举一个我想做的事情的例子,见附件。想象一下顶部的区块,有23个,编号为C3-1到C3-24,然后下面是另一组区块,需要编号为C4-1到C4-24。该块包含属性/块,其中已包含C3-1编号,但可以编辑,因此我无法放置文本,我需要能够根据插入顺序编辑属性和编号。指块顶部的白色文本。希望这有帮助。
074821n2aaujd20o0uoocp.jpg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:01:59 | 显示全部楼层
非常感谢niccoleleaf,我很高兴你是我作品的粉丝!
我的增量编号套件程序确实提供了一个替换选项,可以在文本放置期间通过在命令行上按“R”来访问;尽管这样做不合适,但该任务可能需要专用的自定义程序。
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:07:54 | 显示全部楼层
我又玩了一些,我明白你的意思,但是,我需要在以后的修订中对它们进行批量编辑的能力,以相同的格式对所有块重新编号,而不是在插入时进行。你怎么认为?
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:09:54 | 显示全部楼层
这就是我目前用来对其他属性之一进行编号的方法,我可以放入前缀加-001,它根据插入顺序或反向插入顺序无限编号。我的最终目标是复制和修改它,使另一个例程中包含范围/循环功能,这样我就可以运行命令,选择属性,并根据我的要求生成质量数。
 
 
  1. (defun C:ATTINC()
  2. ;;;--- Get an attributes value
  3. (defun getAttData(en / enlist blkType group66 attData)
  4. ;;;--- Get the DXF group codes of the entity
  5. (setq enlist(entget en))
  6. (setq attData (list))
  7. ;;;--- Check to see if the block's attribute flag is there
  8. (if(cdr(assoc 66 enlist))
  9.    (progn
  10.         
  11.      ;;;--- Get the entity name
  12.      (setq en(entnext en))
  13.      ;;;--- Get the entity dxf group codes
  14.      (setq enlist(entget en))
  15.      ;;;--- Get the type of block
  16.      (setq blkType (cdr(assoc 0 enlist)))
  17.      ;;;--- If group 66 then there are attributes nested inside this block
  18.      (setq group66(cdr(assoc 66 enlist)))
  19.      ;;;--- Loop while the type is an attribute or a nested attribute exist
  20.      (while(or (= blkType "ATTRIB")(= group66 1))
  21.          
  22.        ;;;--- Get the block type
  23.        (setq blkType (cdr(assoc 0 enlist)))
  24.        ;;;--- Check to see if this is an attribute
  25.        (if(= blkType "ATTRIB")
  26.          ;;;--- Save the tag of the attribute
  27.          (setq attData(append attData(list (cdr(assoc 2 enlist)))))
  28.        )
  29.        ;;;--- Get the next sub-entity
  30.        (setq en(entnext en))
  31.        ;;;--- Get the dxf group codes of the next sub-entity
  32.        (setq enlist(entget en))
  33.        ;;;--- Get the block type of the next sub-entity
  34.        (setq blkType (cdr(assoc 0 enlist)))
  35.        ;;;--- See if the dxf group code 66 exist.  if so, there are more nested attributes
  36.        (setq group66(cdr(assoc 66 enlist)))
  37.      )
  38.    )
  39. )
  40. attData
  41. )
  42. ;;;--- Get an attributes value
  43. (defun replaceAtt(en tagName str / enlist blkType group66)
  44. ;;;--- Get the DXF group codes of the entity
  45. (setq enlist(entget en))
  46. ;;;--- Check to see if the block's attribute flag is there
  47. (if(cdr(assoc 66 enlist))
  48.    (progn
  49.         
  50.      ;;;--- Get the entity name
  51.      (setq en(entnext en))
  52.      ;;;--- Get the entity dxf group codes
  53.      (setq enlist(entget en))
  54.      ;;;--- Get the type of block
  55.      (setq blkType (cdr(assoc 0 enlist)))
  56.      ;;;--- If group 66 then there are attributes nested inside this block
  57.      (setq group66(cdr(assoc 66 enlist)))
  58.      ;;;--- Loop while the type is an attribute or a nested attribute exist
  59.      (while(or (= blkType "ATTRIB")(= group66 1))
  60.          
  61.        ;;;--- Get the block type
  62.        (setq blkType (cdr(assoc 0 enlist)))
  63.        ;;;--- Check to see if this is an attribute
  64.        (if(= blkType "ATTRIB")
  65.          ;;;--- If the attribute value matches....
  66.          (if(= tagName (cdr(assoc 2 enlist)))
  67.            (progn
  68.              ;;;--- Substitute the dxf group codes
  69.              (setq enlist(subst (cons 1 str)(assoc 1 enlist)enlist))
  70.              (entmod enlist)
  71.              (entupd en)
  72.            )
  73.          )
  74.        )
  75.        ;;;--- Get the next sub-entity
  76.        (setq en(entnext en))
  77.        ;;;--- Get the dxf group codes of the next sub-entity
  78.        (setq enlist(entget en))
  79.        ;;;--- Get the block type of the next sub-entity
  80.        (setq blkType (cdr(assoc 0 enlist)))
  81.        ;;;--- See if the dxf group code 66 exist.  if so, there are more nested attributes
  82.        (setq group66(cdr(assoc 66 enlist)))
  83.      )
  84.    )
  85. )
  86. )
  87. ;;;--- Function to save the dialog box settings
  88. (defun saveVars(/ index retList readlist count item)
  89. ;;;--- Save the input from the SELECTPLOTTER.dcl file
  90. (setq retList(list))
  91. (setq readlist(get_tile "attdata"))  
  92. (setq count 1)
  93. (while (setq item (read readlist))
  94.    (setq retlist(append retList (list (nth item attData))))
  95.    (while (and (/= " " (substr readlist count 1))
  96.      (/= "" (substr readlist count 1)))
  97.      (setq count (1+ count))
  98.    )
  99.    (setq readlist (substr readlist count))
  100. )
  101. (if(= retList nil)
  102.    (setq tagName nil)
  103.    (setq tagName (car retList))
  104. )
  105. (setq str(get_tile "startstr"))
  106. (setq inc(atoi(get_tile "increment")))
  107. (setq order1(atoi(get_tile "order1")))
  108. (setq order2(atoi(get_tile "order2")))
  109. )
  110. ;;;--- Function to increment a string
  111. ;;;    str = a string
  112. ;;;    inc = an integer
  113. ;;;
  114. ;;;    Examples (incStr "A100") would return "A101" if inc is set to 1
  115. ;;;             (incStr "A01")  would return "A11"  if inc is set to 10           
  116. (defun incStr(str inc)
  117. ;;;--- Set up some variable defaults
  118. (setq strPart "" numPart "" chkStr str flag T)
  119. ;;;--- While there are characters left in the string to check
  120. (while(/= chkStr "")
  121.    ;;;--- Get the last character in the string
  122.    (setq ch(substr chkStr (strlen chkStr)))
  123.    ;;;--- If the flag is clear continue on...
  124.    (if(= flag T)
  125.      (progn
  126.        ;;;--- If the character to check matches a numerical string value....
  127.        (if(member ch (list "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "."))
  128.          ;;;--- Add the numerical string value to the number portion
  129.          (setq numPart(strcat ch numPart))
  130.          ;;;--- Else set the flag to nil because the rest of the string is letters
  131.          (setq flag nil strPart chkStr)
  132.        )
  133.      )
  134.    )
  135.    ;;;--- Drop the last character off the string
  136.    (setq chkStr(substr chkStr 1 (- (strlen chkStr) 1)))
  137. )
  138. ;;;--- See how many characters make up the numerical string portion
  139. (setq numLen(strlen numPart))
  140. ;;;--- Convert the numerical to a string, add the increment, and convert back to a string
  141. (setq numStr (itoa(+ (atoi numPart) inc)))
  142. ;;;--- If the converted string is less characters than the original, prefix with zeros
  143. (while(< (strlen numStr) numLen)
  144.    (setq numStr(strcat "0" numStr))
  145. )
  146. ;;;--- Put the string back together
  147. (setq str(strcat strPart numStr))
  148. )
  149. ;;;--- Main application
  150. ;;;--- Let the user select the block
  151. (if(setq ent(entsel "\n Select Block: "))
  152.    (progn
  153.      ;;;--- Get the entity name from the entity selection
  154.      (setq en(car ent))
  155.      ;;;--- Get the dxf group codes of the entity
  156.      (setq enlist(entget en))
  157.      ;;;--- Make sure this is a block entity
  158.      (if(= "INSERT" (cdr(assoc 0 enlist)))
  159.        (progn
  160.          ;;;--- Get the name of the block
  161.          (setq blkName(cdr(assoc 2 enlist)))
  162.          ;;;--- If attribute information is found in the block
  163.          (if(setq attData(getAttData en))
  164.            (progn
  165.              ;;;--- Put up the dialog box
  166.              (setq dcl_id (load_dialog "ATTINC.dcl"))
  167.              ;;;--- Make sure the DCL file loaded
  168.              (if (not (new_dialog "ATTINC" dcl_id))
  169.                (progn
  170.                  (alert "Could not find the ATTINC.DCL file!")
  171.                  (exit)
  172.                )
  173.              )
  174.              ;;;--- Add the list to the dialog box
  175.              (start_list "attdata" 3)
  176.              (mapcar 'add_list attData)
  177.              (end_list)
  178.              ;;;--- Set a default selection
  179.              (set_tile "attdata" "0")
  180.              ;;;--- If an action event occurs, do this...
  181.              (action_tile "okay"  "(saveVars)(setq ddiag 1)(done_dialog)")
  182.              (action_tile "cancel"  "(setq ddiag 2)(done_dialog)")
  183.              ;;;--- Display the dialog box
  184.              (start_dialog)
  185.              ;;;-- Unload the dialog box
  186.              (unload_dialog dcl_id)
  187.              ;;;--- Start the routine
  188.              (if(= ddiag 1)
  189.                (progn
  190.                  ;;;--- Display a message
  191.                  (princ "\n Gathering all blocks named ")(princ blkName) (princ " .....")
  192.                  ;;;--- Get the blocks
  193.                  (if(setq eset(ssget "X" (list (cons 0 "INSERT")(cons 2 blkName))))
  194.                    (progn
  195.                      (princ "\n Manipulating data .....")
  196.                      ;;;--- While entities exist in the selection set...
  197.                      (while (> (sslength eset) 0)
  198.                        ;;;--- If insertion order is to be used...
  199.                        (if(= order1 1)
  200.                          ;;;--- Get the first entity in the selection set
  201.                          (setq en(ssname eset 0))
  202.                          ;;;--- Else use reverse order and get the last entity in the selection set
  203.                          (setq en(ssname eset (- (sslength eset)1)))
  204.                        )
  205.                        ;;;--- Replace the value of the tag
  206.                        (replaceAtt en tagName str)
  207.                        ;;;--- Increment the value for the next attribute                  
  208.                        (setq str(incStr str inc))                        
  209.                         
  210.                        ;;;--- Remove the entity from the selection set
  211.                        (ssdel en eset)
  212.                      )
  213.                    )
  214.                  )
  215.                )
  216.              )
  217.            )
  218.            (alert "The block selected does not contain attributes!")
  219.          )
  220.        )
  221.        (alert "The entity selected is not a block!")
  222.      )     
  223.      
  224.    )
  225.    (alert "No block selected!")
  226. )
  227. (princ)
  228. )

_____________________________________
 
地址:
  1. ATTINC : dialog {
  2.         label = "AttInc";
  3.         : column {
  4.           : column {
  5.             : list_box{
  6.               label ="Select Tag Name";
  7.               key = "attdata";
  8.               height = 15;
  9.               width = 45;
  10.               multiple_select = false;
  11.               fixed_width_font = false;
  12.             }
  13.           }
  14.           : column {
  15.             : edit_box  {
  16.               key = "startstr";
  17.               label = "Start Value:";
  18.               edit_width = 8;
  19.               value  = "A001";
  20.             }
  21.             : edit_box  {
  22.               key = "increment";
  23.               label = "Increment:";
  24.               edit_width = 8;
  25.               value  = "1";
  26.             }
  27.             : radio_button {
  28.               label = "Insertion order";
  29.               key = "order1";
  30.               value  = "0";
  31.             }
  32.             : radio_button {
  33.               label = "Reverse insertion order";
  34.               key = "order2";
  35.               value = "1";
  36.             }
  37.           }
  38.           : column {
  39.             : boxed_row {
  40.               : button {
  41.                 key = "okay";
  42.                 label = "Okay";
  43.                 is_default = true;
  44.               }
  45.               : button {
  46.                 key = "cancel";
  47.                 label = "Exit";
  48.                 is_default = false;
  49.                 is_cancel = true;
  50.               }
  51.             }
  52.           }
  53.         }
  54. }

 
 
再次感谢
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 07:15:25 | 显示全部楼层
 
X1-1之前是什么,如果我理解的话,你可以在X24-24之后有别名X25-1,或者我错了,在X24-24之后和X1-1之前应该是Y1-1,W24-24。。。首先,A1-1之前是什么(我想没有什么-这是起始字符串)。。。
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:17:52 | 显示全部楼层
 
你是对的,X25-1将在X24-24之后,后缀是唯一一个范围限制高达24的东西。A1-1之前不会出现任何东西,A1表示第一个设备
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-6 07:22:39 | 显示全部楼层
我想你没有完全理解我。。。你什么时候更改别名-在什么数字X之后-24来Y1-1?
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:26:38 | 显示全部楼层
实际上,你根本不需要更改字母,设备的约定是提前制定的,将一直使用,因此如果它从B1-1开始,每个约定都将是Bx xx
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 15:13 , Processed in 0.595599 second(s), 74 queries .

© 2020-2025 乐筑天下

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