Jump to content

Text style visual lisp routine not functioning correctly


JRC123

Recommended Posts

I have a lisp routine to update a font from one or more types to a single type.

 

Here it is:

 

(vl-load-com)

(defun c:TXSHX (/ new)
(setq new "C:/Program Files/Autodesk/AutoCAD 2016/Fonts/simplex.shx")
(vlax-map-collection(vla-get-textstyles(vla-get-activedocument(vlax-get-acad-object)))
'(lambda (x / font)
(setq font (strcase (vla-get-fontfile x)))
(if (wcmatch font "simplex.ttf,simplex.shx,simplex._ttf,simplex._shx")
(vla-put-fontfile x new)))
)
(princ)
)

 

I have no idea why, but it does not function. I get no errors, and nothing changes. Originaly I got this routine from a forum post. I modified it as required, but it was functional in its original form

 

Here is the original:

 

(vl-load-com)

(defun c:updateTextstyles (/ new)
(setq new (strcat (getenv "systemroot") "\\Fonts\\Arial.ttf"))
(vlax-map-collection
(vla-get-textstyles
(vla-get-activedocument
(vlax-get-acad-object)))
'(lambda (x / font)
(setq font (strcase (vla-get-fontfile x)))
(if (wcmatch font "ROMANS.SHX,SIMPLEX.SHX,TXT.SHX")
(vla-put-fontfile x new)))
)
(princ)
)

 

The drawing files I am working with are a bit weird as they are exported from revit. For example: The value in the styles table shows the font as "simplex_.ttf", but the UI shows the font as "simplex.shx". Reselecting simplex.shx fixes the style table. I am trying to automate this, but it just doesn't change when I run the routine.

Edited by JRC123
Link to comment
Share on other sites

Please read this:

http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines

 

And change the match pattern string from:

"simplex.ttf,simplex.shx,simplex._ttf,simplex._shx "

To:

"SIMPLEX.TTF,SIMPLEX.SHX,SIMPLEX._TTF,SIMPLEX._SHX"

All caps and no trailing space.

Edited by Roy_043
For some reason the forum software adds a trailing space to the strings. Using CODE tags now.
Link to comment
Share on other sites

Fixing the case got it working for about half of them. I also changed simplex._shx to simple_.shx as this was a type. For some reason only half of them change.

Link to comment
Share on other sites

Fixing the case got it working for about half of them. I also changed simplex._shx to simple_.shx as this was a type. For some reason only half of them change.

 

 

It would be helpful for you to post an example drawing for us to test. Otherwise it's almost impossible to determine what is going on in your drawing. It almost certainly has something to do with your wcmatch test if it is working on some, but not all. Perhaps to troubleshoot, you should use the (vlax-map-collection) function with just 'vla-get-fontfile and print the result to the command line to see what is coming up. Also check the path of your replacement font. unless you have "simplex.shx" in more than one place in your search paths, you should be able to replace:

 

 

(setq new "C:/Program Files/Autodesk/AutoCAD 2016/Fonts/simplex.shx")

with:

(setq new (findfile "simplex.shx"))

Link to comment
Share on other sites

Alright, I found the code below on the AUGI forums. I've added a link to the post at the end. This seems to work perfectly. It uses functions I have not seen in the LISP guides I've read, and unlike the other LISP routines I have found, it doesn't bother selection the active document or style sheats. I'm guessing the biggest change is wcmatch searches for a string rather than a font.

 

 

(defun c:allstyle2romansshx nil
 (foreach st (ai_table "STYLE" 4)
   (if (wcmatch st "RomanD*")
     (progn
       (command "_.STYLE" st "romans.shx")
       (while (< 0 (getvar 'cmdactive))
         (command "")
       )
     )
   )
 )
 (princ)
)

 

 

http://forums.augi.com/showthread.php?165834-LISP-to-change-font-of-text-styles-from-Revit-export

Link to comment
Share on other sites

Alright, I found the code below on the AUGI forums. I've added a link to the post at the end. This seems to work perfectly. It uses functions I have not seen in the LISP guides I've read, and unlike the other LISP routines I have found, it doesn't bother selection the active document or style sheats. I'm guessing the biggest change is wcmatch searches for a string rather than a font.

 

 

...

http://forums.augi.com/showthread.php?165834-LISP-to-change-font-of-text-styles-from-Revit-export

 

 

 

FYI - The (ai_table) function is a lisp routine written by Autodesk and included in the "ai-utils.lsp" file. (serach for it by typing (findfile "ai_utils.slp") on the command line. There are other useful utilities in there as well. They load with AutoCAD.

 

 

Otherwise all the functions in this are just built in functions. This is just a simpler way to code using the "STYLE" command to change the font Rather than the Visual LISP methods. Note "romans.shx" should not be necessary to use a (findfile) on if it already resides in the support paths.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...