Mezalaja Posted June 24, 2010 Share Posted June 24, 2010 Hi there,... Is there a lisp routine out there that will allow you to select an object in your drawing and make the selected object's text style or dimension style the current text or dimension style? I've searched the forums and haven't found anything so far. Thanks in advance! Meza Quote Link to comment Share on other sites More sharing options...
CHLUCFENG Posted June 24, 2010 Share Posted June 24, 2010 I modified a routine I've had for setting the current layer: (defun C:SetStuff (/ ent lyrnme checkEntity txtnme dimnme) (setq ent (entsel "\nSelect Entity containing properties: ")) (if (/= ent nil) (progn (setq lyrnme (cdr (assoc 8 (entget (car ent))))) (setq checkEntity (cdr (assoc 0 (entget (car ent))))) (if (or (= checkEntity "MTEXT") (= checkEntity "TEXT")) (setq txtnme (cdr (assoc 7 (entget (car ent))))) ; TEXTSTYLE ) (if (or (= checkEntity "LEADER") (= checkEntity "DIMENSION")) (setq dimnme (cdr (assoc 3 (entget (car ent))))) ; DIMSTYLE ) ) ) (if lyrnme (setvar "CLAYER" lyrnme)) (if dimnme (progn (command "_dimstyle" "R" dimnme) (setq txtnme (GETVAR "DIMTXSTY")) ) ) (if txtnme (setvar "TEXTSTYLE" txtnme)) (princ) ) I did sneak a (command...) call in there. I hope noone notices! Chuck Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 25, 2010 Author Share Posted June 25, 2010 Thanks for the code... but it doesn't seem to work. It changes the layer over but the current text style or the current dimension style doesn't change. This is the error that I get when I run it. Select Entity containing properties: ; error: AutoCAD variable setting rejected: "TEXTSTYLE" "civ3d - profile" Also,... I am currently trying this out in AutoCAD 2008... I don't know if that makes a difference or not. I do have 2011 but I haven't tried it there yet. M Quote Link to comment Share on other sites More sharing options...
CHLUCFENG Posted June 25, 2010 Share Posted June 25, 2010 I wrote the code using 2006, I tested today in 2009, and it works on my end. Also, I modified the code above to include changing the text style to the dimension text style when a dimension is selected. I am unsure why you are getting the error. Has anyone else tried this and received an error, or does it work? Input greatly appreciated. Chuck Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 25, 2010 Author Share Posted June 25, 2010 Chuck,... I don't know why but it's working for me now. Thanks so much! One other question... it doesn't seem to work when I select a leader. Could you test it on your end to check? Thanks again. M Quote Link to comment Share on other sites More sharing options...
CHLUCFENG Posted June 25, 2010 Share Posted June 25, 2010 Added leader to the mix. Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 25, 2010 Share Posted June 25, 2010 Just for fun.. (defun c:Match (/ ent) ;; Alan J. Thompson, 06.25.10 (vl-load-com) (if (setq ent (car (entsel "\nSelect object: "))) (if (wcmatch (cdr (assoc 0 (setq ent (entget ent)))) "DIMENSION,LEADER,MTEXT,TEXT") (progn (vl-catch-all-apply (function (lambda () (vla-put-activedimstyle (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) (vla-item (vla-get-dimstyles *AcadDoc*) (cdr (assoc 3 ent))) ) ) ) ) (setvar 'clayer (cdr (assoc 8 ent))) (setvar 'textstyle (cdr (cond ((assoc 7 ent)) (((lambda (dim) (if dim (assoc 2 (entget (cdr (assoc 340 (tblsearch "dimstyle" dim))))) ) ) (cdr (assoc 3 ent)) ) ) ) ) ) (princ (strcat "\nActive styles: (Text . " (getvar 'textstyle) ") (CLayer . " (getvar 'clayer) ") (Dimension . " (getvar 'dimstyle) ")" ) ) ) (princ "\nInvalid object!") ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
CHLUCFENG Posted June 25, 2010 Share Posted June 25, 2010 Thanks Alan. I knew one of you smart guys would come along eventually and show me how to remove the (command ...) call. By the way, now that you are browsing, can you look at this one for me: http://www.cadtutor.net/forum/showthread.php?t=49311&page=2 I'm a little confused, but learning much! Thanks, Chuck Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 25, 2010 Author Share Posted June 25, 2010 Thanks Chuck, thanks Alan.... you guys are great. I was just trying edit Chuck's code to show the current styles after changing them when along comes Alan and posts exactly what I was going to ask next! Borderline telepathic, I think Alan... Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 26, 2010 Author Share Posted June 26, 2010 Alan, when I tried your code, it works fine when I select a text but I get an error when I select a dimension or a leader. It changes the dimstyle but not the text style. It seems to be searching for a textstyle that is the same name as the dimstyle. This was good, however because it got me to thinking that maybe it would be benificial to only change the dimstyle and not the current textstyle when selecting a dimension or a leader. Is it possible to adjust your code to do that? Is it also possible to adjust the settings when selecting a leader as well? For example: When using a leader, I frame my text for proposed objects and I don't frame my text when they are existing objects. Is it possible to incorporate that into the routine? i.e. when I select a leader with a frame it checks the "frame text" box and vice versa? One other thing.... what is the difference/benifits between the code that you wrote and the one that Chuck wrote? I am slowly trying to understand the lisp lanuage and have started by trying to edit some simple routines out here to see what happen when I change certain things. Any help would be greatly appreciated and thanks again to you and Chuck. M Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 26, 2010 Share Posted June 26, 2010 Doh! I completely forgot that the text style name is embedded within the entity list data of a selected dimension. I've updated the code in the above post to rip the textstyle from the dimension style, rather than my original attempt - strictly my mistake. The top benefit to avoiding usage of command is the possible errors that can ensue with its use. If there's an error, I can trap it and the routine won't crash, whereas the other version (usage of command) must go through much more effort to 'pretty-much' avoid all possible errors. Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 27, 2010 Share Posted June 27, 2010 tiny fix,,,,,,,. Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 27, 2010 Author Share Posted June 27, 2010 Thanks Alan. Works perfectly now. Any way to make it so that the frame text option in the leader setting is toggled off or on to match the leader you select? If not, that's okay... you'll be saving me tons of time with the routine you posted just the way it is! M Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 27, 2010 Share Posted June 27, 2010 You're very welcome, but I think I've done enough to make your life easier. If you want it to do more, you should give it a shot, yourself. :wink: Quote Link to comment Share on other sites More sharing options...
Mezalaja Posted June 28, 2010 Author Share Posted June 28, 2010 lol,... fair enough, Alan! And also very true... you have helped out a lot... not only with this routine but with all the others that you have posted out here as well. I shall give it a shot and see what happens... Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 28, 2010 Share Posted June 28, 2010 lol,... fair enough, Alan! And also very true... you have helped out a lot... not only with this routine but with all the others that you have posted out here as well. I shall give it a shot and see what happens... Why buy the cow when you get the milk for free. Have to make you work a little. 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.