Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to modify dim text color in current dimstyle?

33 REPLIES 33
Reply
Message 1 of 34
allenliuyy
4465 Views, 33 Replies

How to modify dim text color in current dimstyle?

How to change the dim text color in current dimstyle with a lisp routine? I want to modify current dimstyle instead of override current dimstyle, so it can change all existing dim text color under the current dimstyle.

 

Help please, thank you in advance.

 

33 REPLIES 33
Message 2 of 34
pbejse
in reply to: allenliuyy


@allenliuyy wrote:

How to change the dim text color in current dimstyle with a lisp routine? I want to modify current dimstyle instead of override current dimstyle, so it can change all existing dim text color under the current dimstyle.

 

Help please, thank you in advance.

 


(Defun c:dcol ( / color)
      (setq currentdimstyle (getvar 'Dimstyle))
      (setvar 'Expert 5)
       (while (not
                     (and
                           (setq color
                                      (getint
                                            "\nEner Dimension text color: "))
                           (<= -1 color 257))))
      (command "_dim" "dimclrt" color
            "_save" currentdimstyle "_Exit")
      (princ)
      )

or

 

(Defun c:dcol ( / color)
      (setq currentdimstyle (getvar 'Dimstyle))
      (setvar 'Expert 5)
       (if (setq color (acad_colordlg 7 t))
      (command "_dim" "dimclrt" color
            "_save" currentdimstyle "_Exit")
            )
      (princ)
      )

 

Message 3 of 34
allenliuyy
in reply to: allenliuyy

Spoiler
 

Thank you.

 

But it does not change the existing dim text color. There are some dims already in the drawing. I also want to change the existing dim text color under the same dimstyle.

 

 

Message 4 of 34
pbejse
in reply to: allenliuyy


@allenliuyy wrote:
Spoiler
 

Thank you.

 

But it does not change the existing dim text color. There are some dims already in the drawing. I also want to change the existing dim text color under the same dimstyle.

 

 


Quick Mod

 

(Defun c:dcol  (/ color ss e)
      (setq currentdimstyle (getvar 'Dimstyle))
      (setvar 'Expert 5)
      (if (setq color (acad_colordlg 7 t))
            (progn
                  (command
                        "_dim"
                        "dimclrt"
                        color
                        "_save"
                        currentdimstyle
                        "_Exit")
                  (setq ss (ssget "_X" (list '(0 . "DIMENSION")(cons 3 currentdimstyle))))
                  (while (setq e (ssname ss 0))
                        (vla-put-TextColor
                              (vlax-ename->vla-object e)
                              color)
                        (ssdel e ss))
                  )
            )
      (princ)
      )

 


 

Message 5 of 34
Kent1Cooper
in reply to: allenliuyy


@allenliuyy wrote:

....

But it does not change the existing dim text color. There are some dims already in the drawing. I also want to change the existing dim text color under the same dimstyle. 


It does update the color of the text in already-drawn Dimensions for me -- maybe it's version-dependent, or there's some setting that controls that.

 

But I have another suggestion.  If you happen to have some temporary Dimension-Style override(s) in effect that are not part of the Style definition, such as suppression of one or both extension lines, those overrides will then become part of the "base" definition of the Dimension Style.  For me, in that case, it not only changes the color of the text in already-drawn dimensions, but it also changes the extension-line suppression combinations of all of them, if there aren't individual-Dimension-entity overrides applied to them, to match what the current overrides happen to be at the time.  So some existing extension lines that I had on might disappear, and/or some that were suppressed might come on again.  It would do the same with dimension-line suppression, colors of other elements, etc., etc. -- all those myriad Dimension-related System Variables that can be overridden temporarily or on individual Dimension entities.

 

I suggest that you Restore the current Dimension Style first, which will wipe out any current overrides and go back to the "base" Style definition's settings, before saving that Style again with a different color assigned.  Incorporating that into pbejse's second routine [because I like the dialog-box way of getting the color]:
 

(Defun c:dcol ( / color)
  (setq currentdimstyle (getvar 'Dimstyle))
  (setvar 'Expert 5)
  (if (setq color (acad_colordlg 7 t))
    (command "_dim"
      "_restore" currentdimstyle
      "_dimclrt" color
      "_save" currentdimstyle
      "_Exit"
    ); command
  ); if
  (princ)
); defun

 

And also think about saving the EXPERT System Variable setting first, and restoring it at the end.

Kent Cooper, AIA
Message 6 of 34
allenliuyy
in reply to: pbejse

Thank you again.

 

It works now and updates all dim text color in the drawing.

 

But there is another issue,  I used to change dim text color by mannually going to dimstyle, then "modify" current dimstyle, then change the dim text color, then "ok", then "close". all dims text color is updated. Now it does not work this way. if somebody else opens the drawing and wants to change dim text color mannually, this will be a problem.

 

Could you please restore to the status which dim text color can be changed mannually by dimstyle dilogue box in case other people wants to change back to original color without lisp routine?

 

 

Message 7 of 34
Kent1Cooper
in reply to: allenliuyy


@allenliuyy wrote:

.... 

It works now and updates all dim text color in the drawing.

 

But there is another issue,  I used to change dim text color by mannually going to dimstyle, then "modify" current dimstyle, then change the dim text color, then "ok", then "close". all dims text color is updated. Now it does not work this way. if somebody else opens the drawing and wants to change dim text color mannually, this will be a problem.

 

Could you please restore to the status which dim text color can be changed mannually by dimstyle dilogue box in case other people wants to change back to original color without lisp routine?


That must be coming from the fact that pbejse's latest routine is explicitly assigning that color to the text of all Dimensions individually, rather than assigning it only to the Dimension Style and letting that control it in all the Dimensions.  An explicit text color override on an individual Dimension won't be overcome by a change in the text color of the applicable Style.  That, and the fact that it worked for me, makes me wonder whether, when you tried pbejse's first routine, you had explicit text color overrides on the Dimensions.  That would explain the fact that it didn't work right.
 

If you can take all Dimensions and remove any text color overrides, then I think the color change in the Dimension Style definition will handle it, and people will still be able to change it later as you describe.

 

That's not in entity data, but is carried in Extended Data, or in the TextColor VLA property.  I'm not sure how you would go about fixing that, because I can't find any kind of "ByDimensionStyle" option for things like this.  You don't want to change it to ByLayer if the Dimension text color is supposed to be the same regardless of Layer.  And you don't want to change it to any explicit color, because even if it's the same as the color in the Style definition, it will be a permanent color override that won't be affected by changing that definition.

 

I don't have enough experience working with Extended Data to know whether you can wipe out the appropriate entries.  Extended Data for a Dimension that has a text color override of Blue [5], and nothing else, looks like this:

 

("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 178) (1070 . 5) (1002 . "}"))

 

You would want to reach into that and remove the (1070 . 178) (1070 . 5) parts, but not just remove all Extended Data, because that's also where things like extension line suppression are kept, in other pairs of entries between the (1002) ones.

Kent Cooper, AIA
Message 8 of 34
allenliuyy
in reply to: Kent1Cooper

Thanks Kent.

 

I tried pbejse's first routine, it works with new drawing with existing dim text, I say new drawing which is the drawing I created with dims for testing the first routine. But it does not work with existing drawings with lots of dim text on them, even they have the same dimstyle as new drawing. That's why I requested the lasted routine from Pbejse, but it causes the new issue for not allowing mannually change the dim text color from dimstyle command.

 

 

Message 9 of 34
Kent1Cooper
in reply to: allenliuyy


@allenliuyy wrote:

.... 

I tried pbejse's first routine, it works with new drawing with existing dim text, I say new drawing which is the drawing I created with dims for testing the first routine. But it does not work with existing drawings with lots of dim text on them, even they have the same dimstyle as new drawing. That's why I requested the lasted routine from Pbejse, but it causes the new issue for not allowing mannually change the dim text color from dimstyle command.


I'm guessing that the trouble with existing drawings with lots of Dimensions isn't the lots of Dimensions, but that those Dimensions probably have text color overrides assigned to them, which remain overridden even if the Style has its text color changed.  You could test that easily enough: make a new drawing, draw some Dimensions in it, select one and in the Properties box, give it a text color that's the same as the text color in the Style definition.  Then run the routine to change the text color of that Style.  I expect the one you gave that color to explicitly will remain that color, and the others will update correctly.

 

If that's what happens, I think the solution is going to be stripping any text color overrides out of the Extended Data of all Dimensions, so they revert to the color in the Style definition.  I haven't done that kind of thing, but I imagine it's possible, and I'll poke at it a little later if someone else doesn't chime in.

Kent Cooper, AIA
Message 10 of 34
allenliuyy
in reply to: Kent1Cooper

I am sure those dims are not overriden dim text in existing drawings, I checked again there is no overridden dimstyle in the drawing, and the drawing is the one I made two days ago, I did not use any override dimstyle. Maybe it relates to some settings in the drawing. Thanks Kent.

 

Is there any chance that can restore the original status after running pbejse's lastest routine, so that the dim text color can still be changed mannually by dimstyle command by somebody else as I mentioned before?

 

 

Message 11 of 34
pbejse
in reply to: allenliuyy


allenliuyy wrote:

 

But it does not change the existing dim text color. There are some dims already in the drawing. I also want to change the existing dim text color under the same dimstyle.


Is there any chance that can restore the original status after running pbejse's lastest routine, so that the dim text color can still be changed mannually by dimstyle command by somebody else as I mentioned before? 


Thats odd. I'm pretty sure there are overrides thats why the first code ddint work as well as you wanted it to.

NOT dimstyle but Entitry overrides.

 

(as kent stated) The second code will Override text color [Entity overrides]

 

Now this code will first restore the dimstyle (taking out overrides)

 assign a new color  Save the dimstyle. update dimensions entities

 

(Defun c:dcol  (/ currentdimstyle color ss e)
      (setq currentdimstyle (getvar 'Dimstyle))
      (setvar 'Expert 5)
      (if (setq color (acad_colordlg 7 t))
            (progn
                  (command
                        "_dim"
                        "_restore"
                        currentdimstyle
                        "dimclrt"
                        color
                        "_save"
                        currentdimstyle
                        "_Exit")
                  (setq ss   (ssget "_X"
                                    (list '(0 . "DIMENSION")
                                          (cons 3 currentdimstyle))))
                  (while (setq e (ssname ss 0))
                        (vla-put-TextColor
                              (vlax-ename->vla-object e)
                              color)
                        (ssdel e ss))
                  )
            )
      (princ)
      )

 

HTH

 

 

Message 12 of 34
allenliuyy
in reply to: pbejse

Thank you.

There are some Entity overrides in the drawing, some dim text are modified with notes. "restore" does not help to change entity overriden dim text color.

 

As Kent stated, the codes

                  (setq ss   (ssget "_X"
                                    (list '(0 . "DIMENSION")
                                          (cons 3 currentdimstyle))))
                  (while (setq e (ssname ss 0))
                        (vla-put-TextColor
                              (vlax-ename->vla-object e)
                              color)
                        (ssdel e ss))

force to change all dim text color to what I want, including overridden dim texts.

But new issue is the dim text color can not be changed after by somebody else mannually through dimstyle dilogue box as I mentioned before.   

Message 13 of 34
pbejse
in reply to: allenliuyy


@allenliuyy wrote:

Thank you.

There are some Entity overrides in the drawing, some dim text are modified with notes. "restore" does not help to change entity overriden dim text color.

 

force to change all dim text color to what I want, including overridden dim texts.

But new issue is the dim text color can not be changed after by somebody else mannually through dimstyle dilogue box as I mentioned before.   


Did you try the code on top of this page? post an example... its getting too confusing 🙂

 

oh crap..i see what you mean now.

 

Hang on

 

Message 14 of 34
pbejse
in reply to: pbejse

try this now

 

(Defun c:dcol2  (/ currentdimstyle color ss e)
      (setq currentdimstyle (getvar 'Dimstyle))
      (setq exprt (getvar 'Expert))
      (setvar 'Expert 5)
      (if (setq color (acad_colordlg 7 t))
                  (progn
                        (command
                        "_dim"
                        "_restore" currentdimstyle
                        "dimclrt" color
                        "_save"  currentdimstyle
                        "_Exit")
  (if  (setq ss (ssget "_X"
          (list '(0 . "*DIMENSION")
                (cons 3 currentdimstyle)
                                     (cons 410 (getvar 'ctab))
                '(-4 . "<OR")
                '(1 . "*?*")
                '(-3 ("ACAD"))
                '(-4 . "OR>")
                ))
          )
                     (command "_dim" "update" ss "" "_Exit"))
                     )
                       
          )(setvar 'Expert eprt)
      (princ)
      )

 

Message 15 of 34
allenliuyy
in reply to: pbejse

That's perfect ! Thank you very much.

 

In the last row code:

 (setvar 'Expert eprt)

 

"eprt"  should be "exprt". 

 

Is this row necessary in the program?

Message 16 of 34
Kent1Cooper
in reply to: pbejse


@pbejse wrote:

....

                     (command "_dim" "update" ss "" "_Exit"))
....


The one remaining problem I see is that doing that by way of Dim Update will not only cause Dimensions to be updated to the current Style's definition in regard to text color, but also in regard to everything else.

 

I use extension-line suppression quite a lot on individual extension lines of individual dimensions [such as dimensions to center-lines, so the extension line doesn't draw through the gaps in the center-line], and occasionally other things like dimension-line suppression, text rotation, etc.  I wouldn't want all of those adjustments in existing Dimensions to be lost and revert to the base Style definition's characteristics.  That's why I think what's needed is to only strip any text-color override out of the extended data, and only in Dimensions that have such an override.

 

And I found a way to do that, without stripping out any other extended data entries such as extension-line suppression, or losing other adjustments.  It might not be the only or the most efficient way, but it seems to work, leaving all Dimensions in the current Style to take their text color from the Style definition and its newly-assigned text color.  See the attached file [minimally tested].  It could also use error handling, etc., but see whether it does what's needed.

Kent Cooper, AIA
Message 17 of 34
allenliuyy
in reply to: Kent1Cooper

Thanks, Kent.

You are right. pbejse's routine will update everything in the dimstyle during the dim text color change. If one dim with a tolerance in the drawing, this tolerance will be gone after running pbejse's lisp. But you lisp only changes the text color and keep tolerance. That's really what I want, just change the dim text color only.

 

Thank both of your efforts and solved my problem.

Message 18 of 34
Kent1Cooper
in reply to: allenliuyy


@allenliuyy wrote:

Thanks, Kent.

You are right. pbejse's routine will update everything in the dimstyle during the dim text color change. If one dim with a tolerance in the drawing, this tolerance will be gone after running pbejse's lisp. But you lisp only changes the text color and keep tolerance. That's really what I want, just change the dim text color only.

 

Thank both of your efforts and solved my problem.


You're welcome.  I was skeptical at first that there would be a way to strip text-color overrides, and it was quite an adventure to get the (list)/(append)/(cons) combination to end up with the right result, so I learned some good stuff in the process.

Kent Cooper, AIA
Message 19 of 34
allenliuyy
in reply to: Kent1Cooper

Hi Kent,

I tried some more drawings today with your latest lisp routine, it looks like not stable for all drawings I tested.

1) For some existing drawings with dims, it changes all dim text color for the first time running DTCR.LSP, but it does not work at all when I tried to change back to previous color or any other different color. (I could change back mannually through the dimstlye dilogue box).

2) For some existing drawings, it only changes one dim at a time, I have to keep press enter key to change the next dim text color.

3) I made a new drawing with some dims, DTCR.LSP runs perfectly, nothing wrong at all. it does not matter how many times I run the lsp, everytime it works well.

 

 

 

 

Message 20 of 34
pbejse
in reply to: allenliuyy


@allenliuyy wrote:

Hi Kent,

I tried some more drawings today with your latest lisp routine, it looks like not stable for all drawings I tested.

1) For some existing drawings with dims, it changes all dim text color for the first time running DTCR.LSP, but it does not work at all when I tried to change back to previous color or any other different color. (I could change back mannually through the dimstlye dilogue box).

2) For some existing drawings, it only changes one dim at a time, I have to keep press enter key to change the next dim text color.

3) I made a new drawing with some dims, DTCR.LSP runs perfectly, nothing wrong at all. it does not matter how many times I run the lsp, everytime it works well.

 


I tried Kents code , and its working on my end, can you post a sample drawing here with all possible conditions

 

I  used (command "_dim" "_update"....) when the understanding that there are absolutely no overrides at all.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost