Author Topic: Dimension Precision  (Read 4946 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Dimension Precision
« on: April 27, 2016, 08:24:51 PM »
Hello to all who read,

Been a while since I've been here.

I'm currently in search for a LISP routine which will allow me to adjust the precision of a dimension(s) without going through the properties palette. I could have a go at this myself but am currently to busy to spare the time.

For example: The user implements the command and selects the dimension(s) in which to adjust the precision. The user is then prompted to enter the number of decimal places, say 2, and the selected dimensions update, displaying two decimal places.

If such a routine exists please let me know.

Thanks,
Cuddles

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimension Precision
« Reply #1 on: April 27, 2016, 09:31:56 PM »
Try this:
Quote
(defun c:DPre (/ SelectDim dimPrecision L_Decimal)
(setq SelectDim (entsel "\nSelect a Dimension to Change Precision: "))
(initget "1 2 3 4 5")
(setq dimPrecision (getkword "\nSpecify the Number of Decimal Place <1>, 2, 3, 4 or 5: "))
(if (not dimPrecision) (setq dimPrecision "1"))
(setq L_Decimal (expt 10.0 (- 0 (atof dimPrecision))))
(command "._DIMOVERRIDE" "dimrnd" L_Decimal "dimdec" (atoi dimPrecision) "" SelectDim "")
(princ)
)

HTH
« Last Edit: April 29, 2016, 12:26:32 AM by MeasureUp »

Cuddles

  • Guest
Re: Dimension Precision
« Reply #2 on: April 28, 2016, 06:11:26 PM »
Hello MeasureUp

Thanks for your response. However, the command "dimoverride" was not effective in changing the precision.
Evidently, I've discovered AutoCAD has a built-in fucntion for this: AIDIMPREC. Never knew it existed  :uglystupid2:

Thanks anyhow,

Cuddles

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Dimension Precision
« Reply #3 on: April 28, 2016, 08:07:28 PM »
Sorry for the error.
It is fixed. please see the code updated in my 1st post.

BTW what version are you using?
I am afraid that "AIDIMPREC" doesn't always return an actual value for the dimension.
It is controlled by "dimdec".
For example, if you set "dimdec" to "0" to the current dimstyle, then create a dimension for a 50mm line then you set "AIDIMPREC" to 5.
The dimension shows you "50.00000" which is right.
If you stretch the dimension to 100.12345mm, it won't return "100.12345" but gives you "10.00000".

HTH

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Dimension Precision
« Reply #4 on: April 28, 2016, 11:40:44 PM »
Haha...I've got so pathetically lazy with coding I opted to just use the options box for this....thanks for sharing.

Sorry for the error.
It is fixed. please see the code updated in my 1st post.

BTW what version are you using?
I am afraid that "AIDIMPREC" doesn't always return an actual value for the dimension.
It is controlled by "dimdec".
For example, if you set "dimdec" to "0" to the current dimstyle, then create a dimension for a 50mm line then you set "AIDIMPREC" to 5.
The dimension shows you "50.00000" which is right.
If you stretch the dimension to 100.12345mm, it won't return "100.12345" but gives you "10.00000".

HTH

johne

  • Mosquito
  • Posts: 5
Re: Dimension Precision
« Reply #5 on: April 29, 2016, 03:23:09 AM »
You can modify this code (no error checking tho :thinking:). Currently just increments or decrements by 1. eg (dimunits "1") or (dimunits "-1")

Code: [Select]
(defun DimUnits ( mode / modeValue dim cun )

(setq modeValue (atoi mode))
(if (or (> modeValue 1) (< modeValue -1))
(princ "\n Invalid argument")
  (progn
(setq dim (vlax-ename->vla-object (car (entsel "\n Select dimension: "))))
(setq cun (vla-get-PrimaryUnitsPrecision dim))
  (vla-put-PrimaryUnitsPrecision dim (+ cun modeValue))
)
)

(princ)

)

danallen

  • Guest
Re: Dimension Precision
« Reply #6 on: April 29, 2016, 11:40:43 AM »
my code, I like to type commands with preset options instead of answer prompts

Code: [Select]
(defun c:DRND0 () (SAA_DIM_ROUND nil nil "4")) ;round dimensions to 1"
(defun c:DRND  () (SAA_DIM_ROUND nil "1" "4")) ;round dimensions to 1"
(defun c:DRNDFT  () (SAA_DIM_ROUND nil "12" "4")) ;round dimensions to 12"
(defun c:DRND1 () (SAA_DIM_ROUND nil "1" "4")) ;round dimensions to 1"
(defun c:DRND12 () (SAA_DIM_ROUND nil "12" "4")) ;round dimensions to 12"
(defun c:DRND06 () (SAA_DIM_ROUND nil "6" "4")) ;round dimensions to 6"
(defun c:DRND2 () (SAA_DIM_ROUND nil "1/2" "4")) ;round dimensions to 1/2"
(defun c:DRND3 () (SAA_DIM_ROUND nil "1/4" "4")) ;round dimensions to 1/4"
(defun c:DRND4 () (SAA_DIM_ROUND nil "1/8" "4")) ;round dimensions to 1/8"
(defun c:DRND5 () (SAA_DIM_ROUND nil "1/16" "4")) ;round dimensions to 1/16"
(defun c:DRND6 () (SAA_DIM_ROUND nil "1/32" "5")) ;round dimensions to 1/32"
(defun c:DRND7 () (SAA_DIM_ROUND nil "1/64" "6")) ;round dimensions to 1/64"
(defun c:DRND8 () (SAA_DIM_ROUND nil "1/128" "7")) ;round dimensions to 1/128"
(defun c:DRND9 () (SAA_DIM_ROUND nil "1/256" "8")) ;round dimensions to 1/256"

(defun SAA_DIM_ROUND ( ss1 rnd ddec) ;round dimensions to passed in value
  (setvar "cmdecho" 0)
  (if (not rnd) (setq rnd (rtos (getvar "dimrnd")))) ;no value defaults to current setting
  (if (not ss1)
    (progn
      (princ (strcat "\nSelect dimensions to round-off to " rnd"\": "))
      (setq ss1 (ssget ":L" '((0 . "DIMENSION")))) ;no value defaults to current setting
    )
  )
  (if ss1 (progn
    (command "_.dim1" "override" "DIMRND" rnd "DIMDEC" ddec "DIMALTRND" rnd "DIMALTD" ddec "" ss1 "")
    (setvar "cmdecho" 1)
  ))
  (princ)
)

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Dimension Precision
« Reply #7 on: May 02, 2016, 12:19:44 PM »
I have been using this bit of code for years for quickly changing the precision of existing dims. It just uses the DIMOVERRIDE command. I try to account for dual dimensions as well. Someone here probably has a better method, but this works for me.

Code - Auto/Visual Lisp: [Select]
  1. (defun pjk-dimdec (val / altd daf dset str)
  2.         (princ "\nSelect Dimension(s) to Change:")
  3.         (setq dset (ssget '((0 . "DIMENSION"))) str (itoa val))
  4.         (if (or
  5.           (and (>= (setq daf (getvar "dimaltf")) 25.4)(/= daf 32.0)(/= daf 64.0))
  6.           (= (getvar "Measurement") 0)
  7.        )
  8.                 (if (> val 0)(setq altd (itoa (1- val)))(setq altd "0"))
  9.                 (if (< val 8)(setq altd (itoa (1+ val)))(setq altd "8"))
  10.         )
  11.         (if dset (command "._dimoverride" "dimdec" str "dimtdec" str "dimaltd" altd "dimalttd" altd "dimadec" str "" dset ""))
  12.         (princ)
  13. )
  14.  
  15. (defun C:D0 ()(pjk-dimdec 0))
  16. (defun C:D1 ()(pjk-dimdec 1))
  17. (defun C:D2 ()(pjk-dimdec 2))
  18. (defun C:D3 ()(pjk-dimdec 3))
  19. (defun C:D4 ()(pjk-dimdec 4))
  20. (defun C:D5 ()(pjk-dimdec 5))
  21. (defun C:D6 ()(pjk-dimdec 6))
  22. (defun C:D7 ()(pjk-dimdec 7))
  23. (defun C:D8 ()(pjk-dimdec 8))
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

nekonihonjin

  • Newt
  • Posts: 103
Re: Dimension Precision
« Reply #8 on: May 02, 2016, 05:36:45 PM »
Try this:
Quote
(defun c:DPre (/ SelectDim dimPrecision L_Decimal)
(setq SelectDim (entsel "\nSelect a Dimension to Change Precision: "))
(initget "1 2 3 4 5")
(setq dimPrecision (getkword "\nSpecify the Number of Decimal Place <1>, 2, 3, 4 or 5: "))
(if (not dimPrecision) (setq dimPrecision "1"))
(setq L_Decimal (expt 10.0 (- 0 (atof dimPrecision))))
(command "._DIMOVERRIDE" "dimrnd" L_Decimal "dimdec" (atoi dimPrecision) "" SelectDim "")
(princ)
)

HTH



Could you please make this work for angular dim?

Cuddles

  • Guest
Re: Dimension Precision
« Reply #9 on: May 03, 2016, 05:13:00 PM »
Hello All,

Thanks for your responses so far.

Quote
BTW what version are you using?
I am afraid that "AIDIMPREC" doesn't always return an actual value for the dimension.
It is controlled by "dimdec".
For example, if you set "dimdec" to "0" to the current dimstyle, then create a dimension for a 50mm line then you set "AIDIMPREC" to 5.
The dimension shows you "50.00000" which is right.
If you stretch the dimension to 100.12345mm, it won't return "100.12345" but gives you "10.00000".

HTH

MeasureUp (HTH) - I'm using a mix of AutoCAD 2013 LT and AutoCAD 2015 (2015 is a network license which i cannot use all the time - my work is a missed up place). I checked your comment regarding AIDIMPREC - stretching the 50.00000mm to 100.12345mm. For me, the dimension updates automatically, returning 100.12345mm. My DIMDEC is set to "0".

Thanks,
Cuddles

ahsattarian

  • Newt
  • Posts: 112
Re: Dimension Precision
« Reply #10 on: December 15, 2023, 06:45:25 AM »



Have a look at this  :


Code - Auto/Visual Lisp: [Select]
  1. ;;;   change dimension #xdata  
  2. (defun dimension-xdata-change (sj varj assj valj)
  3.   (setq enj (entget sj '("*")))
  4.   (setq lii (list (cons 1070 varj) (cons assj valj)))
  5.   (setq xd1 nil)
  6.   (if (and
  7.         (setq xd (assoc -3 enj))
  8.         (foreach a xd (cond ((listp a) (cond ((= (strcase (car a) t) "acad") (setq xd1 a))))))
  9.         xd1
  10.       )
  11.     (progn
  12.       (setq xd11 xd1)
  13.       (setq xd2 (list (car xd11)))
  14.       (setq xd11 (cdr xd11))
  15.       (setq add 1)
  16.       (while (setq a (car xd11))
  17.         (setq xd11 (cdr xd11))
  18.         (cond
  19.           ((equal a (cons 1070 varj))
  20.            (cond ((/= valj "Dimstyle") (setq xd2 (append xd2 lii))))
  21.            (setq xd11 (cdr xd11))
  22.            (setq add 0)
  23.           )
  24.           (t (setq xd2 (append xd2 (list a))))
  25.         )
  26.       )
  27.       (cond
  28.         ((= add 1)
  29.          (setq las (last xd2))
  30.          (setq xd2 (reverse (cdr (reverse xd2))))
  31.          (cond ((/= valj "Dimstyle") (setq xd2 (append xd2 lii))))
  32.          (setq xd2 (append xd2 (list las)))
  33.         )
  34.       )
  35.       (setq xdnew (subst xd2 xd1 xd))
  36.       (setq en1j (subst xdnew xd enj))
  37.     )
  38.     (cond
  39.       ((/= valj "Dimstyle")
  40.        (regapp "ACAD")
  41.        (setq en1j (append enj (list (list -3 (append '("ACAD" (1000 . "DSTYLE") (1002 . "{")) lii '((1002 . "}")))))))
  42.       )
  43.     )
  44.   )
  45.   (entmod en1j)
  46. )
  47. ;;;   change dimension precision subroutine  
  48. (defun mydimprec (sj valj)
  49.   (cond ((and (= (type valj) 'str) (/= valj "Dimstyle")) (setq valj (atoi valj)))) ;|  #type  |;
  50.   (cond ((= (type valj) 'int) (setq valj (min (max valj 0) 8))))
  51.   (setq objj (vlax-ename->vla-object sj))
  52.   (setq method1j 4)
  53.   (cond
  54.     ((= method1j 1) (command "dimoverride" "dimdec" valj "" sj ""))
  55.     ((= method1j 2) (vlax-put-property objj 'primaryunitsprecision valj))
  56.     ((= method1j 3) (vla-put-primaryunitsprecision objj valj))
  57.     ((= method1j 4) (dimension-xdata-change sj 271 1070 valj)) ;|  Only this option works with  :  Dimstyle  |;
  58.   )
  59.   (cond
  60.     ((= method1j 1) (command "dimoverride" "dimadec" valj "" sj ""))
  61.     ((= method1j 2) (vlax-put-property objj 'textprecision valj))
  62.     ((= method1j 3) (vla-put-textprecision objj valj))
  63.     ((= method1j 4) (dimension-xdata-change sj 179 1070 valj)) ;|  Only this option works with  :  Dimstyle  |;
  64.   )
  65. )
  66. ;;;   change dimension precision  
  67. (defun c:dp ()
  68.   (defun sub1 (valj)
  69.     (setq n (sslength ss))
  70.     (setq k -1)
  71.     (repeat n
  72.       (setq k (1+ k))
  73.       (setq s (ssname ss k))
  74.       (setq obj (vlax-ename->vla-object s))
  75.       (if (= valj "Dimstyle")
  76.         (mydimprec s "Dimstyle")
  77.         (if (vlax-property-available-p obj 'textprecision)
  78.           (mydimprec s (+ (vla-get-textprecision obj) valj))
  79.           (mydimprec s (+ (vla-get-primaryunitsprecision obj) valj))
  80.         )
  81.       )
  82.     )
  83.   )
  84.   (setq ss (ssget ":l" '((0 . "dimension"))))
  85.   (princ " Press  +  or  -  to Change Dimensions Precision ( R for Reset to dimstyle )  :  ")
  86.   (setvar "cursorsize" 1)
  87.   (setq g 1)
  88.   (while (= g 1) ;|  #grread point  |;
  89.     (setq gr (grread t 15 0))
  90.     (setq code (car gr))
  91.     (setq po (cadr gr))
  92.     (cond
  93.       ((= code 5)) ;|  Bedune Click  |;
  94.       ((= code 3) (setq g 0)) ;| Click Beshe |;
  95.       ((= code 2) ;|  Type Beshe  |;
  96.        (cond
  97.          ((= po 43) (sub1 +1)) ;|  +  |;
  98.          ((= po 45) (sub1 -1)) ;|  -  |;
  99.          ((member po '(82 114)) (sub1 "Dimstyle")) ;|  R  r  |;
  100.          ((member po '(13 32)) (setq g 0)) ;|  space  enter  |;
  101.        )
  102.       )
  103.       ((= code 25) (setq g 0)) ;| #mouse #right-click |;
  104.     )
  105.   )
  106.   (princ)
  107. )