Change Text Style Definitions

Change Text Style Definitions

CNinBC
Advocate Advocate
1,982 Views
4 Replies
Message 1 of 5

Change Text Style Definitions

CNinBC
Advocate
Advocate

Hi Everyone,

 

one of our client asks us to provide drawing in pdf format with searchable text function, we haveto swap all the text style definition(except for style "Standard" and "Roadname") to use "Arial Narrow.ttf" and change the width factor to 1.

I found a code from https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-change-text-style-font-file-..., and tried to modify it. but it comes up with error message saying " error: no function definition: nil"

I couldn't figure out what i did wrong, any suggestion? Thanks.

 

(defun c:txt2ttf (/ DOC FNTPTH STY )
  (vl-load-com)
  (setq	doc (vla-get-activedocument
	      (vlax-get-acad-object)
	    )
  )
  (setq FntPth (findfile "C:\\Windows\\Fonts\\arialn.ttf"))
  (setq sty (vla-get-textstyles doc))
  (vlax-for s sty
	(setq sname (vla-get-name s))
	(if (/= sname "Standard")
		(
			(vla-put-fontfile s FntPth)
			(vla-put-width s 1.0)
;;			(print sname)
		)
;;		(print sname)
	)
	
  )
  (if (ssget "x" '((0 . "text")))
 	(vlax-for n	(vla-get-activeselectionset doc)
  )
 )
  (vla-regen doc acAllViewports)
  (princ)
)

 

0 Likes
Accepted solutions (2)
1,983 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

You are missing a progn

(defun c:txt2ttf (/ DOC FNTPTH STY )
  (vl-load-com)
  (setq	doc (vla-get-activedocument
	      (vlax-get-acad-object)
	    )
  )
  (setq FntPth (findfile "C:\\Windows\\Fonts\\arialn.ttf"))
  (setq sty (vla-get-textstyles doc))
  (vlax-for s sty
	(setq sname (vla-get-name s))
	(if (/= sname "Standard")
		(progn ; this was missing
			(vla-put-fontfile s FntPth)
			(vla-put-width s 1.0)
;;			(print sname)
		)
;;		(print sname)
	)
	
  )
  (if (ssget "x" '((0 . "text")))
 	(vlax-for n	(vla-get-activeselectionset doc)
  )
 )
  (vla-regen doc acAllViewports)
  (princ)
)

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store

0 Likes
Message 3 of 5

dbhunia
Advisor
Advisor

@CNinBC wrote:

all the text style definition(except for style "Standard" and "Roadname") to use "Arial Narrow.ttf" and change the width factor to 1.

 

Hi,

 

In your code there two modifications needed ............ go through the below code.

 

(defun c:txt2ttf (/ DOC FNTPTH STY )
(vl-load-com)
(setq doc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq FntPth (findfile "C:\\Windows\\Fonts\\arialn.ttf"))
(setq sty (vla-get-textstyles doc))
(vlax-for s sty
(setq sname (vla-get-name s))
(if (/= sname "Standard" "sections") ; Need to Change this line
(progn ; Add this
(vla-put-fontfile s FntPth)
(vla-put-width s 1.0)
;; (print sname)
)
;; (print sname)
)

)
(if (ssget "x" '((0 . "TEXT")))
(vlax-for n (vla-get-activeselectionset doc)
)
)
(vla-regen doc acAllViewports)
(princ)
)

 

But in my system the above code does not changing the "Width Factor", if this happens with you then go through the attached code.


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 5

dbhunia
Advisor
Advisor
Accepted solution
Hi,

Sorry I forgot to change the variables....

The modified codes are..

First----

(defun c:txt2ttf (/ DOC FNTPTH STY )
(vl-load-com)
(setq doc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq FntPth (findfile "C:\\Windows\\Fonts\\arialn.ttf"))
(setq sty (vla-get-textstyles doc))
(vlax-for s sty
(setq sname (vla-get-name s))
(if (/= sname "Standard" "Roadname")
(progn
(vla-put-fontfile s FntPth)
(vla-put-width s 1.0)
)
)
)
(if (ssget "x" '((0 . "TEXT")))
(vlax-for n (vla-get-activeselectionset doc)
)
)
(vla-regen doc acAllViewports)
(princ)
)


Second------


(defun c:txt2ttf (/ DOC FNTPTH STY )
(vl-load-com)
(setq doc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq FntPth (findfile "C:\\Windows\\Fonts\\arialn.ttf"))
(setq sty (vla-get-textstyles doc))
(vlax-for s sty
(setq sname (vla-get-name s))
(if (/= sname "Standard" "Roadname")
(progn
(vla-put-fontfile s FntPth)
)
)
)
(if (ssget "x" '((0 . "TEXT")))
(vlax-for n (vla-get-activeselectionset doc)
)
)
(vla-regen doc acAllViewports)
(Width_Factor)
(princ)
)
(defun Width_Factor ()
(if (Setq selectionset (ssget "x" '((0 . "TEXT"))))
(repeat (setq N (sslength selectionset))
(setq Data (ssname selectionset (setq N (- N 1))))
(setq EntityData (entget Data))
(setq Text_Style (cdr (assoc 7 EntityData)))
(if (/= Text_Style "Standard")
(if (/= Text_Style "Roadname")
(setq EntityData (subst (cons 41 1.0)(assoc 41 EntityData)EntityData))
)
)
(entmod EntityData)
)
)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 5

CNinBC
Advocate
Advocate

for some reason, the (/= sname "Standard" "Roadname") doesn't work, I have to use  (and (/= sname "Standard") (/= sname  "Roadname") )

0 Likes