ILoveMadoka Posted March 16, 2015 Share Posted March 16, 2015 I wanted to create a new thread since it's a different problem even though it is from a previous thread. Since I never know how many instances of a font that needs changing (SLDTEXTSTYLE) I wanted to create a counter. http://www.cadtutor.net/forum/showthread.php?91375http:// Digging around I found a way to create my counter number from this thread: http://www.cadtutor.net/forum/archive/index.php/t-76290.html How do I make the CNT a subroutine and call it from C:SWT (defun c:cnt () (setq la (cdr (assoc 2 (tblnext "STYLE" T)))) (setq lal (list la)) (while (/= (setq la (cdr (assoc 2 (tblnext "STYLE")))) nil) (setq lal (append lal (list la)) ) ) (setq LEN (length lal)) ) (defun c:swt (/ i s) (Princ "\nFinds all SW Text Styles, replaces with ROMANS Font:") (if (not (tblsearch "STYLE" "ROMANS")) (progn (command "_.STYLE" "ROMANS" "ROMANS") (while (> (getvar "CMDACTIVE") 0) (command "")))) (setq i 0) (repeat 9 ; All my LEN from the subroutine here? (setq s (strcat "SLDTEXTSTYLE" (itoa i))) (if (tblsearch "STYLE" s) (progn (command "_.STYLE" s "ROMANS") (while (> (getvar "CMDACTIVE") 0) (command "")))) (setq i (1+ i))) (princ)) And of course if there is a "better way" I'm always open to that too!! Thanks Much! Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted March 16, 2015 Author Share Posted March 16, 2015 Fixed my own problem. Is there a better way to achieve all this given my kindergarten programming skills? (defun c:swt (/ i s la lal len) (Princ "\nFinds all SolidWorks Text Styles, replaces with ROMANS Font:" ) (setq la (cdr (assoc 2 (tblnext "STYLE" T)))) (setq lal (list la)) (while (/= (setq la (cdr (assoc 2 (tblnext "STYLE")))) nil) (setq lal (append lal (list la)) ) ) (setq LEN (length lal)) (if (not (tblsearch "STYLE" "ROMANS")) (progn (command "_.STYLE" "ROMANS" "ROMANS") (while (> (getvar "CMDACTIVE") 0) (command "") ) ) ) (setq i 0) (repeat LEN ; All my LEN from the subroutine here (setq s (strcat "SLDTEXTSTYLE" (itoa i))) (if (tblsearch "STYLE" s) (progn (command "_.STYLE" s "ROMANS") (while (> (getvar "CMDACTIVE") 0) (command "") ) ) ) (setq i (1+ i)) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
jdiala Posted March 16, 2015 Share Posted March 16, 2015 No need for a counter. Just check the name of your text style. (defun C:swt () (vlax-map-collection (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object) ) ) (function (lambda ( x / n ) (if (or (= (setq n(strcase (vla-get-name x))) "ROMANS") (wcmatch n "SLDTEXTSTYLE*") ) (if (not (= "ROMANS" (vla-get-fontfile x))) (vla-put-fontfile x "ROMANS.SHX") ) ) ) ) ) (princ n) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted March 16, 2015 Share Posted March 16, 2015 (edited) I'm not getting the logic for c:cnt routine ILoveMadoka. But if you are planning to use a "sub-routine" in just one place on a routine, there's no point in creating one. > (Defun c:something () (blah blah) (while ; or repeat (subroutine);<-- right here and only here (blah blah blah) (blah blah) );end while ) To justify using a sub-routine, at least use it more than once in a routine, [ there's more reason than just that of course ]. (Defun c:something () (if (blah blah) (subroutine arg) (while ; or repeat (subroutine arg) (blah blah blah) (blah blah) );end while ) And you are wanting to convert the c:cnt to a subroutine for the wrong reason. You dont need the repeat function, just go ahead and run the font style change inside tblnext. I dont know if that is better for you though EDIT: i see you posted anew before i did Edited March 16, 2015 by pBe Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted March 16, 2015 Author Share Posted March 16, 2015 This is Da Bomb! Thx No need for a counter. Just check the name of your text style. (defun C:swt () (vlax-map-collection (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object) ) ) (function (lambda ( x / n ) (if (or (= (setq n(strcase (vla-get-name x))) "ROMANS") (wcmatch n "SLDTEXTSTYLE*") ) (if (not (= "ROMANS" (vla-get-fontfile x))) (vla-put-fontfile x "ROMANS.SHX") ) ) ) ) ) (princ n) ) Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted March 16, 2015 Author Share Posted March 16, 2015 pBe, My original code ran a set number of instances. Because I didn't always know how many I would find I needed a counter. I got a way to count the number of instances and I had the code to change but I didn't know how to marry the two together. At the moment I thought "subroutine." Newbie thinking.. 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.