Search the Community
Showing results for tags 'calculate mass blocks'.
-
Calculate mass of Solids including ones in blocks.
CADkitt posted a topic in AutoLISP, Visual LISP & DCL
I frankenbuild 2 autolisp scripts to output the mass of a solid (in mm density is from steel 0.00782 g/mm^3/7820 kg/m^3 ) It also explodes all blocks and then undo that, so your blocks are unharmed, but this way it also uses the solids in those blocks. The volume code is from lee mac: http://www.cadtutor.net/forum/showthread.php?37358-how-to-Pick-the-Value-of-Volume The explode code is also from lee mac: http://www.cadtutor.net/forum/showthread.php?53107-Xplode-All-Blocks This is my franken build code: (remember output is from a part in mm) (defun c:vol (/ ss vol bset |cmdecho|) (vl-load-com) (SETQ |cmdecho| (GETVAR "cmdecho")) (SETVAR "cmdecho" 1) (COMMAND "undo" "begin") (c:ExplodeAllBlocks) (COMMAND "undo" "end") (if (setq ss (ssget '((0 . "3DSOLID")))) (progn (setq vol (apply '+ (vl-remove-if 'vl-catch-all-error-p (mapcar (function (lambda (x) (vl-catch-all-apply 'vla-get-volume (list x)))) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))))) (command "undo" "")(princ (strcat "\n<< Total Volume = " (rtos vol 2 2) " >>")) (setq volume (rtos vol 2 2)) )) (setq massa (* 0.00782 vol))) (PRINC (strcat "\n<<mass:" (rtos (/ massa 1000) 2 2) " kg >>")) (princ) (SETVAR "cmdecho" |cmdecho|) ) Explode block lisp from lee mac (defun c:ExplodeAllBlocks ( / *error* _StartUndo _EndUndo doc locked ss ) (vl-load-com) ;; © Lee Mac 2010 ;; Error Handler (defun *error* ( msg ) (if locked (mapcar (function (lambda ( l ) (vl-catch-all-apply 'vla-put-lock (list l :vlax-true)) ) ) locked ) ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) ;; Start an Undo Mark (_StartUndo (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ;; Unlock all Layers (vlax-for l (vla-get-layers doc) (if (eq :vlax-true (vla-get-lock l)) (progn (vla-put-lock l :vlax-false) (setq locked (cons l locked)) ) ) ) ;; Now lets explode 'em (if (ssget "_X" '((0 . "INSERT"))) (progn (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc)) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Explode (list obj)) ) (princ (strcat "\n** Unable to Explode Block: " (vla-get-name obj) " **")) (vla-delete obj) ) ) (vla-delete ss) ) ) ;; ReLock the Layers (mapcar (function (lambda ( l ) (vla-put-lock l :vlax-true)) ) locked ) ;; End the Undo mark (_EndUndo doc) ;; Exit Cleanly (princ) )
