See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Changing color of all dimension styles on a drawing

  1. #1
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Angry Update: My script for changing dimstyle colors almost works I bet Acad is bugging

    Hi pals,

    I am looking for little piece of code that enables to loop through all dimension styles of a drawing, and turn all the dimension text color to white (currently yellow...).

    I guess I have to use DIMSTYLE or _DIMSTYLE or that kind of command, but I don't know how to set the colors to the style.

    So if someone has an idea how to code that, that would help me a lot. Also I'd like to know where I can find a good API documentation for all autocad lisp commands.

    eg: (command "_LAYER" "_CO" (caddr listed) (cadr listed) "")
    Renames a layer, but where in hell is that described? I managed to create that little lisp routine by poking around and messing with other lisp files I have fetched on internet, but i'd like to understand what I do, and be able to program lisp correctly.


    Regards y'all
    Last edited by thomas.glasgow; 2007-07-15 at 07:51 PM.

  2. #2
    100 Club
    Join Date
    2006-11
    Location
    UTAH
    Posts
    135
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    Just to clarify... Are you trying to change the dimstyle colors via lisp for new dimensions? Or are you trying to change the color of existing dimensions?

    Also, there's a lot of places to look online for tutorials and such, like Afralisp at www.afralisp.net . Just do a forum search for "afralisp" and you'll find many of them.

    If you're anything like me and like to just dive in, break AutoCAD and then work out what happened (IOW, the long way), check the AutoCAD help files. From the main help page, select "AutoLISP, Visual Lisp, and DXF" on the right-hand side, and then "autolisp developers guide..." There's also a tutorial to create a "garden path" there, to help get you started.

  3. #3
    100 Club CADmium's Avatar
    Join Date
    2004-08
    Location
    Eberswalde, Germany, Europe
    Posts
    128
    Login to Give a bone
    1

    Default Re: Changing color of all dimension styles on a drawing

    Try this
    Code:
    (defun DT:DIMSTYLE-COLORSWITCH (DIMSTYLENAME COLOR)
      (if(and(=(type DIMSTYLENAME)'STR)
             (=(type COLOR)'INT)
             (<= 0 COLOR 256)
             (setq DIMSTYLE(tblobjname "DIMSTYLE" DIMSTYLENAME))
             (setq DIMSTYLE(entget DIMSTYLE '("*")))                        
         )
        (entmod
          (mapcar '(lambda(X / Y)
                     (if ;(setq Y(car(member (car X)'( 176 177 178))))
                          (setq Y(car(member (car X)'( 178)))) ;only Text
                       (cons Y COLOR)
                       X
                     )  
                   )
                   DIMSTYLE
          )        
        )           
      )
    )
    
    (defun ALLDIMSTYLE-COLORSWITCH (COLOR / DS )
      (while (setq DS (tblnext "DIMSTYLE" (null DS)))
        (DT:DIMSTYLE-COLORSWITCH (cdr(assoc 2 DS))COLOR)
      )  
    )
    
    (ALLDIMSTYLE-COLORSWITCH 7)

  4. #4
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    @mike: I want to change the color or dimensions that are already on the drawing, and of course I want that newly added dimensions also use the newly defined dimensions.
    The help for developers can be directly reached under: Help > Additional Resources > Developer Help.


    @thomas: as is your code didn't do anything. I guess I have to add it to an existing lisp file. Can you give some quick implementation documentation about that?

    I'd also like to know some things:

    1) what means the DT: DIMSTYLE-COLOR which follows the defun. It's specially the DT: that I don't understand the use.

    2) what is the use of the single quotation marks?

    Once I understand well the code, I'll post an updated version with comments all over the place for other people to understand and learn.

  5. #5
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    I am trying to learn scripting in ACAD, but when I run the following script:
    Code:
    TIME R
    BOX 0,0 10,10,10 SPHERE 5,5,5 5 SUBTRACT NON 0,0  L
    VPOINT 1,-1,1 SLICE L   5,0 5,5 5,5,5 -1,0
    3DARRAY L  R 4 4 4 10 10 10
    ZOOM ALL HIDE
    VPORTS 4
    CVPORT 5 UCS X 90 PLAN C
    CVPORT 4 UCS W PLAN C
    CVPORT 2 UCS X 90 UCS Y 90 PLAN C
    TILEMODE 0 ERASE ALL  MVIEW R  F
    MSPACE CVPORT 3 SOLPROF ALL  Y Y Y
    CVPORT 4 SOLPROF ALL  Y Y Y
    CVPORT 5 SOLPROF ALL  Y Y Y
    CVPORT 6 SOLPROF ALL  Y Y Y
    TIME
    I get the following error message:
    Command: '_script
    Command: TIME
    Current time: Sunday, July 15, 2007 15:15:26 PM:421
    Times for this drawing:
    Created: Sunday, July 15, 2007 15:05:52 PM:234
    Last updated: Sunday, July 15, 2007 15:05:52 PM:234
    Total editing time: 0 days 00:09:34:187
    Elapsed timer (on): 0 days 00:00:47:750
    Next automatic save in: 0 days 00:01:08:344
    Enter option [Display/ON/OFF/Reset]: R
    Timer reset to zero.
    Enter option [Display/ON/OFF/Reset]: BOX
    Invalid option keyword.
    The script runs the "TIME R" command, then stupidly gets stuck at the "BOX" command thinking it's a value entered, instead of running a new command. Is there an option to modify somewhere?

    This code was taken from the Sybex book about Acad 2007, so it must work.

  6. #6
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    Okay guys, AutoCAD is just messed up, here is the updated code taken from the sybex website. If you can spot the changes you are very good.
    Code:
    ;;;;Dan Abbott
    ;;;;AutoCAD: Secrets Every User Should Know
    ;;;;Sybex Publishing, January, 2007
    ;;;;This script is designed to test the performance of a workstation from AutoCAD
    ;;;;To increase the demands on the system, increase the values used with the 3DARRAY command
    time r
    
    box 0,0 10,10,10 sphere 5,5,5 5 subtract non 0,0  L
    
    VPOINT 1,-1,1 slice l   5,0 5,5 5,5,5 -1,0
    3Darray l  r 4 4 4 10 10 10
    ZOOM All HIDE
    VPORTS 4
    CVPORT 5 UCS x 90 plan C
    CVPORT 4 UCS w plan C
    CVPORT 2 UCS x 90 UCS y 90 plan C
    TILEMODE 0 erase all  MVIEW r  F
    MSPACE CVPORT 3 SOLPROF all  y y y
    CVPORT 4 SOLPROF all  y y y
    CVPORT 5 SOLPROF all  y y y
    CVPORT 6 SOLPROF all  y y y
    time
    By the way it's a benchmarking script. My C2D E6300 performed: 1.250s

  7. #7
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    Holy snatch! How do we break never ending loops????

    Ctrl+C doesn't seem to work, Esc nor anything else!!!! What the heck is that visual lisp editor for?

  8. #8
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    I have finally been able to create an autolisp script that changes the DIMCLRT value for each dimension style, and that's the value that is supposed to change the dimension style text color.

    However AutoCAD doesn't seem to give a $hit about that.

    First, my dimension text style is yellow, so I update the DXF group code for dimension style DIMCLRT which is #178. Here is the returned list that defines the dimension ISONORM00 entity which I have updated using my script:

    Note: I have truncated most of the list, to only show the first two elements of it, and the only other element that changes, i.e (178 . x)
    Code:
    ((0 . "DIMSTYLE") (2 . "ISONORM00")...(178 . 7)...)
    (178 . 7) means that the dimension style text should appear white, but it still appears yellow.

    Now I edit by hand issuing the DIMSTYLE command in the command line, to have the text appear as red. When I close the dimstyle dialog box, the text appears red, and here is the list returned for ISONORM00:
    Code:
    ((0 . "DIMSTYLE") (2 . "ISONORM00")...(178 . 1)...)
    (178 . 1) means that the dimension style text shoud appears red, and it does!

    So I decided to edit by hand one more time and change the text color to white, and here is the list:
    Code:
    ((0 . "DIMSTYLE") (2 . "ISONORM00")...(178 . 7)...)
    As you can see, the entity definition list for ISONORM00 which I have updated by hand and using my script are both exactly the same.

    So why in hell AutoCAD doesn't want to apply the changes when using the script? Do I need to run some kind of update command or save the drawing and restart autocad???

    I am really stuck, and I spent my whole Sunday afternoon on that script, I know it works and that there is just a little stupid thing which I am not aware of and that's driving me nuts! Thanks for anyone who could help me out.

    Here are screenshots to understand the problem. The text on screen is still yellow although the attributes say it should be white...



    And another one, that's the dialog box when I type in "dimstyle" at the command line.
    Last edited by thomas.glasgow; 2007-07-16 at 09:14 PM.

  9. #9
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    In the mean time, I wanted to test if I really understood how to use the entget/subst/entmod combo, so I derived this little piece of code of my previous script:

    Code:
    (setq myCircle (entget (car (entsel))))
    (entmod (subst '(40 . 30) (assoc 40 myCircle) myCircle))
    This code prompts the user to select an object. It must be a circle, and then it sets its radius attribute to 30 by directly accessing the DXF code which is 40. Here is the result:

    Before:


    After:


    So my algorithm works, and AutoCAD is being naughty about the dimension styles...
    Last edited by thomas.glasgow; 2007-07-15 at 09:23 PM.

  10. #10
    Member
    Join Date
    2006-08
    Posts
    38
    Login to Give a bone
    0

    Default Re: Changing color of all dimension styles on a drawing

    jaberwork in another thread has proposed me to try:

    Menubar > Dimension > Update > All.

    Now., Hang on tight, because it's not simple.

    So in the previous screenshots, where you see the dimstyle dialog box opened, and the red ellipses that draw your attention, you will see that ISONORM00 doesn't have a <style override>, so when I do the update of the dimension, then my text turns into white! Tadah!!

    But! and there is a but (actually, why things never turn out right the first time?....), you will also notice that ISONORM, does have a <style override>.

    In this particular drawing, it is not a problem, because my styles depend on ISONORM00 and not on ISONORM (don't ask me why ISONORM doesn't get purged as it is not used, I am wasting my energy trying to understand how autocad works...)

    However in other drawings, it is an absolute mess! Here it goes:

    I tried my script on a drawing, where there is only one dimension style, and it is set to yellow. I run my script and the text still appears yellow. Great! So I decided to give a look at the dimension style manager, the dimension style is now turned to white, woohoo!! and... well... that stupid dumb AutoCAD creates a <style override>, that overrides the text color to yellow...

    So when I delete the override by hand, and update the dimensions, it finally turns out white.

    I don't know, if there are some autocad developers here, but they sure are twisted. Why making things simple, when they could be complicated?

    Now I need to find a way to code the style override deletion by hand, and still I am not sure it will work, probably autocad will come up with some new idea to plss me off...


    Here are the screen shots:

    Before autolisping my drawing:


    And after:

Page 1 of 2 12 LastLast

Similar Threads

  1. Changing Dimension Properties in an Existing Drawing
    By scoot in forum AutoCAD General
    Replies: 6
    Last Post: 2015-03-17, 04:25 PM
  2. Changing color of Xref layers based on color and layer name
    By tuerlinckx_peter862162 in forum AutoLISP
    Replies: 7
    Last Post: 2013-02-14, 06:46 PM
  3. dimension changing when drawing closed.
    By shenderson in forum AutoCAD General
    Replies: 1
    Last Post: 2009-03-16, 12:39 PM
  4. Replies: 3
    Last Post: 2007-02-24, 03:50 PM
  5. Sharing standard Dimension styles, text styles, hatch patterns, etc
    By dhavalpatel_us337373 in forum AutoCAD General
    Replies: 1
    Last Post: 2007-02-02, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •