New Text Style by Layer(s) fro
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.
;;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."); else ); end if (command "_.layerp") ); end progn (alert "No such Text Style in this drawing."); else ); end if (princ)); end defun
Materials.txt 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)
(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 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.
(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) 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. 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.
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)?
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.
(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.") ) ) ) (princ))
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
Hi Tharwat,
The code does not change the textstyles as the TXT file.
Attached model.
Thank you.
Materials.dwg
Materials.txt
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.
PERFECT!
Thank you very much for helping me again.
Best wishes. :-)
页:
[1]
2