View Full Version : Changing color of all dimension styles on a drawing
thomas.glasgow
2007-07-12, 11:53 PM
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
Mike_R
2007-07-13, 12:38 AM
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.
CADmium
2007-07-13, 09:13 AM
Try this
(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)
thomas.glasgow
2007-07-13, 02:38 PM
@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.
thomas.glasgow
2007-07-15, 03:23 PM
I am trying to learn scripting in ACAD, but when I run the following script:
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.
thomas.glasgow
2007-07-15, 03:40 PM
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.
;;;;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
thomas.glasgow
2007-07-15, 05:32 PM
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?
thomas.glasgow
2007-07-15, 09:22 PM
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)
((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:
((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:
((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... :banghead:
http://img96.imageshack.us/img96/2908/singledimstyleattributect1.png
And another one, that's the dialog box when I type in "dimstyle" at the command line.
http://img392.imageshack.us/img392/9334/dimstyleforsingledimensue2.png
thomas.glasgow
2007-07-15, 10:52 PM
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:
(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:
http://img102.imageshack.us/img102/1769/circlebeforevc9.png
After:
http://img102.imageshack.us/img102/2337/circleafterih5.png
So my algorithm works, and AutoCAD is being naughty about the dimension styles...
thomas.glasgow
2007-07-16, 12:26 PM
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!! :beer:
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... :banghead:
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? :screwy:
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... :veryevil:
Here are the screen shots:
Before autolisping my drawing:
http://img256.imageshack.us/img256/3066/01dimstylebeforedu6.png
And after:
http://img529.imageshack.us/img529/1935/02dimstyleafterse7.png
thomas.glasgow
2007-07-16, 02:56 PM
That's so hilarious :lol:
In google I typed: "autocad delete dimstyle override"
I found that: http://discussion.autodesk.com/thread.jspa?messageID=247576
Here is a quote:
Evil DimStyle Override (3 replies)
Posted by: Sanchez, Mark
Date: Feb/01/02 - 07:46 (GMT) Reply
I have a dimstyle override in a couple of my drawings (How they got in
there is a mystery). When I delete the override and save the drawing,
it will mysteriously re-appear when the drawing is Saved or re-opened.
I've tried everything I could think of (purge, recover, etc.) but this
EVIL override keeps coming back from the dead. This is very annoying as
it keeps re-setting our DIMSCALE value every time the drawing is saved.
What am I doing wrong,
Mark Sanchez
It just cracks me up! :mrgreen:
6000 bucks for that fine high quality craftsman piece of elegant software. :?
EDIT: Even augi is plagged by dimstyle overrides: http://forums.augi.com/showthread.php?t=64437
thomas.glasgow
2007-07-16, 09:37 PM
I found this in the so helpful autocad- built-in help:
There are restrictions on the changes to the database that entmod can make...
Blabla...
Other restrictions apply when modifying dimensions and hatch patterns.
Of course, these restrictions when modifying dimensions are not documented under the entmod section of the so helpful documentation... :|
thomas.glasgow
2007-07-16, 11:00 PM
Well it seems that everything has been sorted out at last :)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.