Jump to content

text and dimension styles


Mezalaja

Recommended Posts

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

Link to comment
Share on other sites

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. :oops: I hope noone notices! :D

 

Chuck

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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... :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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...:unsure:

Link to comment
Share on other sites

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...:unsure:
Why buy the cow when you get the milk for free. Have to make you work a little. ;)
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...