Author Topic: Get minimum bounding box of attribute  (Read 1286 times)

0 Members and 1 Guest are viewing this topic.

ziele_o2k

  • Newt
  • Posts: 49
Get minimum bounding box of attribute
« on: October 07, 2016, 04:46:00 PM »
Hi, how to get minimum bounding box of rotated attribute to the WCS.
When attribute isn't rotated to the WCS I can use:
http://www.lee-mac.com/boundingbox.html
I tried with http://www.lee-mac.com/minboundingbox.html but this don't work with attributes.

Any help ?

ziele_o2k

  • Newt
  • Posts: 49
Re: Get minimum bounding box of attribute
« Reply #1 on: October 08, 2016, 07:15:56 AM »
Solved (not for multiline atts):

Code - Auto/Visual Lisp: [Select]
  1. (defun PZ:AttBox ( ent off / enx rot bpt lst )
  2.   (if
  3.     (and
  4.       (= "ATTRIB" (cdr (assoc 0 (setq enx (entget ent)))))
  5.       (not (= "Embedded Object" (cdr (assoc 101 enx))))
  6.     )
  7.     (progn
  8.       (setq
  9.         bpt (cdr (assoc 10 enx))
  10.         rot (cdr (assoc 50 enx))
  11.         lst (TextBoxExt enx T)
  12.         lst
  13.         (list
  14.           (list (- (caar  lst) off) (- (cadar  lst) off)) (list (+ (caadr lst) off) (- (cadar  lst) off))
  15.           (list (+ (caadr lst) off) (+ (cadadr lst) off)) (list (- (caar  lst) off) (+ (cadadr lst) off))
  16.         )
  17.       )
  18.       (if lst
  19.         (progn
  20.           (setq lst
  21.             (
  22.               (lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) bpt)) lst))
  23.               (list
  24.                 (list (cos rot) (sin (- rot)) 0.0)
  25.                 (list (sin rot) (cos rot)     0.0)
  26.                 '(0.0 0.0 1.0)
  27.               )
  28.             )
  29.           )
  30.           lst
  31.         )
  32.       )
  33.     )
  34.     (princ "\nTry again.")
  35.   )
  36. )
  37.  
  38. ;; Matrix x Vector - Vladimir Nesterovsky
  39. ;; Args: m - nxn matrix, v - vector in R^n
  40.  
  41. (defun mxv ( m v )
  42.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  43. )
  44.  
  45. ; =========================================================================================== ;
  46. ;  enx   [LIST] - An entity definition list defining a text object,                           ;
  47. ;                 in the format returned by entget                                            ;
  48. ;  flg  [T/nil] - nil = standard textbox function procedure                                   ;
  49. ;                       (ignore spaces at start and end of string)                            ;
  50. ;                 T   = extended textbox function                                             ;
  51. ;                       (do not ignore spaces at start and end of string)                     ;
  52. ; =========================================================================================== ;
  53.  
  54. (defun TextBoxExt ( enx flg / textboxs )
  55.   (defun textboxs ( enx str )
  56.     (textbox (subst (cons 1 str) (assoc 1 enx) enx))
  57.   )
  58.   (if
  59.     (and flg (wcmatch (cdr (assoc 1 enx)) " *,* "))
  60.     (
  61.       (lambda ( a b ) (list (car a) (cons (- (caadr a) (caadr b)) (cdadr a))))
  62.       (textboxs enx (strcat "-" (cdr (assoc 1 enx)) "-"))
  63.       (textboxs enx "--")
  64.     )
  65.     (textbox enx)
  66.   )
  67. )
As always thanks to Lee Mac
« Last Edit: October 08, 2016, 07:24:56 AM by ziele-o2k »