Author Topic: Area list extraction  (Read 2411 times)

0 Members and 1 Guest are viewing this topic.

david

  • Guest
Area list extraction
« on: May 18, 2005, 08:52:19 PM »
Is it possible to extract only the area, in sq. ft., through lisp. What I want to do is be able to select several rectangles and extract the area, in sq. ft., to variables so I can add them together? Hope this make since. For example:
 
Code: [Select]
(defun c:art (/)
 (SETQ a (ENTSEL "Select object to get area of:"))
 (SETQ b (COMMAND "AREA" "o" a))
 (setq c (cDr b))
 (SETQ d (ENTSEL "Select object to get area of:"))
 (SETQ e (COMMAND "AREA" "o" d))
 (setq f (car e))
)


I apologize for the code. I'm just starting to dabble in autolisp. Thank you to all who respond.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Area list extraction
« Reply #1 on: May 18, 2005, 09:51:36 PM »
Instead of using vlax-property-available-p this uses a crude sledge hammer technique --

Code: [Select]
(defun c:SumArea ( / getarea area ss i )

    (defun getarea ( object / area )
        (vl-catch-all-apply
           '(lambda ()
                (setq area
                    (vla-get-area
                        object
                    )
                )
            )  
        )
        (if area area 0.0)
    )

    (cond
        (   (setq area 0.0 ss (ssget))
            (repeat (setq i (sslength ss))
                (setq area
                    (+ area
                        (getarea
                            (vlax-ename->vla-object
                                (ssname ss
                                    (setq i (1- i))
                                )
                            )    
                        )
                    )
                )
            )
        )
    )
   
    (if area area 0.0)

)

You can modify it to suit, for example divide the result by 144, whatever. I bashed it out quick and ran it thru a couple examples, seems to work and produce the same results as the native area command. Let me know if you have any problems; cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

david

  • Guest
Area list extraction
« Reply #2 on: May 18, 2005, 10:10:06 PM »
MP... Thanks. It works great but, I do need it to give sq. ft. I'm just starting out with the lisp learning and although your routine works great I
don't know enough to edit it to give sq. ft. Thank you for the help though.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Area list extraction
« Reply #3 on: May 18, 2005, 10:18:38 PM »
Did you try the help file? A surprising amount of info --

Direct quote from the AutoLISP Reference --

Quote
Divides the first number by the product of the remaining numbers and returns the quotient

(/ [number number] ...)

Arguments

number: A number.

Return Values

The result of the division. If you supply more than two number arguments, this function divides the first number by the product of the second through the last numbers, and returns the final quotient. If you supply one number argument, this function returns the result of dividing it by one; it returns the number. Supplying no arguments returns 0.

Examples

(/ 100 2)                 returns  50
(/ 100 2.0)               returns  50.0
(/ 100 20.0 2)            returns  2.5
(/ 100 20 2)              returns  2
(/ 4)                     returns  4

Even after pounding code for some twenty years I still refer to the help file(s).

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

david

  • Guest
Area list extraction
« Reply #4 on: May 18, 2005, 10:23:49 PM »
Thanks MP for the reference. I will research the help files as advised. Again, thanks.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Area list extraction
« Reply #5 on: May 18, 2005, 10:30:25 PM »
My pleasure. If you get stuck don't hesitate to ask additional questions, and incidentally, there aren't any dumb ones. We may try to get you to do some of the work because that will serve you well.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Area list extraction
« Reply #6 on: May 18, 2005, 10:49:13 PM »
You may want to look at this one too.
http://www.theswamp.org/phpBB2/viewtopic.php?t=1303
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

david

  • Guest
Area list extraction
« Reply #7 on: May 18, 2005, 11:23:40 PM »
Cab & MP.... Thanks for the help, I really appreciate it.