Jump to content
Jest

Multiple polyline area sum

Recommended Posts

Jest

I need a lisp command, to calculate area sum of already selected multiple closed polylines ...

Thanks

Share this post


Link to post
Share on other sites
Emmanuel Delay
(vl-load-com)
;; Get Selected Areas
(defun c:gsa ( / ss1 obj i sum)
  ;; SSGET polylines already selected
  (setq ss1  (ssget "I" '( (0 . "POLYLINE,LWPOLYLINE") (70 . 1) )))  ;; 70=1 means closed
 
  (setq
    i 0
    sum 0.0
  )
  (repeat (sslength ss1)
    (setq obj (vlax-ename->vla-object (ssname ss1 i)))
    (setq ar (vlax-curve-getarea obj))  ;; get area
    (setq sum (+ sum ar))
    (setq i (+ i 1))
  )
 
  (princ sum)
  (princ)
)

Edited by Emmanuel Delay

Share this post


Link to post
Share on other sites
Jest

Thank you!!
It works fine, but I have two more questions, and asking you, if you can help me.
Using this lisp, i found out two strange things.
1. example: My units are set to 4 decimal numbers. in one case result shows 5 decimal numbers.
2. example: I choose few really big objects and result is 9.36016e+06. But I want to see whole real number (so I can use copy-paste option), not to calculate result ...is it possible at all?
How to fix this. Do I have to change something in my program settings or any of System Variables?

kind regards!

Share this post


Link to post
Share on other sites
Lee Mac

You may want to consider my Total Length & Area programs.

 

To modify the precision of the output, change:

(princ (rtos a 2))

To:

(princ (rtos a 2 15))

Alternatively, retain the existing code and increase the value of your LUPREC system variable.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
Jest

Thanks....exactly what I need.

By the way, an option (princ (rtos a 2 1 5 )) doesnt work...but never mind, original version works fine.

Now I am just wondering, if there is an option, to display thousands separated with comma...or space..?

Share this post


Link to post
Share on other sites
Lee Mac
7 minutes ago, Jest said:

Thanks....exactly what I need.

By the way, an option (princ (rtos a 2 1 5 )) doesnt work...but never mind, original version works fine.

Now I am just wondering, if there is an option, to display thousands separated with comma...or space..?

 

It should be:

(rtos a 2 15)

Per my post, not:

(rtos a 2 1 5)

The rtos function accepts a maximum of three arguments.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
Lee Mac
9 minutes ago, Jest said:

Now I am just wondering, if there is an option, to display thousands separated with comma...or space..?

 

For this you can make use of the function I posted here.

 

Copy the code for that function to the end of your .lsp file, and then change the output expression to:

(princ (rtoc a 15))

 

Edited by Lee Mac

Share this post


Link to post
Share on other sites
Jest

It works, but now i got 6 decimal numbers, not 4, as before..

Did I wrote down correctly?:

 

 

;;---------------------=={ Total Area }==---------------------;;
;;                                                            ;;
;;  Displays the total area of selected objects at the        ;;
;;  command line. The precision of the printed result is      ;;
;;  dependent on the setting of the LUPREC system variable.   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:tarea ( / a i s )
    (if (setq s
            (ssget
               '(   (0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                    (-4 . "<NOT")
                        (-4 . "<AND")
                            (0 . "POLYLINE") (-4 . "&") (70 . 80)
                        (-4 . "AND>")
                    (-4 . "NOT>")
                )
            )
        )
        (progn
            (setq a 0.0)
            (repeat (setq i (sslength s))
                (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
            )
            (princ "\nTotal Area: ")
            (princ (rtoc a 15))
        )
    )
    (princ)
)
(vl-load-com) (princ)
(defun rtoc ( n p / d i l x )
    (setq d (getvar 'dimzin))
    (setvar 'dimzin 0)
    (setq l (vl-string->list (rtos (abs n) 2 p))
          x (cond ((cdr (member 46 (reverse l)))) ((reverse l)))
          i 0
    )
    (setvar 'dimzin d)
    (vl-list->string
        (append (if (minusp n) '(45))
            (reverse
                (apply 'append
                    (mapcar
                       '(lambda ( a b )
                            (if (and (zerop (rem (setq i (1+ i)) 3)) b)
                                (list a 44)
                                (list a)
                            )
                        )
                        x (append (cdr x) '(nil))
                    )
                )
            )
            (member 46 l)
        )
    )
)

 

Share this post


Link to post
Share on other sites
Lee Mac
10 minutes ago, Jest said:

It works, but now i got 6 decimal numbers, not 4, as before..

 

Note that the precision is limited to approximately 15 significant figures, hence for larger numbers, you'll lose precision in the number of decimal places - observe:

_$ (rtos 1.123456789012345 2 15)
"1.123456789012345"
_$ (rtos 10.123456789012345 2 15)
"10.12345678901234"
_$ (rtos 100.123456789012345 2 15)
"100.1234567890123"
_$ (rtos 1000.123456789012345 2 15)
"1000.123456789012"
_$ (rtos 10000.123456789012345 2 15)
"10000.12345678901"
_$ (rtos 100000.123456789012345 2 15)
"100000.123456789"
_$ (rtos 1000000.123456789012345 2 15)
"1000000.123456789"
_$ (rtos 10000000.123456789012345 2 15)
"10000000.12345679"
_$ (rtos 100000000.123456789012345 2 15)
"100000000.1234568"
_$ (rtos 1000000000.123456789012345 2 15)
"1000000000.123457"
_$ (rtos 10000000000.123456789012345 2 15)
"10000000000.12345"
_$ (rtos 100000000000.123456789012345 2 15)
"100000000000.1235"
_$ (rtos 1000000000000.123456789012345 2 15)
"1000000000000.123"
_$ (rtos 10000000000000.123456789012345 2 15)
"10000000000000.12"
_$ (rtos 100000000000000.123456789012345 2 15)
"100000000000000.1"
_$ (rtos 1000000000000000.123456789012345 2 15)
"1000000000000000"

 

Share this post


Link to post
Share on other sites
Jest

I see...thanks

Can you just tell me, ho toadd thousand comma separation to TotaL Lenght lisp?

Share this post


Link to post
Share on other sites
Lee Mac
6 hours ago, Jest said:

I see...thanks

Can you just tell me, ho toadd thousand comma separation to TotaL Lenght lisp?

 

In the same way, changing:

(princ (rtos l))

to:

(princ (rtoc l 15))

 

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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