Author Topic: Getting a boundingbox  (Read 2725 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Guest
Getting a boundingbox
« on: January 13, 2006, 08:35:32 PM »
Good evening,
Could someone point me in the direction of getting a boundingbox for some attributed text in a block ???
It's been a while since I last wrote a lithp and I've forgotten a lot.  Jeff helped me put something together several months ago for a different project, so I've been doing some cut-n-paste actions to get this started, but I can't do lithp anymore.  Gotta start all over.

So anyways, this is what I have so far:
Code: [Select]
(defun c:km (/ )
  (vl-load-com)
  (setq cdwg (vla-get-activedocument (vlax-get-acad-object));get the drawing
        mspace (vla-get-modelspace cdwg);get modelspace
        blks (vla-get-blocks cdwg);get the blocks collection
  )
  (setq blok (nentsel))

;;;;;  I know I need to convert something here
;;;;;  and if the block is rotated 45 or 60 degrees, there's another action needed.

  (vla-getboundingbox blok 'll 'ur);get the block's physical limits
  (setq ll (vlax-safearray->list ll ));convert lower left corner to a list
  (setq ur (vlax-safearray->list ur ));convert upper right corner to a list
;create a point list a little lower & longer than the actual text position
  (setq pt1 (list (- (car ll) 0.0625) (- (cadr ll) 0.0625) (caddr ll)))
  (setq pt2 (list (+ (car ur) 0.0625) (- (cadr ll) 0.0625) (caddr ur)))

  (command "rectang" pt1 pt2)
)

thanks,

uncoolperson

  • Guest
Re: Getting a boundingbox
« Reply #1 on: January 14, 2006, 01:16:21 AM »
wouldn't ss-extents work for this?

(acet-geom-ss-extents sset)

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Getting a boundingbox
« Reply #2 on: January 14, 2006, 09:14:42 AM »
Some of my apps need to draw 3DFaces behind text or attributes. To do this, I use this functions:
Code: [Select]
;
; == Function MeDraw3DFace
; Draws 3DFaces to hide objects behind text and attributes.
; Arguments [Type]:
;   Obj = Block or Text [VLA_OBJECT]
;   Gap = Gap distance around text [REAL]
;   Lay = Layer name [STR]
;   Spc = Model/paper space object [VLA_OBJECT]
; Return [Type]:
;   > Null
; Notes:
;   - None
;
(defun MeDraw3DFace (Obj Gap Lay Spc / AttLst InsPnt ObjNme PntLst TmpObj)
 (setq ObjNme (vla-get-ObjectName Obj))
 (if (or
      (eq ObjNme "AcDbBlockReference")
      (eq ObjNme "AcDbMInsertBlock")
     )
  (progn
   (setq AttLst (append
                 (vlax-invoke Obj 'GetAttributes)
                 (vlax-invoke Obj 'GetConstantAttributes)
                )
   )
   (foreach memb AttLst
    (if (eq (vlax-get-property memb "Constant") :vlax-true)
     (setq InsPnt (vlax-get Obj 'InsertionPoint))
     (setq InsPnt (list 0.0 0.0 0.0))
    )
    (if (not (eq (vla-get-TextString memb) ""))
     (progn
      (setq PntLst (MeGetTextBox memb Gap)
            TmpObj (vla-Add3DFace
                    Spc
                    (vlax-3d-point (mapcar '+ (nth 0 PntLst) InsPnt))
                    (vlax-3d-point (mapcar '+ (nth 1 PntLst) InsPnt))
                    (vlax-3d-point (mapcar '+ (nth 2 PntLst) InsPnt))
                    (vlax-3d-point (mapcar '+ (nth 3 PntLst) InsPnt))
                   )
      )
      (vla-put-Layer TmpObj Lay)
     )
    )
   )
  )
  (if (not (eq (vla-get-TextString memb) ""))
   (progn
    (setq PntLst (MeGetTextBox Obj Gap)
          TmpObj (vla-Add3DFace
                  Spc
                  (vlax-3d-point (nth 0 PntLst))
                  (vlax-3d-point (nth 1 PntLst))
                  (vlax-3d-point (nth 2 PntLst))
                  (vlax-3d-point (nth 3 PntLst))
                 )
    )
    (vla-put-Layer TmpObj Lay)
   )
  )
 )
 (princ)
)
;
; == Function MeGetTextBox
; Returns the boundingbox information of text or attribute.
; Arguments [Type]:
;   Obj = Text/Attribute object [VLA-OBJECT]
;   Gap = Gap distance around text [REAL]
; Return [Type]:
;   > Point list [LIST]
; Notes:
;   - None
;
(defun MeGetTextBox (Obj Gap / CosRot GapFac InsAng InsPnt LltPnt SinRot
                               TxtEnt UrtPnt)
 (setq TxtEnt (entget (vlax-vla-object->ename Obj))
       InsPnt (vlax-get Obj 'InsertionPoint)
       InsAng (vla-get-Rotation Obj)
       GapFac (* (vla-get-Height Obj) Gap)
       GapFac (sqrt (* (* GapFac GapFac) 2.0))
       SinRot (sin InsAng)
       CosRot (cos InsAng)
       LltPnt (car (textbox TxtEnt))
       UrtPnt (cadr (textbox TxtEnt))
 )
 (list
  (polar
   (list
    (+ (car  InsPnt) (- (* (car LltPnt) CosRot) (* (cadr LltPnt) SinRot)))
    (+ (cadr InsPnt) (+ (* (car LltPnt) SinRot) (* (cadr LltPnt) CosRot)))
    0.0
   )
   (+ InsAng (* 1.25 pi))
   GapFac
  )
  (polar
   (list
    (+ (car  InsPnt) (- (* (car UrtPnt) CosRot) (* (cadr LltPnt) SinRot)))
    (+ (cadr InsPnt) (+ (* (car UrtPnt) SinRot) (* (cadr LltPnt) CosRot)))
    0.0
   )
   (+ InsAng (* 1.75 pi))
   GapFac
  )
  (polar
   (list
    (+ (car  InsPnt) (- (* (car UrtPnt) CosRot) (* (cadr UrtPnt) SinRot)))
    (+ (cadr InsPnt) (+ (* (car UrtPnt) SinRot) (* (cadr UrtPnt) CosRot)))
    0.0
   )
   (+ InsAng (* 0.25 pi))
   GapFac
  )
  (polar
   (list
    (+ (car  InsPnt) (- (* (car LltPnt) CosRot) (* (cadr UrtPnt) SinRot)))
    (+ (cadr InsPnt) (+ (* (car LltPnt) SinRot) (* (cadr UrtPnt) CosRot)))
    0.0
   )
   (+ InsAng (* 0.75 pi))
   GapFac
  )
 )
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Joe Burke

  • Guest
Re: Getting a boundingbox
« Reply #3 on: January 16, 2006, 08:49:52 AM »
Hangman,

Just a thought, which might be obvious if you've studied Jürg's code. Notice he uses the textbox function rather than vla-getboundingbox. The latter will not return the points you want when the text/attribute is rotated.