Author Topic: getting annotative scale factor of the object  (Read 2672 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
getting annotative scale factor of the object
« on: May 09, 2017, 12:42:53 PM »
I am searching for a function that would get the annotative scale (scales) factor of the object.
I mean not the scale itself, but the factor, similar to cannoscalevalue variable, but one that the object itself posses (if it does).
Can it be red from the object directly?
I have a function to get the list of annotative scales from the object, but how to proceed after it? For example if the scale is "1/4" = 1'-0", how to convert it to scale factor, which would be 0.0208333 in this case?

Code: [Select]
(defun GetAnnoScales (e / dict lst rewind res)
;;; Argument: the ename of an annotative object.
;;; Returns the annotative scales associated with the
;;; ename as a list of strings.
;;; Example: ("1:1" "1:16" "1:20" "1:30")
;;; Returns nil if the ename is not annotative.
;;; Can be used to test whether ename is annotative or not.
;;; Works with annotative objects: text, mtext, leader, mleader,
;;; dimension, block reference, tolerance and attribute.
;;; Based on code by Ian Bryant.
;;;Joe Burk
;;;http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-do-i-make-hatch-annotative-via-vlisp-almost-there/m-p/2080831   
;; Argument: an ename or vla-object.
;; Return T if object is annotative, otherwise nil.

    (if
      (and
        e
        (setq dict (cdr (assoc 360 (entget e))))
        (setq lst (dictsearch dict "AcDbContextDataManager"))
        (setq lst
               (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES")
        ) ;_ end of setq
        (setq dict (cdr (assoc -1 lst)))
      ) ;_ end of and
       (progn
         (setq rewind t)
         (while (setq lst (dictnext dict rewind))
           (setq e      (cdr (assoc 340 lst))
                 res    (cons (cdr (assoc 300 (entget e))) res)
                 rewind nil
           ) ;_ end of setq
         ) ;_ end of while
       ) ;_ end of progn
    ) ;_ end of if
    (reverse res)
  )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: getting annotative scale factor of the object
« Reply #1 on: May 09, 2017, 01:40:25 PM »
Try this:

Code - Auto/Visual Lisp: [Select]
  1. (defun getannoscales (e / el dict lst rewind res)
  2. ;;; Argument: the ename of an annotative object.
  3. ;;; Returns the annotative scales associated with the
  4. ;;; ename as a list of strings.
  5. ;;; Example: ("1:1" "1:16" "1:20" "1:30")
  6. ;;; Returns nil if the ename is not annotative.
  7. ;;; Can be used to test whether ename is annotative or not.
  8. ;;; Works with annotative objects: text, mtext, leader, mleader,
  9. ;;; dimension, block reference, tolerance and attribute.
  10. ;;; Based on code by Ian Bryant.
  11. ;;;Joe Burk
  12. ;;;http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-do-i-make-hatch-annotative-via-vlisp-almost-there/m-p/2080831    
  13.   ;; Argument: an ename or vla-object.
  14.   ;; Return T if object is annotative, otherwise nil.
  15.   (if (and e
  16.            (setq dict (cdr (assoc 360 (entget e))))
  17.            (setq lst (dictsearch dict "AcDbContextDataManager"))
  18.            (setq lst (dictsearch (cdr (assoc -1 lst)) "ACDB_ANNOTATIONSCALES")) ;_ end of setq
  19.            (setq dict (cdr (assoc -1 lst)))
  20.       ) ;_ end of and
  21.     (progn (setq rewind t)
  22.            (while (setq lst (dictnext dict rewind))
  23.              (setq e      (cdr (assoc 340 lst))
  24.                    ;; RJP 5.9.2017 - added decimal value to list
  25.                    res    (cons (cons (cdr (assoc 300 (setq el (entget e))))
  26.                                       (/ (cdr (assoc 140 el)) (cdr (assoc 141 el)))
  27.                                 )
  28.                                 res
  29.                           )
  30.                    rewind nil
  31.              ) ;_ end of setq
  32.            ) ;_ end of while
  33.     ) ;_ end of progn
  34.   ) ;_ end of if
  35.   (reverse res)
  36. )
  37.  
  38.  
  39.  ;|(getannoscales (car (entsel)))
  40. ;; Result
  41. (("1:1" . 1.0)
  42.   ("3/8\" = 1'-0\"" . 0.03125)
  43.   ("1/2\" = 1'-0\"" . 0.0416667)
  44.   ("3/4\" = 1'-0\"" . 0.0625)
  45.   ("1/128\" = 1'-0\"" . 0.000651042)
  46.   ("1/64\" = 1'-0\"" . 0.00130208)
  47.   ("1/32\" = 1'-0\"" . 0.00260417)
  48.   ("1/16\" = 1'-0\"" . 0.00520833)
  49.   ("3/32\" = 1'-0\"" . 0.0078125)
  50.   ("1/8\" = 1'-0\"" . 0.0104167)
  51.   ("3/16\" = 1'-0\"" . 0.015625)
  52.   ("1/4\" = 1'-0\"" . 0.0208333)
  53. )|;
« Last Edit: May 09, 2017, 03:00:29 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Red Nova

  • Newt
  • Posts: 69
Re: getting annotative scale factor of the object
« Reply #2 on: May 09, 2017, 03:55:51 PM »
ronjonp
Thanks, that works!  :-) Looks like I have to study definition data and association lists a bit. Where can one see what is represented by each key when using assoc? For example you used assoc 140 and 141, where did you check who is who?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: getting annotative scale factor of the object
« Reply #3 on: May 09, 2017, 04:02:37 PM »
ronjonp
Thanks, that works!  :) Looks like I have to study definition data and association lists a bit. Where can one see what is represented by each key when using assoc? For example you used assoc 140 and 141, where did you check who is who?
Just did a bit of snooping :) .. BTW .. it might be better to divide (/ 141 140) .. then you'd get the scale.
Code - Auto/Visual Lisp: [Select]
  1. (("3/8\" = 1'-0\"" . 32.0) ("6\" = 1'-0\"" . 2.0) ("1/4\" = 1'-0\"" . 48.0))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: getting annotative scale factor of the object
« Reply #4 on: May 10, 2017, 02:49:14 AM »
I am searching for a function that would get the annotative scale (scales) factor of the object.
I mean not the scale itself, but the factor, similar to cannoscalevalue variable, but one that the object itself posses (if it does).
An old set of these I did quite some time ago: https://sourceforge.net/p/caddons/code/HEAD/tree/General/Scales.LSP

You're probably looking for the Scales:Entity_List function in that file, though it uses some of the other functions as helpers.

BTW, another utility I made helping to "drill" into these dictionary items (to find out what's inside these even from a selected entity): https://sourceforge.net/p/caddons/code/HEAD/tree/General/DictEdit.lsp
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Red Nova

  • Newt
  • Posts: 69
Re: getting annotative scale factor of the object
« Reply #5 on: May 10, 2017, 02:02:36 PM »
ronjonp OK, thanks.

irneb
Quote
BTW, another utility I made helping to "drill" into these dictionary items (to find out what's inside these even from a selected entity): https://sourceforge.net/p/caddons/code/HEAD/tree/General/DictEdit.lsp
That's a hell of a code...  I thought that is something to be on the surface, but looks like not....