Jump to content

Area & Volume of closed polyline


noyjoreb

Recommended Posts

hi to all, i have a question... what lisp routine for computing the volume of closed polyline? example, i will get the area of a close polyline then by entering the thickness of depth, it will show a volume.. and put it on the table... any help is appreciated,... tnx

Link to comment
Share on other sites

Not sure if its what you want as I don't completely understand your request, but it was fun to write:

 

(defun c:V2Cell ( / tables ent dep pt doc )
 (vl-load-com)
 ;; Lee Mac  ~  17.05.10

 (while
   (progn
     (cond
       (
         (not
           (or tables
             (setq tables
               (ss->vla
                 (ssget "_X" '((0 . "ACAD_TABLE")))
               )
             )
           )
         )
         (princ "\n** No Tables in Drawing **") nil
       )
       (
         (not
           (or ent
             (setq ent
               (CurveifFoo
                 (lambda ( x )
                   (vlax-property-available-p
                     (vlax-ename->vla-object x) 'Area
                   )
                 )
                 "\nSelect Object to Retrieve Volume: "
               )
             )
           )
         )
        nil
       )
       (
         (not
           (or dep
             (setq dep
               (getdist "\nSpecify Depth: ")
             )
           )
         )
        nil
       )
       (
         (not
           (and
             (setq pt
               (getpoint "\nPick Cell for Volume: ")
             )
             (TextinCell tables pt
               (strcat "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                 (GetObjectID
                   (vlax-ename->vla-object ent)
                   (setq doc
                     (cond
                       ( doc )
                       (
                         (vla-get-ActiveDocument
                           (vlax-get-acad-object)
                         )
                       )
                     )
                   )
                 )
                 ">%).Area>% * "
                 (vl-princ-to-string dep) " \\f \"%lu6%qf1\">%"
               )
             )
           )
         )
        (princ "\n** Cell Not Found **")
       )
     )
   )
 )
 (princ)
)   

(defun TextinCell ( tables pt str / data )
 ;; Lee Mac  ~  17.05.10
 (if
   (setq data
     (vl-some
       (function
         (lambda ( table )
           (if
             (eq :vlax-true
               (vla-hittest table (vlax-3D-point (trans pt 1 0))
                 (vlax-3D-point (trans (getvar 'VIEWDIR) 1 0)) 'row 'col
               )
             )
             (list table row col)
           )
         )
       )
       tables
     )
   )
   (not
     (apply (function vla-setText)
       (append data (list str))
     )
   )
 )
)

(defun ss->vla ( ss )
 (if ss
   (
     (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (setq l
           (cons
             (vlax-ename->vla-object e) l
           )
         )
       )
       l
     )
     -1
   )
 )
)

(defun CurveifFoo ( foo str / sel ent )
 ;; Lee Mac  ~  17.05.10
 (while
   (progn
     (setq sel (entsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (foo (setq ent (car sel))))

           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 ent
)

(defun GetObjectID ( obj doc )
 ;; Lee Mac  ~  17.05.10
 (if
   (eq "X64"
     (strcase
       (getenv "PROCESSOR_ARCHITECTURE")
     )
   )
   (vlax-invoke-method
     (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false
   )
   (itoa (vla-get-Objectid obj))
 )
)

Link to comment
Share on other sites

  • 5 months later...

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...