Jump to content

How to get the minimum bounding box of the rotation angle primitive


Recommended Posts

Posted
(vl-load-com)
(defun c:test (/ obj sel spc tc wnm)
  (setq	spc
	 (vlax-get-property
	   (vla-get-activedocument (vlax-get-acad-object))
	   (if (= 1 (getvar 'cvport))
	     'paperspace
	     'modelspace
	   )
	 )
  )
  (setq p1 (getpoint "p1"))
  (setq p2 (getpoint "p2"))
  (if (and (setq sel (ssget "c" p1 p2 (list '(0 . "INSERT"))))
	   (setq box (LM:ssboundingbox sel))
      )
    (progn
      (setq p4 (ap4 box))
      (setq obj
	     (vlax-invoke
	       spc
	       'addlightweightpolyline
	       (apply
		 'append
		 p4
	       )
	     )
      )
      (vla-put-closed obj :vlax-true)
      (vla-put-elevation obj (caddar box))


    )
  )


  (princ)
)
(vl-load-com)
(princ)

;; Selection Set Bounding Box - Lee Mac
;; returns a list of the lower left and upper right WCS coordinates of a
;; A rectangle encloses all objects in the provided selection set.
;; sel - [sel] returns the selection set of bounding boxes for which

(defun LM:ssboundingbox	(sel / idx llp ls1 ls2 obj urp)
  (setq obj (vlax-ename->vla-object (ssname sel 0)))
  (if (and (vlax-method-applicable-p obj 'getboundingbox)
	   (not	(vl-catch-all-error-p
		  (vl-catch-all-apply
		    'vla-getboundingbox
		    (list obj 'llp 'urp)
		  )
		)
	   )
      )
    (setq ls1 (mapcar 'min
		      (vlax-safearray->list llp)
		      (cond (ls1)
			    ((vlax-safearray->list llp))
		      )
	      )
	  ls2 (mapcar 'max
		      (vlax-safearray->list urp)
		      (cond (ls2)
			    ((vlax-safearray->list urp))
		      )
	      )
    )
  )

  (if (and ls1 ls2)
    (list ls1 ls2)
  )
)

;; Selection Set Bounding Box - Lee Mac

(defun ap4 (box)
  (mapcar
    '(lambda (x) (mapcar '(lambda (y) ((eval y) box)) x))
    '(
      (caar cadar)
      (caadr cadar)
      (caadr cadadr)
      (caar cadadr)
     )
  )
)

Hello everyone, I use Lee Mac's bounding box code, it always gets the primitive bounding with a positive angle, unfortunately, after rotating the primitive angle, or the bounding box is positive, which is not what I want , How can I get the minimum bounding box of the selection set, even if its angle is arbitrary, instead of getting a positive bounding box?20220316.thumb.png.51d32b93b274a66e5cf13e50005aa856.png

20220316.dwg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...