RyanAtNelco Posted October 13, 2009 Posted October 13, 2009 Hello, Can someone help me out with a lisp that changes all the font in all text styles in a drawing to "Arial"? Thanks! Quote
SteveK Posted October 13, 2009 Posted October 13, 2009 Hi, by help do you mean you're trying to write it yourself? If so I would suggest you will need: - an ssget function to find all text: eg (setq ss (ssget "_X" '((0 . "TEXT,MTEXT")))) - a loop to iterate through each text: eg (setq i -1) (while (setq ent (ssname ss (setq i (1+ i)))) ;<code> ) - and a function to modify each text (use entmod & subst): eg (entmod (subst (cons 7 "Arial") (assoc 7 (entget en)) (entget en))) Completed code: (defun c:change2arial (/ ss en) (setq ss (ssget "_X" '((0 . "TEXT,MTEXT")))) (setq i -1) (while (setq en (ssname ss (setq i (1+ i)))) (entmod (subst (cons 7 "Arial") (assoc 7 (entget en)) (entget en))) ) (princ) ) There's no error trapping included & if you want to include inside blocks then that gets a bit more complicated. Quote
rkmcswain Posted October 13, 2009 Posted October 13, 2009 Completed code: (defun c:change2arial (/ ss en) (setq ss (ssget "_X" '((0 . "TEXT,MTEXT")))) (setq i -1) (while (setq en (ssname ss (setq i (1+ i)))) (entmod (subst (cons 7 "Arial") (assoc 7 (entget en)) (entget en))) ) (princ) ) There's no error trapping included & if you want to include inside blocks then that gets a bit more complicated. That changes the style of each text and mtext entity, but the OP wanted to change the font associated with each STYLE. ---------------------------- The code below changes the font of each STYLE to ARIAL. (vl-load-com) (vlax-for x (vla-get-TextStyles (vla-get-activedocument (vlax-get-acad-object)) ) (princ) (vla-setfont x "ARIAL" :vlax-False :vlax-False 0 32) ) Quote
RyanAtNelco Posted October 15, 2009 Author Posted October 15, 2009 Awesome, thanks guys!!! This is exactly what i am looking for. Steve - I do like your explanation of the code. It is quite helpful to someone at the beginning stages of lisp. Quote
rkmcswain Posted October 15, 2009 Posted October 15, 2009 ...Steve - I do like your explanation of the code. It is quite helpful to someone at the beginning stages of lisp. I should have done the same... :wink: [color="Red"]; required once per session[/color] (vl-load-com) [color="Red"]; vlax-for is a looping mechanism, x is the variable assigned to each object as it passes through the loop...[/color] (vlax-for x [color="Red"]; get a reference to the collection of textstyles [/color] (vla-get-TextStyles [color="Red"]; get a reference to the active document[/color] (vla-get-activedocument [color="Red"]; get a reference to the AutoCAD object[/color] (vlax-get-acad-object) ) ) (princ) [color="Red"]; this is the code that actually sets the font to the style object ; remember "x" is the reference to the textstyle[/color] (vla-setfont x "ARIAL" :vlax-False :vlax-False 0 32) ) Quote
RyanAtNelco Posted October 15, 2009 Author Posted October 15, 2009 rkmcswain, i am not quite sure how to get your code how to work. It does not seem to be as simple as typing it in, and is more complicated than simply adding "defun C:" to it. Can you help me out with what i am missing? Thanks! Quote
rkmcswain Posted October 15, 2009 Posted October 15, 2009 rkmcswain, i am not quite sure how to get your code how to work. It does not seem to be as simple as typing it in, and is more complicated than simply adding "defun C:" to it. Can you help me out with what i am missing? Thanks! If you copy the original code into the VLIDE, and press the run button, it will execute. If you save that code into a file, and load the file, it will execute. You can load a file using the APPLOAD command, or by using the (load) function at the command line like this: (load "myfile") -or- (load "c:\\lispcode\\myfile") if the file is not in the support file search path. If you want to create a function to be loaded into memory, for later execution, then you will have to add the (defun) wrapper like this: (vl-load-com) [color="Blue"](defun C:FOO ()[/color] (vlax-for x (vla-get-TextStyles (vla-get-activedocument (vlax-get-acad-object)) ) (princ) (vla-setfont x "ARIAL" :vlax-False :vlax-False 0 32) ) [color="Blue"])[/color] If you use the above code, you can still load the code into AutoCAD by copying the code (or opening the file) into the VLIDE and pressing the run button. You can also load the file as described above with the (load) function. The difference is that if you add the (defun) wrapper, then the code does not execute when you load it, it only loads the code into memory. At this point, you would have to run the command (named FOO at this point) while inside of AutoCAD Quote
RyanAtNelco Posted October 15, 2009 Author Posted October 15, 2009 For some reason, i can only get the function to return "nil" Quote
rkmcswain Posted October 15, 2009 Posted October 15, 2009 So you loaded the function, and then typed the function name at the command prompt, and it returns nil and does not change the fonts in your styles? Does it do the same thing in ALL drawings, even a new empty drawing? Quote
RyanAtNelco Posted October 15, 2009 Author Posted October 15, 2009 I figured it out, it does work. There were just overrides on some of the text i was working with. Thanks!!! Quote
lpseifert Posted October 15, 2009 Posted October 15, 2009 Mr. McSwain... Just out of curiosity, could you explain the purpose of the :vlax-False :vlax-False 0 32) in the above code? Thanks Quote
rkmcswain Posted October 15, 2009 Posted October 15, 2009 Mr. McSwain...Just out of curiosity, could you explain the purpose of the :vlax-False :vlax-False 0 32) in the above code? Thanks If you have access to the developers help, look for SETFONT method under ActiveX and VBA Reference. The syntax is: object.SetFont(Typeface, Bold, Italic, CharSet, PitchAndFamily) The CharSet and PitchAndFamily arguments expect certain constants as defined in the developers help. 0 = ANSI_CHARSET 32 = FF_SWISS Quote
alanjt Posted October 15, 2009 Posted October 15, 2009 Very interesting, thanks RK. Now, how do you make it Annotative? :wink: Quote
rkmcswain Posted October 15, 2009 Posted October 15, 2009 Now, how do you make it Annotative? :wink: HA! That I have never done with lisp.... Quote
lpseifert Posted October 15, 2009 Posted October 15, 2009 If you have access to the developers help, look for SETFONT method under ActiveX and VBA Reference. The syntax is: object.SetFont(Typeface, Bold, Italic, CharSet, PitchAndFamily) The CharSet and PitchAndFamily arguments expect certain constants as defined in the developers help. 0 = ANSI_CHARSET 32 = FF_SWISS Thanks for that... Actually I did look in Help for Setfont prior to asking you. It's remains Greek to me, I was just curious to what the significance of the :vlax-False :vlax-False and the arguments were, and if they were necessary. Quote
rkmcswain Posted October 16, 2009 Posted October 16, 2009 Thanks for that...Actually I did look in Help for Setfont prior to asking you. It's remains Greek to me, I was just curious to what the significance of the :vlax-False :vlax-False and the arguments were, and if they were necessary. Unfortunately, I don't know any more about it than is documented in HELP, a portion of which was copied into that last post. Quote
Jabberwock Posted November 12, 2009 Posted November 12, 2009 Thank you people! I'm just a beginer and this proved as useful start. Quote
Tue_NV Posted January 21, 2010 Posted January 21, 2010 (vlax-for x (vla-get-TextStyles (vla-get-activedocument (vlax-get-acad-object)) ) (princ) (vla-setfont x "ARIAL" :vlax-False :vlax-False [color=magenta]0 32[/color]) ) Hi all! Please show me a little : Number 0 and number 32 in the code this mean anything? 0 = ANSI_CHARSET -> this mean? 32 = FF_SWISS -> this mean? Thank you very much Quote
rkmcswain Posted January 21, 2010 Posted January 21, 2010 (vlax-for x (vla-get-TextStyles (vla-get-activedocument (vlax-get-acad-object)) ) (princ) (vla-setfont x "ARIAL" :vlax-False :vlax-False [color=magenta]0 32[/color]) ) Hi all! Please show me a little : Number 0 and number 32 in the code this mean anything? See this post Quote
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.