JRC123 Posted August 18, 2016 Share Posted August 18, 2016 (edited) 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 August 18, 2016 by JRC123 Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted August 18, 2016 Share Posted August 18, 2016 (edited) 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 August 19, 2016 by Roy_043 For some reason the forum software adds a trailing space to the strings. Using CODE tags now. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 18, 2016 Share Posted August 18, 2016 Alternatively just add the t symbol for the first routine like this: (setq font (strcase (vla-get-fontfile x) [color="blue"][b]t[/b][/color])) Quote Link to comment Share on other sites More sharing options...
JRC123 Posted August 18, 2016 Author Share Posted August 18, 2016 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. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted August 19, 2016 Share Posted August 19, 2016 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")) Quote Link to comment Share on other sites More sharing options...
JRC123 Posted August 22, 2016 Author Share Posted August 22, 2016 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 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted August 24, 2016 Share Posted August 24, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.