Author Topic: [SOLVED] Modifying dimension style attributes  (Read 16536 times)

0 Members and 1 Guest are viewing this topic.

zibidi

  • Guest
[SOLVED] Modifying dimension style attributes
« on: July 16, 2007, 05:12:53 PM »
Hi swampers,

I am trying to update my existing dimensions so that they meet the ISO standard. I want to create a pure Autolisp script that could do that for me for each dimension style in a drawing. Here is the option I am trying to reach:



I tried comparing the dimension style definition list when changing by hand ISO, but no difference appeared in the dxf codes  :|

So if anyone has an idea on which dxf code to change or which entity to play with...  :-)
« Last Edit: July 18, 2007, 12:04:13 PM by zibidi »

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #1 on: July 16, 2007, 05:48:56 PM »
Looks to me like this affects the 2 Sysvars DIMTIH & DIMTOH. It sets the TIH to OFF (0) and TOH to ON(1) in my testing.

zibidi

  • Guest
Re: ISO dxf code for dimension style
« Reply #2 on: July 16, 2007, 06:06:21 PM »
In the mean time I have experienced a very dangerous behavior from autolisp/autocad:

I have created a simple script that changes all the dimstyle text color to force it to white. And for unknown reasons, AutoCAD has decided that it would also change some other dimension style attribute as well or play with the <style overrides>, I didn't figure out what exactly it did. The huge problem is that I have dimensions that have a scale factor, so when I run my script, the dimensions that have the scale factor have it removed!!!  :x

Just by chance I spotted it, and I could retrieve my old drawings from my backup hard drive, otherwise I would have wasted months of work due to wrong dimensions.

That definitely marks the end of my autolisp experience. I can no longer rely on it, as AutoCAD behavior is too dangerous. On some drawings it works, on some other that have traps, it doesn't, and that is unacceptable for a software of that price. What would have happened if I had automated my script to run on a whole folder?! I would have never been able to see that autocad would trash some drawings!!!  :realmad:

AutoCAD is the biggest piece of crap I have ever encountered in my computing life! And you know what? The worst is that I have no other choice to keep using it as long as my customers and partners use it...

ronjonp

  • Needs a day job
  • Posts: 7526
Re: ISO dxf code for dimension style
« Reply #3 on: July 16, 2007, 06:17:39 PM »
I wouldn't put so much blame on the software....it sounds like you are doing something wrong. :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #4 on: July 16, 2007, 06:24:34 PM »
I wouldn't put so much blame on the software....it sounds like you are doing something wrong. :?
I'd have to Echo that sentiment. As a general rule I won't execute a new routine on a batch job until I've tested it on a backup copy and inspected everything that it supposed to do, and verify that it's NOT doing something unintended.

The trouble with Dimensions is that each Style can have overrides which will be eliminated if the Parent style is altered without first saving the overrides to the parent. When doing this manually in the DimStyle Editor it warns you of this fact. Changing things programatically it is usually left up to the coder to make those decisions.

zibidi

  • Guest
Re: ISO dxf code for dimension style
« Reply #5 on: July 16, 2007, 06:30:29 PM »
Well, after calming down a little (I almost lost my business because of that), I have decided to give it one last chance.

Here is my script:
Code: [Select]
(defun C:DSP ( / dimStyleIdentifier dimStyleName dimStyleEntityName dimStyleEntity)

(setq dimStyleIdentifier (tblnext "DIMSTYLE" T)) ;get the first DIMSTYLE name and store it in dimStyleIdentifier
;Actually, it sets dimStyleIdentifier to the next dimstyle, but because there is the T
;parameter, it rewinds the table to the first entry of the DIMSTYLE table.
;The problem with tblnext is that it doesn't return a usable entity that can be updated with entmod. So we have
;to make a twist and first fetch the dimstylename, then fetch the correct dimstyle entity using tblobjname followed
; by an entget, then we can apply the entmod to update its attibutes.

(while dimStyleIdentifier
(setq dimStyleName (cdr (assoc 2 dimStyleidentifier))) ;fetch dimStyleIdentifier's name and store it in dimStyleName
(setq dimStyleEntityName (tblobjname "DIMSTYLE" dimStyleName)) ;fetch the dimstyle entity name.
(setq dimStyleEntity (entget dimStyleEntityName)) ;here we finally fetch the correct entity on which entmod can be invoked
(entmod (subst '(178 . 7) (assoc 178 dimStyleEntity) dimStyleEntity)) ;perform a substitution of the DXF code for DIMCLRT
;entmod is the function that actually applies the changes

(setq dimStyleIdentifier (tblnext "DIMSTYLE")) ;get the next dimstyle
); ends the while loop

(command "._DIM1" "update" "all" "") ;that's what updates the dimensions and redraws them white.

); ends the defun

The code is simple and I have commented it heavily so it'll be easy for you to understand. All I do, is make a substitution on the DXF code 178 which is the dimension style text color, and I force it to white. That's all my code does.

It seems, that the last line (command "._DIM1" "update" "all ""), is the one that deletes the <dimstyle override> (even though it shouldn't). The problem is that without this line, the changes don't get redrawn on the screen.

Anyone has an idea on that?

In my timezone, it is actually midnight, so I'll go to sleep, I hope the rest will give me some good advice on that enormous flaw.


EDIT: jeff_m you replied while I was writing this post. Yes definitely it is the fact that <dimstyle override> get deleted is what is causing me trouble.
« Last Edit: July 16, 2007, 06:40:08 PM by zibidi »

zibidi

  • Guest
Re: ISO dxf code for dimension style
« Reply #6 on: July 16, 2007, 06:34:04 PM »
Quote
The trouble with Dimensions is that each Style can have overrides which will be eliminated if the Parent style is altered without first saving the overrides to the parent.
That is an absolutely stupid behavior from autocad which I was not aware of, thank you for telling me. Why would overrides get removed? And I have been modifying the dimension style color by hand in the dimstyle editor, it has never notified me of any warning.

So how would you change my code to reflect that behavior? What I understand is that I first need to merge the override into the parent dimension style, then update the changes. Am I right?

PS: where did you manage to learn all that autolisp stuff? The help in autocad is... not very helpful.


EDIT: I have found out that to save dimstyle overrides one can issue at the command line:
Code: [Select]
-DIMSTYLE
SAVE
style-name
But I don't understand. How do I tell autocad to save the override I want. Using the snippet I gave above, it only saves one override. What about the other ones? Or can I simply reissue that command, and autocad will propose to save the next override?

Okay now I am going to bed.

EDIT: I tested the snippet, and it still trashes the scale factor of the dimstyle override that has been saved to an independent dimsension style. This is an absolute nonsense.  :ugly:
« Last Edit: July 16, 2007, 06:53:34 PM by zibidi »

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #7 on: July 16, 2007, 07:11:06 PM »
Oops, I typed without checking first. It is the "Set Current" that you cannot do without saving/losing your overrides.

Dim Update does just that. It updates the selected dimensions to be EXACTLY like that of the object's Dim Style.....which means it has to remove the object's dim overrides.

So, setting your DimStyle's properties will affect all new dimensions, but to change the existing dimensions to match the new style I think requires setting the override for EACH dimension object in the drawing, which is something easier done with ActiveX, IMHO. Otherwise you must modify the dictionary entry(ies) manually (that's where the overrides are stored). Alternatively you could probably save the overrides for each Dim object, use the Update, then reset the overrides for the objects. If anyone else knows differently, please chime in.

Just trying to throw out some ideas here. If you would like some help with any of them, just holler. :-)

The Help is helpful, when you eventually know what to look for :-) I learned by frequenting forums such as this and the Autodesk customization newsgroup. And LOTS of trial & error. :-/


Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #8 on: July 16, 2007, 07:18:39 PM »
My curiosity got the best of me again......I went to the Adesk User's Guide (Help), Command Reference, Found "DIM1" and followed the link. Under the "UPDATE" description it says
Quote from: Equivalent Command
-DIMSTYLE Apply
. So I followed my nose to that command sequence and this is what that described:
Quote
Applies the current dimensioning system variable settings to selected dimension objects, permanently overriding any existing dimension styles applied to these objects.
So the results you obtained are what I would expect, and it confirms that one of the methods I spoke of above will be required to accomplish your task.



Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: ISO dxf code for dimension style
« Reply #9 on: July 16, 2007, 07:33:34 PM »
My curiosity got the best of me again......
Okay mine kicked in as well but I just have questions.

Zibidi, why are you overriding the dimstyle?  It sounds like you are overriding every single dimension in the drawing with the script. That to me sounds like a lot of dimensions that need changing.  Would it not be easier to create different dimstyle and then change the dimensions to the new dimstyle, thus leaving the ones you do not what to change alone on the old dim style.

Just some thoughts here?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #10 on: July 16, 2007, 07:38:55 PM »
Hey zibidi, when you awaken and find all these posts please don't be put off by them...I'm really trying to help you out, not put you down. OK?

Anyway, I found another potential problem. That being that if the DimStyle's DIMCLRT value is the default of BYBLOCK (color 0) then it will not be in the (entget) list....which means there's nothing to modify with (subst), so that Style's Text color will not be revised per your code. Just thought you might want to know.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #11 on: July 16, 2007, 07:43:33 PM »
Hi Krushert,
Yes, I'm pretty sure that zibidi's intent is to change all of the Dimension Text to be White. Which can be done as they were trying, but, as they also found out, updating the dimensions to the revised styles removes any overrides on those dimensions. So yes, I think each & every one needs to be modified individually.

Of course I could be way off base....  :| :?

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: ISO dxf code for dimension style
« Reply #12 on: July 16, 2007, 08:02:09 PM »
Of course I could be way off base....  :| :?
And I am......merely 'touching' the dim objects will update them with the revised style.....try grip editing one and the text will update to the new color. A quickie work around is to use
Code: [Select]
(command "erase" "all" "")
(command "oops")
And that updates them without mucking with the individual overrides.....this is why I quit fooling with dimensions along time ago.....

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: ISO dxf code for dimension style
« Reply #13 on: July 16, 2007, 08:03:52 PM »
Of course I could be way off base....  :| :?
Mostly likely I am.  I am more often than not.  :-)

Let me ask this question.  Is he making the problem bigger?  For example, he is currently dealling with past overrides and the only way to deal with them is make more overides today.  Then lets say 6 months in the future he needs to make more changes.  Then at that time he is dealing with the overrides prior to today, today's overrides and whatever he has to do in the future.

He is trying to become ISO compliant so it might be easier to change dimstyles.  How many past overridden dimensions per file when compared to the total number of virgin dimensions are we talking about.  Only he can answer this question becuase we do not know his situation. 

Hey zibidi, when you awaken and find all these posts please don't be put off by them...I'm really trying to help you out, not put you down. OK?
Same here Zibidi.  Basically I am asking are you tackling this from the right angle? 
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: ISO dxf code for dimension style
« Reply #14 on: July 16, 2007, 08:06:40 PM »
And I am......merely 'touching' the dim objects will update them with the revised style.....try grip editing one and the text will update to the new color. A quickie work around is to use
Code: [Select]
(command "erase" "all" "")
(command "oops")
And that updates them without mucking with the individual overrides.....this is why I quit fooling with dimensions along time ago.....

What the ?   :-o :lmao:
Freakin Autocad
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans