Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filtering solid by volume

3 REPLIES 3
Reply
Message 1 of 4
chorch123
452 Views, 3 Replies

Filtering solid by volume

Hello,

I have an imported 3D model with hundreds of solids. The problem is that all solids are in the same layer.

Is there any option to filter them (as a prelimanary step to sort them) by their volume, as there a lot of them that are the same (such as bolts, small plates and so on)?

Thank you very much

Jorge

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: chorch123


@chorch123 wrote:

Hello,

I have an imported 3D model with hundreds of solids. The problem is that all solids are in the same layer.

Is there any option to filter them (as a prelimanary step to sort them) by their volume, as there a lot of them that are the same (such as bolts, small plates and so on)?

Thank you very much

Jorge


Kind of brute-force, and without the usual enhancements, but this seems to work, in limited testing:

 

;; SortSolidsBySize.lsp ; [command name: SSBS]
;; To create a list of selected 3D Solids, pairing their entity names with
;;   their volumes, and sorted by volume from smallest to largest.
;; Kent Cooper, 13 May 2014
(defun C:SSBS (/ ss sol propfile propline)
  (setq ss (ssget '((0 . "3DSOLID"))))
  (repeat (setq inc (sslength ss))
    (setq sol (ssname ss (setq inc (1- inc))))
    (command "_.massprop" sol "" "_yes" "C:/SSBStemp.mpr")
    (setq
      propfile (open "C:/SSBStemp.mpr" "r")
      propline (read-line propfile)
    ); setq
    (while (/= (substr propline 1 1) "V") (setq propline (read-line propfile))); find the Volume line
    (setq solidlist
      (cons
        (list sol (atof (vl-string-left-trim "Volume: " propline))); take the heading off, convert to number
        solidlist
      ); cons
    ); setq
    (close propfile)
    (vl-file-delete "C:/SSBStemp.mpr")
  ); repeat
  (setq sortedlist (vl-sort solidlist '(lambda (x y) (< (cadr x) (cadr y))))); use > instead to sort largest-to-smallest
); defun

 

It leaves you both the sortedlist variable in size order and the [unsorted] solidlist variable, but you can localize the latter so it won't stick around, if you have no use for it.

 

If there's a way I couldn't find to extract the results of MASSPROP from a System Variable or something, rather than going through a text file, that could streamline the whole thing.

Kent Cooper, AIA
Message 3 of 4
dgorsman
in reply to: Kent1Cooper

Volume of 3dSolid entities is available as a vla-property.  It doesn't show up in the Properties palette, so it can't be used with a conventional selection method.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 4
Kent1Cooper
in reply to: dgorsman


@dgorsman wrote:

Volume of 3dSolid entities is available as a vla-property.  ....


So it is!  I was looking only at the MASSPROP command approach, because it was the only thing I was aware of that got at the volume, but apparently not....  That makes it a lot simpler -- no external file, etc.:

 

;; SortSolidsBySize.lsp ; [command name: SSBS]
;; To create a list of selected 3D Solids, pairing their entity names with
;;   their volumes, and sorted by volume from smallest to largest.
;; Kent Cooper, 13 May 2014 [with simplification help from dgorsman]
(defun C:SSBS (/ ss sol propfile propline)
  (setq ss (ssget '((0 . "3DSOLID"))))
  (repeat (setq inc (sslength ss))
    (setq
      sol (ssname ss (setq inc (1- inc)))
      solidlist
        (cons
          (list sol (vla-get-Volume (vlax-ename->vla-object sol)))
          solidlist
        ); cons & solidlist
    ); setq
  ); repeat
  (setq sortedlist (vl-sort solidlist '(lambda (x y) (< (cadr x) (cadr y))))); use > instead to sort largest-to-smallest
); defun

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost