Author Topic: Modifying the Standard dimstyle  (Read 3149 times)

0 Members and 1 Guest are viewing this topic.

mr_nick

  • Guest
Modifying the Standard dimstyle
« on: October 13, 2006, 03:40:50 AM »
Is there a way to programatically alter a dimstyle definition? I have had a look around various topics that start with a little promise but then trail to a dead end.

The reason I want to do this is because we are getting a lot of drawings coming in from a particular archiects practice where they seem to have a thing with having very personalised dimstyles. Not too much of a problem under normal circumstances but in this case they always modify the 'Standard' dimstyle rather than create themselves a new style. Add to this that depending on which person in the practice creates the drawing, the 'Standard' dimstyle is always different between users. We have different text sizes, colours, arrowheads, fonts etc etc.

What I would ideally like to do is have a 'magic button' that reverts the standard dimstyle back to the 'out of the box' settings so that we can bring back a degree a uniformity to these drawings. Does anybody have any suggestions on the best way of achieving this goal - if it is at all possible?
« Last Edit: October 13, 2006, 03:44:53 AM by mr_nick »

kpblc

  • Bull Frog
  • Posts: 325
Re: Modifying the Standard dimstyle
« Reply #1 on: October 13, 2006, 04:01:11 AM »
Somthing like this?
Code: [Select]
(defun _kpblc-style-create-sub-dimstyle
       (style-number / ent_list ent_name _dimblk_)
  (setq ent_name (if style-number
   (strcat *kpblc-stylename* "$" (itoa style-number))
   *kpblc-stylename*
) ;_ end of if
ent_list
(list
   (cons 0 "DIMSTYLE") ; @R@
   (cons 100 "AcDbSymbolTableRecord") ; @R@
   (cons 100 "AcDbDimStyleTableRecord") ; @R@
   (cons 2
(if (> (_kpblc-acad-version) 16)
   ent_name
   (vla-get-name (vla-get-activedimstyle *kpblc-activedoc*))
) ;_ end of if
   ) ;dimsty @R@
   (cons 70
(if (not style-number)
   0
   style-number
) ;_ end of if
   ) ; @R@
   (cons 40 (getvar "dimscale")) ;dimscale @R@
   (cons 41 2.5) ;dimsz @R@
   (cons 42 0.625) ;dimexo @R@
   (cons 43 3.75) ;dimdli @R@
   (cons 44 1.25) ;dimexe @R@
   (cons 45 0.5) ;dimrnd @R@
   (cons 46 0.0) ;dimdle @R@
   ;; 47 and 48 groups aren't used
   (cons 140 2.5) ;dimtxt @R@
   (cons 141 -2.5) ;dimcen @R@
   (cons 143 0.005) ;dimaltf @R@
;(cons 144 1) ;dimlfac
   (cons 145 0) ;dimtvp
   (cons 147 0.5) ;dimgap @R@
   ;; group 146 (dimtfac) not used - in dimstyle alternate units are not used
   (cons 72 0) ;dimlim
   (cons 73 0) ;dimtih @R@
   (cons 74 0) ;dimtoh @R@
   (cons 77 1) ;dimtad @R@
   (cons 78 8) ;dimzin @R@
   (cons 79 2) ;dimazin @R@
   ;; group 71 (dimtol) - not used (no alternate units)
   (cons 170 0) ;dimalt
   (cons 172 1) ;dimtofl @R@
   (cons 173 0) ;dimsah @R@
   (cons 174 0) ;dimtix
   (cons 175 1) ;dimsoxd
   (cons 176 0) ;dimclrd
   (cons 177 0) ;dimclre
   (cons 178 0) ;dimclrt
   (cons 179 1) ;dimadec
   ;; group 171 (dimaltd) not used - there's no altertate units
   (cons 271 0) ;dimdec @R@
   (cons 272 0) ;dimtdec @R@
   (cons 275 1) ;dimaunit
   (cons 277 2) ;dimlunit
   (cons 278 44) ;dimdsep @R@
   (cons 279 1) ;dimtmove
   (cons 280 0) ;dimjust
   (cons 281 0) ;dimsd1
   (cons 282 0) ;dimsd2
   (cons 283 0) ;dimtolj
   (cons 284 8) ;dimtzin
   ;; groups 270 and 287 are not used
   (cons 288 0) ;dimupt
   ;; groups 273 (dimaltu), 274 (dimalttd), 285 (dimaltz),
   ;; 286 (dimalttz) not used - there's no alternate untis
   ;; group 276 (dimfrac) not set
   (cons 340 (tblobjname "style" *kpblc-stylename*))
;dimtxtsty @R@
   (cons 371 -2) ;dimlwd
   (cons 372 -2) ;dimlwe
) ;_ end of list
  ) ;_ end of setq
  (cond
    ((member style-number '(nil 0 1))
     (if (not (tblobjname "block" "_archtick"))
       (progn
(setq _dimblk_ (getvar "dimblk"))
(setvar "dimblk" "_archtick")
(setvar "dimblk"
(if (= _dimblk_ "")
   "."
   _dimblk_
) ;_ end of if
) ;_ end of setvar
       ) ;_ end of progn
     ) ;_ end of if
     (setq ent_list
    (reverse
      (cons
(cons 342
      (cdr
(assoc 330
       (entget
(tblobjname "block" "_archtick")
       ) ;_ end of entget
) ;_ end of assoc
      ) ;_ end of cdr
) ;dimblk @R@
(reverse ent_list)
      ) ;_ end of cons
    ) ;_ end of reverse
     ) ;_ end of setq
     (setq ent_list
    (reverse
      (cons
(cons 343
      (cdr
(assoc 330
       (entget
(tblobjname "block" "_archtick")
       ) ;_ end of entget
) ;_ end of assoc
      ) ;_ end of cdr
) ;dimblk1
(reverse ent_list)
      ) ;_ end of cons
    ) ;_ end of reverse
     ) ;_ end of setq
     (setq ent_list
    (reverse
      (cons
(cons 344
      (cdr
(assoc 330
       (entget
(tblobjname "block" "_archtick")
       ) ;_ end of entget
) ;_ end of assoc
      ) ;_ end of cdr
) ;dimblk2
(reverse ent_list)
      ) ;_ end of cons
    ) ;_ end of reverse
     ) ;_ end of setq
    )
    ((= style-number 7)
     (setq ent_list
    (reverse
      (cons
(cons 341
      (cdr
(assoc 330
       (entget
(tblobjname "block" "_open30")
       ) ;_ end of entget
) ;_ end of assoc
      ) ;_ end of cdr
) ;dimblk @R@
(reverse ent_list)
      ) ;_ end of cons
    ) ;_ end of reverse
     ) ;_ end of setq
    )
  ) ;_ end of cond
  (if (setq exist_style (tblobjname "dimstyle" ent_name))
    (foreach item ent_list
      (_kpblc-ent-modify exist_style (car item) (cdr item))
    ) ;_ end of foreach
    (entmake ent_list)
  ) ;_ end of if
) ;_ end of defun
And example for using:
Code: [Select]
(if (or (not (tblsearch "block" "_archtick"))
      (not (tblsearch "block" "_open30"))
      ) ;_ end of or
(vl-catch-all-error-p
  (vl-catch-all-apply
    '(lambda ()
       (foreach item '("_archtick" "_open30")
(setq _dimblk_ (getvar "dimblk"))
(setvar "dimblk" ".")
(setvar "dimblk" item)
(if (or (= _dimblk_ "") (not _dimblk_))
   (setvar "dimblk" ".")
   ) ;_ end of if
) ;_ end of foreach
       ) ;_ end of LAMBDA
    ) ;_ end of VL-CATCH-ALL-APPLY
  ) ;_ end of VL-CATCH-ALL-ERROR-P
) ;_ end of if
      (foreach item (list nil 2 3 4 7)
(_kpblc-style-create-sub-dimstyle item)
) ;_ end of foreach
Be careful! Text style for new dimstyle sould be exist in file! (in my code name of it saved at *kpblc-style-name*)
--
Added.
@R@ commented groups are requiered to create dimstyle.
--
Edited: some comments translated to english
« Last Edit: October 13, 2006, 04:51:03 AM by kpblc »
Sorry for my English.

mr_nick

  • Guest
Re: Modifying the Standard dimstyle
« Reply #2 on: October 13, 2006, 04:55:39 AM »
Do you have the following code to supplement this - it fails otherwise.

_kpblc-ent-modify

_kpblc-acad-version

kpblc

  • Bull Frog
  • Posts: 325
Re: Modifying the Standard dimstyle
« Reply #3 on: October 13, 2006, 05:10:33 AM »
I terribly sorry, here they are:
Code: [Select]
(defun _kpblc-ent-modify (ent bit value / ent_list old_dxf new_dxf)
  (_kpblc-ent-modify-autoregen ent bit value t)
  ) ;_ end of defun

(defun _kpblc-ent-modify-autoregen (ent        bit   value      ext_regen
    /        ent_list   old_dxf    new_dxf
    layer_dxf70
    )
  (setq ent (_kpblc-conv-ent-to-ename ent))
  (if (not
(and
  (or
    (= (strcase (cdr (assoc 0 (entget ent))) nil) "STYLE")
    (= (strcase (cdr (assoc 0 (entget ent))) nil) "DIMSTYLE")
    (= (strcase (cdr (assoc 0 (entget ent))) nil) "LAYER")
    ) ;_ end of or
  (= bit 100)
  ) ;_ end of and
) ;_ end of not
    (progn
      (setq ent_list (entget ent)
    new_dxf  (cons bit
   (if (and (= bit 62) (= (type value) 'str))
     (if (= (strcase value) "BYLAYER")
       256
       0
       ) ;_ end of if
     value
     ) ;_ end of if
   ) ;_ end of cons
    ) ;_ end of setq
      (if (not (equal new_dxf (setq old_dxf (assoc bit ent_list))))
(progn
  (entmod (if old_dxf
    (subst new_dxf old_dxf ent_list)
    (append ent_list (list new_dxf))
    ) ;_ end of if
  ) ;_ end of entmod
  (if ent_regen
    (entupd ent)
    (redraw ent)
    ) ;_ end of if
  ) ;_ end of progn
) ;_ end of if
      ) ;_ end of progn
    ) ;_ end of if
  ent
  ) ;_ end of defun

(defun _kpblc-acad-version ()
  (atof (getvar "acadver"))
  ) ;_ end of defun
---
Added:
The version checking actually is not nesessary - it requires by my firm. The code is workable at 2002-2006 (i hope at 2007 it will works too - i just didn't test it)
« Last Edit: October 13, 2006, 05:12:37 AM by kpblc »
Sorry for my English.

mr_nick

  • Guest
Re: Modifying the Standard dimstyle
« Reply #4 on: October 13, 2006, 05:21:48 AM »
Now I need this one:

_kpblc-conv-ent-to-ename


We'll get there soon!!  :-)

kpblc

  • Bull Frog
  • Posts: 325
Re: Modifying the Standard dimstyle
« Reply #5 on: October 13, 2006, 05:48:20 AM »
These are consequences of concatenates lisps to one big system :(
Code: [Select]
(defun _kpblc-conv-ent-to-ename (ent_value)
  (cond
    ((= (type ent_value) 'vla-object) (vlax-vla-object->ename ent_value))
    ((= (type ent_value) 'ename) ent_value)
    ((= (type ent_value) 'list) (cdr (assoc -1 ent_value)))
    (t nil)
    ) ;_ end of cond
  ) ;_ end of defun
Sorry for my English.

mr_nick

  • Guest
Re: Modifying the Standard dimstyle
« Reply #6 on: October 13, 2006, 06:02:41 AM »
Now all the pieces are together, that does exactly what I need.

I'll now start picking through and see exactly what is happening so that I can learn how you've done this.

Many, many thanks for your input on this. :-D

Andrea

  • Water Moccasin
  • Posts: 2360
Re: Modifying the Standard dimstyle
« Reply #7 on: October 14, 2006, 07:39:58 PM »
sorry guys..but it wasn't more easier to rename the dimstyle and than insert a template file ?

just a question... :?
« Last Edit: October 14, 2006, 07:41:28 PM by Andrea »
Keep smile...

kpblc

  • Bull Frog
  • Posts: 325
Re: Modifying the Standard dimstyle
« Reply #8 on: October 16, 2006, 05:38:06 AM »
In some cases inserting dwt-file in not efficient. User can redefine dimstyle, but when you're execeute some lisp the style should be by firm standard. In this case loading dwt file is not good solve. using dws files could bring some problems in program execeuting or (and) in manually working.
CAD operators in my firm uses lisp like this, and files they create are standard :)
Sorry for my English.