乐筑天下

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

[编程交流] 布局处理

[复制链接]

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 06:40:48 | 显示全部楼层 |阅读模式
你好
我正在做一个项目,它有49个布局,它们的名字都是这样的:
01, 02, 03, 04, 05 ... 48, 49.
问题是:我不得不删除布局6,不幸的是,我应该逐个重命名所有层。
我试着编一个代码,但对我来说很困惑。。。
这是开始,我得到了一个所有层名称的列表。
  1. (setq acadApp (vlax-get-Acad-object))
  2. (setq acadDoc (vla-get-ActiveDocument acadApp))
  3. (setq layouts (vla-get-Layouts acadDoc))
  4. (vlax-for objLayout layouts
  5. (if (not(=(vla-get-name objLayout) "Model"))
  6. (setq laylist (cons(vla-get-name objLayout) laylist))
  7. )
  8. (setq laylist (reverse laylist))

这很烦人,因为我需要在数字中加0,比如
  1. (if (< numero 10)
  2.         (progn
  3.         (setq numero (strcat "0" (itoa numero)))
  4.         (command "_layout" "d" numero)
  5.         )
  6.         (progn
  7.         (setq numero (itoa numero))
  8.         (command "_layout" "d" numero)
  9.         )
  10. )

请,谁来帮帮我):
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:52:09 | 显示全部楼层
我建议如下:
  1. ([color=BLUE]defun[/color] c:renlay ( [color=BLUE]/[/color] layouts order )
  2.    
  3.    [color=GREEN];; Layouts Collection[/color]
  4.    ([color=BLUE]setq[/color] layouts ([color=BLUE]vla-get-layouts[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))))
  5.    [color=GREEN];; Temporarily rename layouts to reduce risk of duplication when renumbering[/color]
  6.    ([color=BLUE]vlax-for[/color] layout layouts
  7.        ([color=BLUE]if[/color] ([color=BLUE]/=[/color] [color=MAROON]"MODEL"[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-name[/color] layout)))
  8.            ([color=BLUE]vla-put-name[/color] layout ([color=BLUE]vla-get-handle[/color] layout))
  9.        )
  10.    )
  11.    [color=GREEN];; Renumber layouts[/color]
  12.    ([color=BLUE]vlax-for[/color] layout layouts
  13.        ([color=BLUE]if[/color] ([color=BLUE]/=[/color] [color=MAROON]"MODEL"[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-name[/color] layout)))
  14.            ([color=BLUE]vla-put-name[/color] layout
  15.                ([color=BLUE]if[/color] ([color=BLUE]<[/color] ([color=BLUE]setq[/color] order ([color=BLUE]vla-get-taborder[/color] layout)) 10)
  16.                    ([color=BLUE]strcat[/color] [color=MAROON]"0"[/color] ([color=BLUE]itoa[/color] order))
  17.                    ([color=BLUE]itoa[/color] order)
  18.                )
  19.            )
  20.        )
  21.    )
  22.    [color=GREEN];; We were never here...[/color]
  23.    ([color=BLUE]princ[/color])
  24. )
  25. ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

 
也可以先加载getval
  1. ; change the 410 to layout name
  2. ;;-------------------=={ Parse Numbers }==--------------------;;
  3. ;;                                                            ;;
  4. ;;  Parses a list of numerical values from a supplied string. ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee Mac, Copyright © 2011 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url]       ;;
  7. ;;------------------------------------------------------------;;
  8. ;;  Arguments:                                                ;;
  9. ;;  s - String to process                                     ;;
  10. ;;------------------------------------------------------------;;
  11. ;;  Returns:  List of numerical values found in string.       ;;
  12. ;;------------------------------------------------------------;;
  13. (defun LM:ParseNumbers ( s )
  14. (
  15.    (lambda ( l )
  16.      (read
  17.        (strcat "("
  18.          (vl-list->string
  19.            (mapcar
  20.              (function
  21.                (lambda ( a b c )
  22.                  (if
  23.                    (or
  24.                      (< 47 b 58)
  25.                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
  26.                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
  27.                    )
  28.                    b 32
  29.                  )
  30.                )
  31.              )
  32.              (cons nil l) l (append (cdr l) (list nil))
  33.            )
  34.          )
  35.          ")"
  36.        )
  37.      )
  38.    )
  39.    (vl-string->list s)
  40. )
  41. )
  42. (defun getline1-2 ()
  43. (if (= tabname (nth 0 plotabs))
  44.    (progn
  45.      (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
  46.        (if (= oldtag6 (strcase (vla-get-tagstring att)))
  47.        (setq newstr6 (vla-get-textstring att))
  48.        )
  49.      )
  50.    
  51.      (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
  52.        (if (= oldtag7 (strcase (vla-get-tagstring att)))
  53.        (setq newstr7 (vla-get-textstring att))
  54.        )
  55.      )
  56.    )
  57. )
  58. )
  59. ;(defun ah:sheetupdate1 (ss1 lay plotabs tabname dwgname)
  60. (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  61. (vlax-for lay (vla-get-Layouts doc)
  62. (setq plotabs (cons (vla-get-name lay) plotabs))
  63. )
  64. (setq plotabs (vl-sort plotabs '<))
  65. (setq len (length plotabs))
  66. (getline1-2) ; gets line 1&2 if not needed
  67. (setq title "Please enter dwg number")
  68. (setq width "   edit_width = 15;")
  69. (setq limit "     edit_limit = 12;")
  70. (ah:getval title width limit)
  71. (setq dwgname item)
  72. (setq TITLE "Please enter version for all sheets <Cr> no change ")
  73. (setq width "   edit_width = 8;")
  74. (setq limit "     edit_limit = 5;")
  75. (ah:getval title width limit)
  76. (setq NEWSTR4 item)
  77. (setq TITLE "Do you want to use line 1 on all sheets OK no change any key for y")
  78. (setq width "   edit_width = 6;")
  79. (setq limit "     edit_limit = 3;")
  80. (ah:getval title width limit)
  81. (if (= item nil)
  82. (setq NEWSTR6 nil)
  83. (setq NEWSTR6yn "y")
  84. )
  85. (setq TITLE "Do you want to use line 2 on all sheets OK no change any key for y")
  86. (setq width "   edit_width = 6;")
  87. (setq limit "     edit_limit = 3;")
  88. (ah:getval title width limit)
  89. (if (= item nil)
  90. (setq NEWSTR7 nil)
  91. (setq NEWSTR7yn "y")
  92. )
  93. (setq x 0)
  94. (setq bname "DA1DRTXT")
  95. (repeat len
  96. (setq tabname (nth x plotabs))
  97. (if (/= tabname "Model")
  98.    (progn
  99.      (setvar "ctab" tabname)
  100.      (setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
  101.      (setq dwgnum (Lm:parsenumbers tabname))
  102.      (setq sheetnum (car dwgnum))
  103.      (setq oldtag1 "SHT_NO") ;attribute tag name
  104.      (setq newstr1 (rtos sheetnum 2 0))
  105.      (setq oldtag2 "DRG_NO") ;attribute tag name
  106.      (setq oldtag3 "PROJ_NO") ;attribute tag name
  107.      (setq newstr3 dwgname)
  108.      (setq oldtag4 "REV_NO") ;attribute tag name
  109.      (setq oldtag6 "PROJECT_TITLE")
  110.      (setq oldtag7 "PROJECT_DESCRIPTION")
  111.      (getline1-2) ; gets line 1&2 if not needed
  112. ; if less than 10
  113.    (if (< (car dwgnum) 10.0)
  114.      (setq newstr2 (strcat dwgname "-D0"  (rtos sheetnum 2 0)))
  115.      (setq newstr2 (strcat dwgname "-D"  (rtos sheetnum 2 0)))
  116.    )
  117.      (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
  118.        (if (= oldtag1 (strcase (vla-get-tagstring att)))
  119.        (vla-put-textstring att newstr1)
  120.        ) ; end if
  121.        (if (= oldtag2 (strcase (vla-get-tagstring att)))
  122.        (vla-put-textstring att newstr2)
  123.        ) ; end if
  124.        (if (= oldtag3 (strcase (vla-get-tagstring att)))
  125.        (vla-put-textstring att newstr3)
  126.        ) ; end if
  127.        (if (and (/= version nil) (= oldtag4 (strcase (vla-get-tagstring att))) )
  128.        (vla-put-textstring att newstr4)
  129.        ) ; end if
  130.        (if (and (/= newstr6yn "Y") (= oldtag6 (strcase (vla-get-tagstring att))) )
  131.        (vla-put-textstring att newstr6)
  132.        ) ; end if
  133.        (if (and (/= newstr7yn "Y") (= oldtag7 (strcase (vla-get-tagstring att))) )
  134.        (vla-put-textstring att newstr7)
  135.        ) ; end if
  136.       ) ; end foreach
  137.    ) ; end progn
  138. ) ; end if
  139. (setq x (+ x 1))
  140. ) ; end repeat
  141. (setq ss1 nil)  
  142. (setq plotabs nil)
  143. ; end defun ah
  144. (princ)
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 07:02:55 | 显示全部楼层
非常好,谢谢你们(:
现在我正在搜索如何在布局中选择块。。。
  1. ;; Input  Dialog box with variable title
  2. ;; By Ah June 2012
  3. ;; code (ah:getval title)
  4. (defun AH:Getval (title width limit / fo)
  5. (setq fname "C://acadtemp//getval.dcl")
  6. (setq fo (open fname "w"))
  7. (write-line "ddgetval : dialog {" fo)
  8. (write-line " : row {" fo)
  9. (write-line ": edit_box {" fo)
  10. (write-line (strcat "    key = "  (chr 34) "sizze" (chr 34) ";") fo)
  11. (write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
  12. ; these can be replaced with shorter value etc
  13. ;(write-line "     edit_width = 18;" fo)
  14. ;(write-line "     edit_limit = 15;" fo)
  15. (write-line width fo)
  16. (write-line limit fo)
  17. (write-line "   is_enabled = true;" fo)        
  18. (write-line "    }" fo)
  19. (write-line "  }" fo)
  20. (write-line "ok_cancel;}" fo)
  21. (close fo)
  22. (setq dcl_id (load_dialog  "c:\\acadtemp\\getval"))
  23. (if (not (new_dialog "ddgetval" dcl_id))
  24. (exit))
  25. (action_tile "sizze" "(setq item  $value)(done_dialog)")
  26. (mode_tile "sizze" 3)
  27. (start_dialog)
  28. ; returns the value of item
  29. )

有更简单的方法吗?
  1. (setq ss (ssget "x" '((0 . "INSERT")(2 . "CARIMBO")(410 . LAYOUTNAME))))
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 07:20:14 | 显示全部楼层
在选择块时使用这种过滤器是可以的。。。
但是当我需要选择文本时,它不起作用。
我试着做这样的事情:
  1. (setq ssfilter (list (cons 0 "INSERT")(cons 2 "CARIMBO")(cons 410 layname)))
  2. (setq ss (ssget "x" ssfilter))

但这需要太长时间,我的意思是,有48个布局,计算机运行太慢/
有没有其他方法,每次都不改变布局?
它看起来像:
  1. (setq pt1 '(989.303 304.802))
  2. (setq pt2 '(1150.43 116.243))
  3. (foreach y (layoutlist)
  4. (setvar 'ctab y)
  5. (setq ss (ssget "W" pt1 pt2 '((0 . "TEXT"))))
  6. ;some codding here
  7. )
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 07:24:23 | 显示全部楼层
 
当使用图形ssget选择方法(例如窗口/交叉/多边形)时,则不适用,因为要选择的对象必须在屏幕上可见;但是,当使用ssget“X”模式在图形数据库上迭代时,可以在ssget过滤器列表中包括DXF组410的过滤器,例如:
 
  1. (command "layout" "s" layout)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:38:09 | 显示全部楼层
嗯,
多么卑鄙):
 
感谢您的帮助(:
回复

使用道具 举报

9

主题

71

帖子

62

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 07:48:54 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 15:17 , Processed in 1.660393 second(s), 66 queries .

© 2020-2025 乐筑天下

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