乐筑天下

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

[编程交流] Duplayout LISP

[复制链接]

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 18:44:45 | 显示全部楼层 |阅读模式
你好
 
我已经使用Gile制作的Duplayout LISP有一段时间了(CADtutor论坛),但是我遗漏了两件事,我希望你们能帮我:
 
使用duplayout时,新布局的名称设置为最后一个字符串1。(即布局名称:4-25,复制x3,新布局名称:4-26,4-27,4-28),我已经在脚本中找到将字符串从1更改为X的位置(即布局名称4-25,复制x3,字符串-12,新布局名称:4-37,4-49,4-61)。如果它要求以1为基数的字符串值(就像它对要复制的布局和副本数所做的那样),那就太好了。
 
第二个问题是在第一个字符后进行更改/命名(即布局名称4-25,副本x3,新布局名称:5-25,6-25,7-25)。它还可以要求角色在后面命名(最后加上base)。要更改的字符不经常超过3个,所以它可以要求第一个、最后一个、中间个或类似的字符。如果太难,它只能要求第一个,最后一个
 
谢谢你的帮助。
 
  1. (defun c:duplayout ( /
  2.                    increment_string CustSort CustSort_Comparable CustSort_SplitStr
  3.                    oce louts flag ctab layout# layoutname newlayoutname )
  4. (vl-load-com)
  5. ;;******************************************************************
  6. ;; Local Functions
  7. ;;******************************************************************
  8. (defun increment_string (string inc / num tmp1 len check sign)
  9.    (if (/= string "");Don't process an empty string
  10.      (progn
  11.        (setq num ""
  12.              tmp1 1
  13.              )
  14.        (while (and (> (setq len (strlen string)) 0) tmp1)
  15.          (setq check (substr string len));The last character of the string
  16.          (if (wcmatch check "[0-9]");Is it a number?
  17.            (setq num (strcat check num);If yes put it aside
  18.                  string (substr string 1 (1- len));and take it off the original string
  19.                  )
  20.            (setq tmp1 nil);If no end the loop
  21.            );if
  22.          );while
  23.       
  24.        ;check for negative signage in front of the string
  25.        (if (and (> (strlen string) 0) (= (substr string 1 1) "-"))
  26.          (progn
  27.            (setq sign -1)
  28.            (if (> (strlen string) 1);more than just a negative sign
  29.              (setq string (vl-string-left-trim " " (substr string 2 (1- (strlen string)))));remove the negative sign and any spaces
  30.              (setq string "")
  31.              )
  32.            );progn
  33.          (setq sign 1)
  34.          )
  35.       
  36.       
  37.       
  38.        (setq tmp1 (+ (* (atoi num) sign) inc)
  39.              sign (if (< tmp1 0) "-" "")
  40.              tmp1 (itoa (abs tmp1))
  41.              )
  42.       
  43.        ;Then pad with zeros if the original was padded
  44.        (if (< (strlen tmp1) (strlen num))
  45.          (repeat (- (strlen num) (strlen tmp1)) (setq tmp1 (strcat "0" tmp1)));Buffer with zeros
  46.          )
  47.        (strcat sign string tmp1)
  48.        );progn
  49.      "1"
  50.      );if
  51.    )
  52. ;;******************************************************************
  53. ;;Customised string sorting function Main Part
  54. (defun CustSort ( x )
  55.    (vl-sort x (function (lambda ( x1 x2 / n1 n2 comp )
  56.                           (setq x1 (CustSort_SplitStr x1);creates a broken down list of alpha & numeric values from the string
  57.                                 x2 (CustSort_SplitStr x2);creates a broken down list of alpha & numeric values from the string
  58.                                 )
  59.                           (while
  60.                             (and
  61.                               (setq comp (CustSort_Comparable (setq n1 (car x1)) (setq n2 (car x2))))
  62.                               (= n1 n2)
  63.                               (/= n1 nil)
  64.                               )
  65.                             (setq x1 (cdr x1) x2 (cdr x2))
  66.                             );while
  67.                           (if comp (< n1 n2) (numberp n1))
  68.                           );lambda
  69.                         );function
  70.             );vl-sort
  71.    )
  72. ;*********************************************************************
  73. ;;Customised string sorting function Sub Part 1 - Tests whether the values are both strings or both numbers
  74. (defun CustSort_Comparable ( e1 e2 )
  75.    (or
  76.      (and (numberp e1) (numberp e2))
  77.      (= 'STR (type e1) (type e2))
  78.      (not e1)
  79.      (not e2)
  80.      )
  81.    )
  82. ;*********************************************************************
  83. ;;Customised string sorting function Sub Part 2 - Splits a string into a list of separated string and number parts
  84. (defun CustSort_SplitStr ( str / lst test rslt num tmp )
  85.    (setq lst  (vl-string->list str)
  86.          test (chr (car lst))
  87.          )
  88.    (if (< 47 (car lst) 58) (setq num T))
  89.    (while (setq lst (cdr lst))
  90.      (if num
  91.        (cond
  92.          ((= 46 (car lst))
  93.           (if (and (cadr lst) (setq tmp (strcat "0." (chr (cadr lst)))) (numberp (read tmp)))
  94.             (setq rslt (cons (read test) rslt) test tmp lst (cdr lst))
  95.             (setq rslt (cons (read test) rslt) test "." num nil))
  96.           );1st condition
  97.          ((< 47 (car lst) 58)
  98.           (setq test (strcat test (chr (car lst))))
  99.           );2nd condition
  100.          (T (setq rslt (cons (read test) rslt)
  101.                   test (chr (car lst))
  102.                   num  nil
  103.                   )
  104.           );3rd condition
  105.          );cond
  106.        (if (< 47 (car lst) 58)
  107.          (setq rslt (cons test rslt) test (chr (car lst)) num T)
  108.          (setq test (strcat test (chr (car lst)))));if
  109.        );if
  110.      );while
  111.    (if num (setq rslt (cons (read test) rslt)) (setq rslt (cons test rslt)))
  112.    (reverse rslt)
  113.    )
  114. ;;******************************************************************
  115. ;; Main Program Code
  116. ;;******************************************************************
  117. (setq oce (getvar "cmdecho"))
  118. (setvar "cmdecho" 0)
  119. (setq louts (layoutlist)
  120.        ctab (if (= "Model" (getvar "ctab")) (car louts) (getvar "ctab"))
  121.        flag nil
  122.        )
  123. (while (not flag)
  124.    (setq layoutname (getstring T (strcat "\nLayout to duplicate <" ctab ">: ")))
  125.    (if (= layoutname "") (setq layoutname ctab))
  126.    (if (= layoutname "Model")
  127.      (alert "Cannot duplicate Modelspace")
  128.      (if (member (strcase layoutname) (mapcar 'strcase louts)) (setq flag T))
  129.      );if
  130.    );while
  131. (initget 6)
  132. (setq layout# (getint "\nHow many copies ? <2>: "))
  133. (if (null layout#) (setq layout# 2))
  134. (setq newlayoutname layoutname
  135.        louts (mapcar 'strcase louts)
  136.        )
  137. (repeat layout#
  138.    (while (member (strcase (setq newlayoutname (increment_string newlayoutname 1))) louts))
  139.    (vl-cmdf ".layout" "copy" layoutname newlayoutname)
  140.    (setq louts (cons (strcase newlayoutname) louts))
  141.    );repeat
  142. (setq louts (CustSort louts))
  143. (vlax-for tab (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  144.    (if (not (= (strcase (vla-get-name tab)) "MODEL"))
  145.      (vla-put-taborder tab (1+ (vl-position (strcase (vla-get-name tab)) louts)))
  146.      )
  147.    )
  148. (setvar "cmdecho" oce)
  149. (princ)
  150. );defun
回复

使用道具 举报

28

主题

118

帖子

95

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
136
发表于 2022-7-5 19:36:11 | 显示全部楼层
流血,
 
我混合使用了以下内容,您可能希望探索这些内容:
 
使用类固醇重命名:
http://www.cadforum.cz/cadforum_en/rename-on-steroids-complex-renaming-of-autocad-objects-tip9265
 
在此处张贴#16(需要安装AUGI登录和AutoCAD VBA Enabler):
http://forums.augi.com/showthread.php?17630-自动重新编号布局选项卡/页面2
 
标签排序:
http://www.lee-mac.com/tabsort.html
 
 
干杯
回复

使用道具 举报

4

主题

16

帖子

12

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 19:59:59 | 显示全部楼层
@abra CAD abra
 
感谢您的回复,我有这些LISP,有时我会使用它们,但是现在我需要复制许多布局才能使用它们,所以我正在寻找更简单、更快的方法;]现在我需要复制大约120-150个布局:/
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 13:41 , Processed in 0.497384 second(s), 69 queries .

© 2020-2025 乐筑天下

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