乐筑天下

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

[编程交流] * (astrix) dose not work in li

[复制链接]

12

主题

21

帖子

9

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 11:41:04 | 显示全部楼层 |阅读模式
Hi,
 
We need to rename all incoming layers, to achieve this I had devised the next lisp:
 
CODE STARTS HERE
 
(Command "rename" "La" "*" "(IMPORTED)*")
 
CODE ENDS HERE
 
However I cannot get the astrix to select all the old layers.
 
Dose anyone know the solution to this???
回复

使用道具 举报

10

主题

8258

帖子

8335

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 11:50:10 | 显示全部楼层
It appears it doesn't work at the command line either (returns the prompt Invalid layer name).
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 11:55:34 | 显示全部楼层
This may help you:
 
  1. (defun AddPrefixToLayerNames( thePrefix / LayerEntry LayerAssocList )(setq LayerEntry (cdr (assoc 2 (tblnext "LAYER" 1))))(while LayerEntry (setq LayerAssocList (entget (tblobjname "LAYER" LayerEntry))) (if (/= LayerEntry "0")  (progn   (setq LayerAssocList (subst (cons '2 (strcat thePrefix LayerEntry))                               (assoc 2 LayerAssocList)                               LayerAssocList))   (entmod LayerAssocList)  ) ) (setq LayerEntry (cdr (assoc 2 (tblnext "LAYER")))))(princ))
 
Use it:
  1. (AddPrefixToLayerNames "MyPrefixString")
 
Regards,
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:00:34 | 显示全部楼层
 
You will need a fairly complex routine to do what you're asking for.  You will have to deal with locked layers, nested block entities layers, etc.  Sorry -David
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 12:03:30 | 显示全部楼层
Give this a try...
 
  1. ;;; Add Prefix and/or Suffix to all layers (excluding 0, Defpoints and XRef layers;;; #Prefix - Prefix string to append to layer names (nil for nothing);;; #Suffix - Suffix string to append to layer names (nil for nothing);;; Alan J. Thompson, 02.16.10(defun LayerPrefixSuffix (#Prefix #Suffix / #Prefix #Suffix) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (and   (or (and (not #Prefix) (setq #Prefix "")) (snvalid #Prefix) (setq #Prefix ""))   (or (and (not #Suffix) (setq #Suffix "")) (snvalid #Suffix) (setq #Suffix ""))   (progn     (vlax-for x (vla-get-layers *AcadDoc*)       (or (wcmatch (strcase (vla-get-name x)) "*|*,0,DEFPOINTS")           (vl-catch-all-apply 'vla-put-name (list x (strcat #Prefix (vla-get-name x) #Suffix)))       ) ;_ or     ) ;_ vlax-for     T   ) ;_ progn ) ;_ and) ;_ defun
 
Example:
  1. (LayerPrefixSuffix "Begin-" "-End")
 
 
It will allow you to add a prefix and/or a suffix. Works on locked layers and ignores the 0, Defpoints and XRef layers.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 12:12:11 | 显示全部楼层
OH yeah, don't forget (vl-load-com) if you don't have it loaded.
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 12:16:50 | 显示全部楼层
Also, here's one I wrote to rename a layer...
 
  1. ;;; Rename layer;;; #OldName - Layer to rename;;; #NewName - New name for layer;;; Returns T if successful, nil if not;;; Alan J. Thompson, 10.07.09(defun AT:LayerRename (#OldName #NewName) (and (tblsearch "layer" #OldName)      (not (tblsearch "layer" #NewName))      (snvalid #NewName)      (or *AcadDoc*          (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))      ) ;_ or      (not (vl-catch-all-error-p             (vl-catch-all-apply               'vla-put-name               (list (vla-item (vla-get-layers *AcadDoc*) #OldName) #NewName)             ) ;_ vl-catch-all-apply           ) ;_ vl-catch-all-error-p      ) ;_ not ) ;_ and) ;_ defun
回复

使用道具 举报

12

主题

21

帖子

9

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 12:23:34 | 显示全部楼层
lol fixed this successfully in another forum with the following code
 
CODE STARTS HERE
 
(vlax-for layer (vla-get-Layers
                    (vla-get-ActiveDocument
                      (vlax-get-acad-object)
                    )
                  )
  (setq ln (vla-get-name layer))
  (if (not (or (= ln "0") (= ln "Defpoints")))
  (vla-put-name layer (strcat "(IMPORTED) " ln))
    )
  )
 
CODE ENDS HERE
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:26:23 | 显示全部楼层
Why not enclose your code in
  1. tags or see here: 
  2. http://www.cadtutor.net/forum/showthread.php?t=9184
  3.  
  4. Nobody seems to read the sticky...
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 12:35:31 | 显示全部楼层
Well, I suppose as long as you're happy.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:32 , Processed in 0.333049 second(s), 72 queries .

© 2020-2025 乐筑天下

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