乐筑天下

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

[编程交流] laymrg lisp的帮助???

[复制链接]

96

主题

322

帖子

234

银币

后起之秀

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

铜币
474
发表于 2022-7-5 22:47:17 | 显示全部楼层 |阅读模式
  1. ;;; Function to load LayMrg2 dialog
  2. (defun load_dialog_LayMrg2 (/ fn f)
  3. (setq fn (strcat (getvar "TEMPPREFIX") "LayMrg2.DCL"))
  4. (setq f (open fn "w"))
  5. (write-line "LayMrg2 : dialog {" f)
  6. (write-line "  label = "Merge Layers";" f)
  7. (write-line "  : text { key = "Label"; label = "Layers to merge:"; }" f)
  8. (write-line "  : list_box { key = "List"; height = 17; width = 50; multiple_select = true; }" f)
  9. (write-line "  ok_cancel;" f)
  10. (write-line "}" f)
  11. (close f)
  12. (load_dialog fn)
  13. ) ;_ end of defun
  14. (defun LayMrg2:GetNames (lst / dcl names enter lay)
  15. (if (and (= (getvar 'cmddia) 1)
  16.           (= (logand (getvar 'cmdactive) (+ 4 32 64)) 0)
  17.           (setq dcl (load_dialog_LayMrg2))
  18.           (new_dialog "LayMrg2" dcl)
  19.      )
  20.    (progn
  21.      (while (setq lay (tblnext "LAYER" (not lay)))
  22.        (if (wcmatch (setq enter (cdr (assoc 2 lay))) "~*|*")
  23.          (setq names (cons enter names))
  24.        )
  25.      )
  26.      (start_list "List")
  27.      (mapcar 'add_list (setq lay (acad_strlsort names)))
  28.      (end_list)
  29.      (set_tile "List" (vl-string-trim "()" (vl-princ-to-string (vl-sort (mapcar '(lambda (lay) (vl-position lay names)) lst) '<))))
  30.      (setq names nil)
  31.      (action_tile "List" "(setq names (read (strcat "(" $value ")")))")
  32.      (if (= (start_dialog) 1)
  33.        (setq names (mapcar '(lambda (n) (nth n lay)) names))
  34.        (setq names nil)
  35.      )
  36.      (unload_dialog dcl)
  37.    )
  38.    (while (setq enter (getstring t "Enter a layer name to add (Enter to stop): "))
  39.      (if (setq dcl (tblsearch "LAYER" enter))
  40.        (if (not (member (setq dcl (cdr (assoc 2 dcl))) names))
  41.          (setq names (cons dcl names))
  42.        )
  43.        (princ "That layer doesn't exist.\n")
  44.      )
  45.    )
  46. )
  47. names
  48. )
  49. ;; Layer Merge but keep color & linetype settings
  50. (defun c:LayMrg2 (/ en ed ln llst ld)
  51. (while (progn
  52.           (initget "Name")
  53.           (setq en (entsel "\nSelect object on layer to merge or [Name]: "))
  54.         ) ;_ end of progn
  55.    (if (= en "Name")
  56.      (if (setq ln (LayMrg2:GetNames llst))
  57.        (setq llst ln)
  58.        (princ "No layer selected, try again.")
  59.      )
  60.      (progn
  61.        (princ "\n")
  62.        (if (setq ed (entget (car en)))
  63.          (if (not (member (cdr (assoc 8 ed)) llst))
  64.            (setq llst (cons (cdr (assoc 8 ed)) llst))
  65.          ) ;_ end of if
  66.        ) ;_ end of if
  67.      ) ;_ end of progn
  68.    ) ;_ end of if
  69.    (princ (strcat "Selected layers: " (car llst)))
  70.    (foreach ln (cdr llst)
  71.      (princ (strcat "," ln))
  72.    ) ;_ end of foreach
  73. ) ;_ end of while
  74. (setq en (entnext)) ;Get 1st entity
  75. (while (and en (setq ed (entget en)))
  76.    (if (setq ln (member (cdr (assoc 8 ed)) llst))
  77.      (progn
  78.        (setq ld (tblsearch "LAYER" (car ln)))
  79.        ;; Color
  80.        (if (not (assoc 62 ed))
  81.          (setq ed (append ed (list (assoc 62 ld))))
  82.        )
  83.        ;; Linetype
  84.        (if (not (assoc 6 ed))
  85.          (setq ed (append ed (list (assoc 6 ld))))
  86.        )
  87.        (entmod ed)
  88.      )
  89.    )
  90.    (setq en (entnext en))
  91. )
  92. (if (and (= (getvar 'cmddia) 1)
  93.           (= (logand (getvar 'cmdactive) (+ 4 32 64)) 0)
  94.      )
  95.    (initdia)
  96. )
  97. (command "._LAYMRG")
  98. (foreach ln llst
  99.    (command "_Name" ln)
  100. ) ;_ end of foreach
  101. (command "")
  102. (while (> (getvar "CMDACTIVE") 0)
  103.    (command pause)
  104. ) ;_ end of while
  105. (princ)
  106. ) ;_ end of defun
  107. (princ)
  108. ;|«Visual LISP© Format Options»
  109. (120 2 1 2 nil "end of " 100 9 0 0 1 nil T nil T)
  110. ;*** DO NOT add text below the comment! ***|;
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 23:03:47 | 显示全部楼层
回复

使用道具 举报

96

主题

322

帖子

234

银币

后起之秀

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

铜币
474
发表于 2022-7-5 23:24:47 | 显示全部楼层
Is there any way to use LayMrg2 Command for this purpose??? or need to modify the main program??
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 23:46:14 | 显示全部楼层
 
As written, the above command does not support being called as a sub-function.
 
In order to achieve the functionality I suspect you to be after (it is a bit unclear to me; language barrier?), then you would need to code your own sub-function with the desired syntax, and properly accredit the author of the source code you culled (if applicable).
 
Cheers
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 23:48:42 | 显示全部楼层
Also this error
 
  1. (defun LayMrg2:GetNames (lst ;;;the variable lst is a list of layer names(setq lst (list "layer1" "layer2" "layer3".....)) or(LayMrg2:GetNames (list "layer1" "layer2" "layer3"..."))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 03:24 , Processed in 0.350707 second(s), 62 queries .

© 2020-2025 乐筑天下

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