Author Topic: Export volumes and bounding box upper limit for 3D Solids  (Read 2322 times)

0 Members and 1 Guest are viewing this topic.

densan

  • Mosquito
  • Posts: 12
Export volumes and bounding box upper limit for 3D Solids
« on: December 20, 2019, 10:52:40 AM »
Hello Forum,
In an attempt to create some code to list the volumes of 3D solids with their corresponding top max elevation and export it to a text file, I hit a wall.
I am struggling putting together the program and I would like some guidance into achieving my goal. Also, I included a sample file of the solids for testing.

Any help would be much appreciated.
Thank you,

Sample of report required:
Top Elevation                   Volume   
----------------------------------------------
6575.20                          1621409.29
6560.70                          1531821.51
6545.90                          1318859.04

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ;; List volume and top elevation of selected 3D Solids and
  3. ;; export results to an external text file
  4. ;;
  5. ;;
  6.  
  7. ;; Swamp forum
  8. ;; Volume of a 3D solid by MP
  9. ;;
  10. (defun c:solvol ()
  11.   (setq a      0
  12.         volume 0
  13.         ss     (ssget '((0 . "3dsolid")))
  14.   )
  15.   (if ss
  16.     (progn
  17.       (setq n (1- (sslength ss)))
  18.       (while (>= n 0)
  19.         (setq solidobj (vlax-ename->vla-object (ssname ss n)))
  20.         (if (= (vla-get-objectName solidobj) "AcDb3dSolid")
  21.           (setq volume (vla-get-volume solidobj))
  22.         )
  23.         (setq a (+ a volume)
  24.               n (1- n)
  25.         )
  26.       )
  27.       ;;close while
  28.     )
  29.     ;;close progn
  30.     (alert "\nNo Solids selected!")
  31.   )
  32.   ;;close if
  33.   (princ (strcat "\nSolid volume = " (rtos a 2 6)))
  34.  
  35. ;;
  36. ;; Autodesk ActiveX reference
  37. ;; How to get the bounding box top Z value for each solid?
  38. ;;
  39. (vla-GetBoundingBox solidobj 'minExt 'maxExt)
  40. (setq minExt (vlax-safearray->list minExt)
  41.       maxExt (vlax-safearray->list maxExt))
  42.  
  43. ;;
  44. ;; Export volumes to text file
  45. ;;
  46. (setq idk (getfiled "I stink at LISP" "" "txt" 1))
  47.   (princ)
  48. )
  49.  

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Export volumes and bounding box upper limit for 3D Solids
« Reply #1 on: December 20, 2019, 11:18:42 AM »
Try this .. although not sure if bounding box is the correct way to go about it .. see if you can figure out how to write this to a file. There are numerous examples.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ o r s)
  2.   (cond ((setq s (ssget '((0 . "3DSOLID"))))
  3.          (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  4.            (vla-getboundingbox (setq o (vlax-ename->vla-object x)) 'a 'b)
  5.            (setq r (cons (list (apply 'max (mapcar 'caddr (mapcar 'vlax-safearray->list (list a b))))
  6.                                (vla-get-volume o)
  7.                          )
  8.                          r
  9.                    )
  10.            )
  11.          )
  12.          (mapcar 'print (vl-sort r '(lambda (r j) (< (car r) (car j)))))
  13.         )
  14.   )
  15.   (princ)
  16. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

densan

  • Mosquito
  • Posts: 12
Re: Export volumes and bounding box upper limit for 3D Solids
« Reply #2 on: December 20, 2019, 11:50:39 AM »
Thank you very much ronjonp,
I will study the code and get there. About the bounding box approach, it was just something I picked up during my search of code.
You think a different method would be better to get the top elevation of the 3D solid?
Thanks again,  :-)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Export volumes and bounding box upper limit for 3D Solids
« Reply #3 on: December 20, 2019, 11:56:35 AM »
Glad to help.  :-) Bounding box might be ok .. I don't do 3D much so would have to defer to someone else to verify.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Export volumes and bounding box upper limit for 3D Solids
« Reply #4 on: December 20, 2019, 02:29:13 PM »
Glad to help.  :-) Bounding box might be ok .. I don't do 3D much so would have to defer to someone else to verify.

It depends what you assume to be max elevation... If you are observing entities from WCS, then ordinary simple boundingbox approach will be fine... If you take some different UCS as base of observing, then you'll have to account for that and use boundingbox method in combination with transformed 3DSOLID entity from UCS to WCS by using (vla-transformby VLA-OBJECT-3DSOLID (vlax-tmatrix matrix-inverseUCSmatrix))...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube