Author Topic: Min Bounding Box of INSERT  (Read 7714 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Min Bounding Box of INSERT
« Reply #15 on: April 06, 2017, 12:22:32 AM »
Refri,

Thanks for your comments.
Perhaps you could send a Personal Message to the supplier and give him your email address.

Generally we are wary of executable and compiled files being distributed here.
The Swamp is primarily a resource for peer support and as such we prefer code postings are source code ( or source snippets).

Unfortunately the potential dangers in VB6 EXE files or compiled lisp files is not discoverable by a virus scan.

Personally I find teaching/helping users code (and find solutions) for themselves  more rewarding for everyone  than turning the site into a dumping ground for anonymous unsecured programs.

Regards,
Kerry
« Last Edit: April 06, 2017, 12:29:10 AM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Min Bounding Box of INSERT
« Reply #16 on: April 06, 2017, 12:42:39 AM »
Hi

Maratovich's solution seems OK but I need the LISP code, not VB6.
Also, I need bounding box of only the Text Part "JJ-1" and not the entire block.
Thanks.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Min Bounding Box of INSERT
« Reply #17 on: April 06, 2017, 09:13:34 AM »
Hi
...
Also, I need bounding box of only the Text Part "JJ-1" and not the entire block.
...
You should revise your example picture in the first post "Third Image : The Bounding Box which I want"  .. the current one shows the desired result as the entire block bounding box.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ChrisCarlson

  • Guest
Re: Min Bounding Box of INSERT
« Reply #18 on: April 06, 2017, 10:04:01 AM »
Hi

Maratovich's solution seems OK but I need the LISP code, not VB6.
Also, I need bounding box of only the Text Part "JJ-1" and not the entire block.
Thanks.

Couldn't that just be summed up to

Code - Auto/Visual Lisp: [Select]

and

Code - Auto/Visual Lisp: [Select]
  1. vlax-safeArray->list

maratovich

  • Mosquito
  • Posts: 4
Re: Min Bounding Box of INSERT
« Reply #19 on: April 06, 2017, 11:37:09 AM »
 :whistling:

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Min Bounding Box of INSERT
« Reply #20 on: April 06, 2017, 11:38:03 AM »
Master_Shake,

Since the text attribute is within a Block (which is not exploded), we cannot use vla-getBoundingBox function on it.
It gives following error :- "Automation Error. Null extents".

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Min Bounding Box of INSERT
« Reply #21 on: April 06, 2017, 12:14:24 PM »
Master_Shake,

Since the text attribute is within a Block (which is not exploded), we cannot use vla-getBoundingBox function on it.
It gives following error :- "Automation Error. Null extents".

Not true. My guess is you're encountering an attribute with no textstring assigned. You merely need to trap the attempt to get said bounding box and branch accordingly.

Code: [Select]
(defun _GetBoundingBox ( object / a b )
    (vl-catch-all-apply 'vlax-invoke-method (list object 'GetBoundingBox 'a 'b))
    (if a (mapcar 'vlax-safearray->list (list a b)))
)

(if (setq bb (_GetBoundingBox obj))
    (then)
    (else)
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Min Bounding Box of INSERT
« Reply #22 on: April 06, 2017, 12:36:00 PM »
Since you're only looking for the bounding box of the attribute reference, here is a Vanilla solution to consider:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ent enx idx sel )
  2.     (if (setq sel (ssget '((0 . "INSERT") (66 . 1))))
  3.         (repeat (setq idx (sslength sel))
  4.             (setq ent (entnext (ssname sel (setq idx (1- idx))))
  5.                   enx (entget ent)
  6.             )
  7.             (while (= "ATTRIB" (cdr (assoc 0 enx)))
  8.                 (entmake
  9.                     (append
  10.                        '(
  11.                             (000 . "LWPOLYLINE")
  12.                             (100 . "AcDbEntity")
  13.                             (100 . "AcDbPolyline")
  14.                             (090 . 4)
  15.                             (070 . 1)
  16.                         )
  17.                         (list (cons 38 (cadddr (assoc 10 enx))))
  18.                         (mapcar '(lambda ( p ) (cons 10 p)) (LM:textbox ent))
  19.                         (list (assoc 210 enx))
  20.                     )
  21.                 )
  22.                 (setq ent (entnext ent)
  23.                       enx (entget  ent)
  24.                 )
  25.             )
  26.         )
  27.     )
  28.     (princ)
  29. )
  30.  
  31. ;; Text Box  -  Lee Mac
  32. ;; A wrapper for the textbox function to return the bounding box of a Text or Attrib (in OCS)
  33.  
  34. (defun LM:textbox ( ent / ins mat rot )
  35.     (setq ent (entget ent)
  36.           ins (cdr (assoc 10 ent))
  37.           rot (cdr (assoc 50 ent))
  38.           mat (list
  39.                   (list (cos rot) (sin (- rot)) 0.0)
  40.                   (list (sin rot) (cos rot)     0.0)
  41.                  '(0.0 0.0 1.0)
  42.               )
  43.     )
  44.     (mapcar '(lambda ( x ) (mapcar '+ (mxv mat x) ins)) (LM:points->boundingbox (textbox ent)))
  45. )
  46.  
  47. ;; Points to Bounding Box  -  Lee Mac
  48. ;; Returns the rectangular extents of a supplied point list
  49.  
  50. (defun LM:points->boundingbox ( lst )
  51.     (   (lambda ( l )
  52.             (mapcar '(lambda ( a ) (mapcar '(lambda ( b ) ((eval b) l)) a))
  53.                '(
  54.                     (caar   cadar)
  55.                     (caadr  cadar)
  56.                     (caadr cadadr)
  57.                     (caar  cadadr)
  58.                 )
  59.             )
  60.         )
  61.         (mapcar '(lambda ( f ) (apply 'mapcar (cons f lst))) '(min max))
  62.     )
  63. )
  64.  
  65. ;; Matrix x Vector  -  Vladimir Nesterovsky
  66. ;; Args: m - nxn matrix, v - vector in R^n
  67.  
  68. (defun mxv ( m v )
  69.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  70. )
  71.  

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Min Bounding Box of INSERT
« Reply #23 on: April 06, 2017, 12:39:22 PM »
Very nice Lee  8)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Min Bounding Box of INSERT
« Reply #24 on: April 06, 2017, 12:41:38 PM »
Thanks Ron  :-)

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Min Bounding Box of INSERT
« Reply #25 on: April 06, 2017, 01:18:22 PM »
Once again Lee Mac to the rescue. Your code works perfect.
Thanks a lot Lee.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Min Bounding Box of INSERT
« Reply #26 on: April 06, 2017, 02:36:25 PM »
I like your subfunctions Lee,
Although for LM:points->boundingbox wouldnt a more adequate function naming be LM:points->4ptboundingbox ?
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Min Bounding Box of INSERT
« Reply #27 on: April 06, 2017, 04:54:37 PM »
Once again Lee Mac to the rescue. Your code works perfect.
Thanks a lot Lee.

You're welcome mailmaverick, I'm glad it helps.

I like your subfunctions Lee,
Although for LM:points->boundingbox wouldnt a more adequate function naming be LM:points->4ptboundingbox ?

Thanks Grrr1337; the boundingbox is rectangular hence 4 points is implied.  :-)