using entmod to change dimension style

Z1000

Usenet Archive
Joined
Jan 6, 2004
Messages
9
Reaction score
0
I am trying to create a lisp that will update associative dimensions on older drawings to a new client standard.

I set up the new style called "style_new" and tried to change all the old "style_old" dimensions to "style_new".

I tried setting "style_new" as my current dimension style and using the "update" command. Problem with that was that it kills any "overrides" that might exist on the dimensions such as DIMLFAC or DIMSE1, etc.

I need a way to change the dimension style without altering the "overrides".

I tried using SSGET to make a selection set SS1 out of the offending dimensions and use (command "-DIMSTYLE" "A" SS1 "") to change them to the current style. It works, but it also resets the "overrides". Aaaagh!

I then tried using SUBST and ENTMOD to change (3 . "style_old") to (3 . "style_new") but it does not work on dimensions apparently. It will change the entity data, but as soon as you ENTMOD it, it returns to the original style.

Anyone solved this or want to try? Please?

Mike (Z1000)
 
Hi

You can read and save the dimension overrides aside then apply the new dimension style on the dimension object then apply back the dimension overrides.

good luck
moshe

Z1000 said:
I am trying to create a lisp that will update associative dimensions on
older drawings to a new client standard.
I set up the new style called "style_new" and tried to change all the old
"style_old" dimensions to "style_new".
I tried setting "style_new" as my current dimension style and using the
"update" command. Problem with that was that it kills any "overrides" that might exist on the dimensions such as DIMLFAC or DIMSE1, etc.
I need a way to change the dimension style without altering the "overrides".

I tried using SSGET to make a selection set SS1 out of the offending
dimensions and use (command "-DIMSTYLE" "A" SS1 "") to change them to the current style. It works, but it also resets the "overrides". Aaaagh!
I then tried using SUBST and ENTMOD to change (3 . "style_old") to (3 .
"style_new") but it does not work on dimensions apparently. It will change the entity data, but as soon as you ENTMOD it, it returns to the original style.
 
sounds like you need to collect your dims in a sel set, step through each dim, get it's overrides, change the stylename, then reapply the overrides (stored in xdata on the dim ent) unless maybe vla methods of setting the styleName property might work?
(rather than entmod)

Z1000 said:
I am trying to create a lisp that will update associative dimensions on
older drawings to a new client standard.
 
Steve, I tried your routine, but I get an error message:

Error: bad argument type: numberp: nil

I might be able to use some of the code however. I need to figure out how to extract the override info and save it and then re-apply it after updating to the new style.

Thanks for you hard work.

Mike (Z1000)

P.S. is the AutoDesk forum REALLY slow, or is it just my computer???
 
I been meaning to write a dimension merge routine for
a while now. Started to do this last night but don't have the time right now to finish it up. I'll offer one of the functions from my attempt, maybe it will help you.

; Jason Piercey . January 6th, 2004
; function to redefine the styleName property
; of a dimension object and retain any overrides
; that have been applied
; Arguments:
; [object] - vla-object, dimension object
; [styleName] - string, new stylename
; return: nil or error message
; example:
; (putDimstyleName (vlax-ename->vla-object (car (entsel))) "myNewStyle")

(defun putDimstyleName (object styleName / values types name child res) (vla-getxdata object "acad" 'values 'types)

;; determine if [object]'s styleName
;; property is that of a child style,
;; if so test for existence of same
;; child style defined by [styleName]
(if
(and
(wcmatch (setq name (vla-get-styleName object)) "*`$#") (not (vl-catch-all-error-p (vl-catch-all-apply '(lambda (vla-item (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object))) (setq child (strcat styleName (substr name (1- (strlen name)) (strlen name) ) ) ) ) ) ) ) ) ) (setq styleName child)
)

(setq
res
(vl-catch-all-apply
'vla-put-styleName
(list object styleName)
)
)

(if (vl-catch-all-error-p res)
(vl-catch-all-error-message res)
(if (and values types)
(vla-setxdata object values types)
)
)
)
 
Jason,

Nice function. I am able to follow your thinking except for the xdata stuff. I haven't much experience with Xdata, perhaps you could enlighten me. What is the purpose of your vla-setxdata line? I would think that it would be sufficient to just vla-put-stylename.

Thanks!

Regards,
Steve Doman
 
Hi Steve,

I'm no xdata expert, but in my brief testing just using (vla-put-stylename) removed any existing overrides. So I found it necessary to save any existing values, and restore them after applying the new stylename.

(setq obj (vlax-ename->vla-object (car (entsel))))
#<VLA-OBJECT IAcadDimRotated 056f8ce4>

(vla-get-stylename obj)
"Standard"

(vla-getxdata obj "acad" 'values 'types)
nil

!values
#<safearray...>

!types
#<safearray...>

(vla-put-stylename obj "test")
nil

(vla-getxdata obj "acad" 'values 'types)
nil

(vla-getxdata obj "acad" 'values 'types)
nil

!values
nil

!types
nil
 
Jason,

Thanks for the explanation! That's way cool. I've got to play around with Xdata some time.

Regards,
Steve Doman
 
I've been leery of xdata in the past as those association lists looked like a pain to deal with but the ActiveX methods sure seemed like a breeze.
 
Here is one I have made, it is for an individual entity selection. It does not change any override that I have concerns for, such as scale and tolerance overrides. Try it, Perhaps it might work or be adaptable for you, keep in mind or couirse, you will have to edit in your DIMSTYLE name to replace my "Fractional".

(defun C:FRAC
(setq DPRES nil
OBJ Nil)
(if (= nil (tblsearch "dimstyle" "FRACTIONAL"))
(progn (alert "No DimStyle named Frational")(exit)(prin1)) ) (while (= nil DPRES) (while (= nil OBJ)(setq OBJ (entsel "\n Select Dimension"))) (setq NM (car OBJ)) (setq D (entget NM)) (if (= "DIMENSION" (cdr (assoc 0 D))) (setq DPRES T) (setq OBJ nil) ) ) (setq D (subst '(3 . "FRACTIONAL") (assoc 3 D) D ) ) (entmod D) (entupd NM) (prin1)
)(prin1)
 
Well, thanks Jason. The function works, but now I am encountering problems with the two styles having different dimscales or DIMLFAC settings, so they don't show up as overrides. I will have to work those issues out, but that function does exactly what I wanted it to do. I don't know how or why it works however as I don't recognize much of the code. I am old school lisp and that stuff is all newfangled. Thanks again.

Mike (Z1000)

Jason Piercey said:
I been meaning to write a dimension merge routine for
a while now. Started to do this last night but don't have the time right now to finish it up. I'll offer one of the functions from my attempt, maybe it will help you.

; Jason Piercey . January 6th, 2004
; function to redefine the styleName property
; of a dimension object and retain any overrides
; that have been applied
; Arguments:
; [object] - vla-object, dimension object
; [styleName] - string, new stylename
; return: nil or error message
; example:
; (putDimstyleName (vlax-ename->vla-object (car (entsel))) "myNewStyle")

(defun putDimstyleName (object styleName / values types name child res) (vla-getxdata object "acad" 'values 'types)

;; determine if [object]'s styleName
;; property is that of a child style,
;; if so test for existence of same
;; child style defined by [styleName]
(if
(and
(wcmatch (setq name (vla-get-styleName object)) "*`$#") (not (vl-catch-all-error-p (vl-catch-all-apply '(lambda (vla-item (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object))) (setq child (strcat styleName (substr name (1- (strlen name)) (strlen name) ) ) ) ) ) ) ) ) ) (setq styleName child)
)

(setq
res
(vl-catch-all-apply
'vla-put-styleName
(list object styleName)
)
)

(if (vl-catch-all-error-p res)
(vl-catch-all-error-message res)
(if (and values types)
(vla-setxdata object values types)
)
)
)

I need to figure out how to extract the override info and save it and then re-apply it after updating to the new style.
 
bgriesel, thank you thank you. Your routine was very similar to the one I wrote below, but yours worked. After reviewing yours, I figured out what I had done wrong. I noted the change I did it the code below. Thanks again, it works wonderfully and simply.

Mike (Z1000)

;;; Routine to change dimension style OLD_STYLE to NEW_STYLE (setq SS1 nil)

(setq SS1 (ssget "X" '((0 . "DIMENSION") (3 . "OLD_STYLE"))))

(if SS1
(progn
(setq CT 0)
(repeat (sslength SS1)
(setq ED (entget (ssname SS1 CT)))
;;; I had the next line as (subst '(3 . "NEW_STYLE") (assoc 3 ED) ED) ;;; it did not work because I did not define ED as the updated data (setq ED (subst '(3 . "NEW_STYLE") (assoc 3 ED) ED)) (entmod ED) (setq CT (1+ CT)) ) )
)

bgriesel said:
Here is one I have made, it is for an individual entity selection. It does
not change any override that I have concerns for, such as scale and tolerance overrides. Try it, Perhaps it might work or be adaptable for you, keep in mind or couirse, you will have to edit in your DIMSTYLE name to replace my "Fractional".
 
Glad I could help.
Don't you just love these Discussion groups? Had a problem of my own solved here ealier today.

Bernie
 
Mike,

Didn't see a reply so wasn't sure if you noticed that I attached the fixed version to my prior post.

Steve Doman

Steve Doman said:
Mike,

Found the bug, thanks. I haven't used this routine for a few years and had forgotten that AutoDesk changed some things inside the dimstyle entget list.
<clip>
 
I got it - version 2.05. Thanks a bunch Steve. Maybe I can help you out sometime.

Mike (Z1000)
 
Back
Top