乐筑天下

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

[编程交流] New Text Style by Layer(s) fro

[复制链接]

15

主题

68

帖子

53

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-5 18:34:37 | 显示全部楼层 |阅读模式
I ask for help from the masters to create a routine that would help me a lot.
I have this old code that changes the text style of all text on a layer.
I don't want to get stuck to the code and would like to get the data from a TXT file like this:
 
Materials.txt
SPT__STEEL;ST80
SPT__WOOD;ST100
SPT__PLAST;ST120
SPT__ALUMIN;ST100
 
e.g.
(NTSL "ST80" "SPT__STEEL")
(NTSL "ST100" "SPT__WOOD,SPT__ALUMIN")
(NTSL "ST120" "SPT__PLAST")
 
Can someone help me?
Thanks in advance.
 
  1. ;;use (NTSL "TEXTSTYLE" "LAYERNAME1,LAYERNAME2,...") (defun NTSL (style layers / textss tent tdata) (if (tblsearch "style" style)   (progn ; then     (command "_.layer" "_unlock" layers "")     (if (setq textss (ssget "_X" (list '(0 . "TEXT") (cons 8 layers))))       (repeat (sslength textss); then         (setq tent (ssname textss 0)               tdata (entget tent)               tdata (subst (cons 7 style) (assoc 7 tdata) tdata)         ); end setq         (entmod tdata)         (ssdel tent textss)       ); end repeat       (alert "No Text on specified Layer[s]."); else     ); end if     (command "_.layerp")   ); end progn   (alert "No such Text Style in this drawing."); else ); end if (princ)); end defun
Materials.txt
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 18:41:13 | 显示全部楼层
Sorry had to leave my pc (wife grr)
 
question, your materials.txt has for every line 1 layer and 1 style and your routine 1 style and a string of more layers. If I were to process the txt file I would do something like (1 style , 1 layer)
 
  1. (defun c:sts ( / fp inp layers stl) (if (setq fp (open (findfile "materials.txt") "r"))   (while (setq inp (read-line fp))     (setq inp (SplitStr inp) ";")     (NTSL (last inp) (car inp)))))(defun SplitStr ( s d / p ) (if (setq p (vl-string-search d s)) (cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s)))
 
gr. Rlx
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 18:51:04 | 显示全部楼层
Try this function to retrieve un-repeated name of (Layer . Style) then you can use your function on the return list from my codes below.
 
  1. (defun Filter:Layer:Style (/ f o str pos lay sty lst) ;; Tharwat 28.09.2015    ;; (if   (and (setq          f (getfiled "Select txt file :" (getvar 'DWGPREFIX) "txt" 16)        )        (setq o (open f "r"))   )    (progn      (while (and (setq str (read-line o))                  (setq pos (vl-string-search ";" str))                  (tblsearch "LAYER" (setq lay (substr str 1 pos)))                  (tblsearch "STYLE" (setq sty (substr str (+ 2 pos))))             )        (if (not (vl-some '(lambda (a)                             (and (= lay (car a)) (= sty (cadr a)))                           )                          lst                 )            )          (setq lst (cons (list lay sty) lst))        )      )      (close o)    ) ) lst)
回复

使用道具 举报

15

主题

68

帖子

53

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-5 18:56:48 | 显示全部楼层
  1. question, your materials.txt has for every line 1 layer and 1 style and your routine 1 style and a string of more layers. If I were to process the txt file I would do something like (1 style , 1 layer)
Hi rlx, thanks for your reply.
Your code return "syntax error".
About your question, it may have the same textstyle for several different layers.
回复

使用道具 举报

15

主题

68

帖子

53

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-5 19:01:19 | 显示全部楼层
  1. Try this function to retrieve un-repeated name of (Layer . Style) then you can use your function on the return list from my codes below.
Thanks Tharwat.
You always rescues me. ;-)
 
Your code returns the list I need.
  1. Command: (Filter: Layer: Style)(("SPT__STEEL" "ST80") ("SPT__WOOD" "ST100") ("SPT__ALUMIN" "ST100") ("SPT__PLAST" "ST120"))
 
As I capture each item to use the function (NTSL)?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 19:07:14 | 显示全部楼层
 
You're welcome
 
I don't have a drawing that contains the name of layers and styles return from the txt file , so I DIDN'T tested t the following program.
 
Try it and let me know.
 
  1. (defun c:test (/ f o str pos lay sty lst sel i en l) ;; Tharwat 29.09.2015    ;; (if   (and (setq          f (getfiled "Select txt file :" (getvar 'dwgprefix) "txt" 16)        )        (setq o (open f "r"))   )    (progn      (while (and (setq str (read-line o))                  (setq pos (vl-string-search ";" str))                  (tblsearch "LAYER" (setq lay (substr str 1 pos)))                  (tblsearch "STYLE" (setq sty (substr str (+ 2 pos))))             )        (if (not (vl-some '(lambda (a)                             (and (= lay (car a)) (= sty (cadr a)))                           )                          lst                 )            )          (setq lst (cons (list lay sty) lst))        )      )      (close o)      (if (and lst               (setq                 sel                  (ssget                    "_X"                    (list                      '(0 . "TEXT")                      (cons                        8                        (substr                          (apply 'strcat                                 (mapcar '(lambda (x) (strcat "," (car x)))                                         lst                                 )                          )                          2                        )                      )                    )                  )               )          )        (repeat (setq i (sslength sel))          (setq en (entget (ssname sel (setq i (1- i)))))          (if            (vl-some              '(lambda (x)                 (and                   (eq (strcase (cdr (assoc 8 en))) (strcase (car x)))                   (setq l x)                 )               )              lst            )             (entmod (subst (cons 7 (cadr l)) (assoc 7 en) en))          )        )        (alert "No Text on specified Layer[s].")      )    ) ) (princ))
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 19:10:45 | 显示全部楼层
 
 
oops... (setq inp (SplitStr inp) ";") should be (setq inp (SplitStr inp ";"))
 
 
But Tharwat's way of first building an index is the way to go (me just being lazy you know cause couldn't concentrate with wife babbeling... ;-)
 
 
gr.Rlx
回复

使用道具 举报

15

主题

68

帖子

53

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-5 19:17:24 | 显示全部楼层
 
Hi Tharwat,
The code does not change the textstyles as the TXT file.
Attached model.
Thank you.
Materials.dwg
Materials.txt
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 19:26:51 | 显示全部楼层
 
Sorry , actually there were two mistakes. The first one is a misplaced bracket , and the second one is that I considered the first one as layer name .
 
I just updated the codes above , so try it now.
回复

使用道具 举报

15

主题

68

帖子

53

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-5 19:29:21 | 显示全部楼层
 
PERFECT!
Thank you very much for helping me again.
Best wishes. :-)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 13:34 , Processed in 0.471556 second(s), 72 queries .

© 2020-2025 乐筑天下

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