TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Amsterdammed on November 22, 2011, 08:10:48 AM

Title: bounding box of a rotated 3dsolid
Post by: Amsterdammed on November 22, 2011, 08:10:48 AM
Hello,
I'm working on a program to define the make a section on each of the walls in our building we need to show. all fine as long as the walls (3solids) are parallel to the usc, i use the bounding box.
 
Can i define a ucs by a 3dsolid with lisp (through "face" maybe, but how to select by lisp)
and will the bounding box give the correct "footprint of the wall when in object ucs with the wall?

Thanks
Title: Re: bounding box of a rotated 3dsolid
Post by: Lee Mac on November 22, 2011, 08:23:38 AM
http://www.theswamp.org/index.php?topic=32179.0 (http://www.theswamp.org/index.php?topic=32179.0)
Title: Re: bounding box of a rotated 3dsolid
Post by: Amsterdammed on November 22, 2011, 08:47:02 AM
Lee,

i get an error when i try to load obb arx. And honestly, i was hoping for a solution in vlisp.

Title: Re: bounding box of a rotated 3dsolid
Post by: gile on November 22, 2011, 11:31:28 AM
Hi,

It may be (very) difficult to get 3d solids data in plain (Visual) LISP.
If you're using A2009 or later, you can try the .NET defined gc-Brep (http://www.theswamp.org/index.php?topic=39278.msg445148#msg445148) Lisp function.
Title: Re: bounding box of a rotated 3dsolid
Post by: Amsterdammed on November 22, 2011, 05:55:33 PM
gile

thanks, but i have no clue how to use that?
what do  have to load and how do  i start it?

Thanks
Bernd
Title: Re: bounding box of a rotated 3dsolid
Post by: wizman on November 28, 2011, 10:55:36 PM

Through here, i used face selection, hope it helps:

http://www.cadtutor.net/forum/showthread.php?43375-3d-Objects-Volume-LISP-required
Title: Re: bounding box of a rotated 3dsolid
Post by: LE3 on November 28, 2011, 11:27:41 PM
Lee,

i get an error when i try to load obb arx. And honestly, i was hoping for a solution in vlisp.

What AutoCAD version do you use?
If i get some time, will try to update my project - But looks like what Gile/WizMan did (open-source) already works - so please give that a try.
Title: Re: bounding box of a rotated 3dsolid
Post by: BlackCADDER on November 30, 2011, 01:57:02 AM
This may help or give you ideas, or not, maybe. works for me (sometimes)

This is how I work out length of a beam (drawn as a 3dsolid).
My beam function stores 2 points along length of beam as xdata.
The length function retrieves the 2 points (pt3 and pt4) and does it's thing as
shown. The real clever stuff is done by the functions written by THESWAMP lispmasters

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:test ()
;;;
            (setq StlEnt (car (entsel "\nPick beam")))
            (setq pt3 '(471.3056 380.3116 0.0000))
            (setq pt4 '(221.3056 813.3243 0.0000))
;;;
            (command ".ucs" "")
            (command ".ucs" "3" pt4 pt3 (polar pt3 (+ (Dmdtr 90) (angle pt3 pt4)) 10))
            (setq boxlst (ucs-bbox StlEnt))
            (setq xlst (mapcar '(lambda (pt) (car pt)) boxlst))
            (setq x_max (apply 'max xlst))
            (setq x_min (apply 'min xlst))
            (setq len (- x_max x_min))
            (command ".ucs" "p")
            (command ".ucs" "p")
            len
)
;;;=============================================================================
(defun DMDtr (Y) (* pi (/ y 180.0)))
;;;=============================================================================
;; Doug C. Broad, Jr.
;; can be used with vla-transformby to
;; transform objects from the UCS to the WCS
;; transform objects from the WCS to the UCS
(defun UCS2WCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
'(lambda (vector origin)
   (append (trans vector 1 0 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 0 1)
      )
      (list '(0 0 0 1))
    )
  )
)

(defun WCS2UCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
'(lambda (vector origin)
   (append (trans vector 0 1 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 1 0)
      )
      (list '(0 0 0 1))
    )
  )
)

;; UCS-BBOX (gile)
;; Returns the UCS coordinates of the object bounding box about UCS
;;
;; Argument
;; obj : a graphical object (ename or vla-object)
;;
;; Return
;; a list of left lower point and right upper point UCS coordinates

(defun ucs-bbox (obj / space bb minpoint maxpoint line lst)
  (vl-load-com)
  (and (= (type obj) 'ENAME)
       (setq obj (vlax-ename->vla-object obj))
  )
  (vla-TransformBy obj (UCS2WCSMatrix))
  (setq bb (vla-getboundingbox obj 'minpoint 'maxpoint))
  (vla-TransformBy obj (WCS2UCSMatrix))
  (list
    (vlax-safearray->list minpoint)
    (vlax-safearray->list maxpoint)
  )
)       
[code]
Title: Re: bounding box of a rotated 3dsolid
Post by: Amsterdammed on November 30, 2011, 05:51:31 AM
The real problem is that i want to do this with a selection set, so multiple items. if i had only a single one, i had no problem, set UCS to face of the solid and had my direction for the bounding box, or not?

but how can i do this without picking the solid???
Title: Re: bounding box of a rotated 3dsolid
Post by: BlackCADDER on November 30, 2011, 09:16:29 AM
If you store orientation points in XDATA in your 3dsolids,

(setq SS1 (ssget "X" (list (list -3 (list appnam)))))

will create a selection set of all the objects with your XDATA. 'appnam' is the XDATA application name.

That is how I do it.
Title: Re: bounding box of a rotated 3dsolid
Post by: Amsterdammed on December 02, 2011, 05:18:25 AM
Sure,

but i need to store them first.
I situation is that we get 3d solids out of a revit model form our builder and then we work with that. all our needed holes in those walls i wanted to find automated. Since we get an permanent update stream i can not store in the solids because they a suspect to update.
Title: Re: bounding box of a rotated 3dsolid
Post by: SEANT on December 02, 2011, 05:30:15 AM
I posted an ActiveX based method (VBA) here:

http://www.theswamp.org/index.php?topic=21524

The tester routine, “SolidDims_Main()”, ask the user to select a solid but the methodology is not based on a selected face (In other words, it could be set up for Selection Sets).
Title: Re: bounding box of a rotated 3dsolid
Post by: SEANT on December 02, 2011, 05:36:58 AM
Would the solids in question always be set upright?  It seems like that would be the case with walls. 

If so, then the routine I just linked is unnecessarily complicated.  It was set up to coordinated extrusion with any arbitrary orientation.