Area for any object

Discussion in 'AutoCAD' started by scatman99, Jul 22, 2004.

  1. scatman99

    scatman99 Guest

    I have a lisp file that calculates the area and perimeter of an object in m2 and m. It only works for closed polylines at the moment, can anyone help me to amend it to work for picked points as well as polylines as the Acad area command does.

    Cheers

    (defun c:aaaa ()
    (setq obj (car (entsel)))
    (command "area" "o" obj)
    (setq A1 (/ (getvar "area") 1000000))
    (setq P1 (/ (getvar "perimeter") 1000))
    (terpri)
    (prompt "Area = ")(princ A1)(prompt "m2")
    (terpri)
    (prompt "Peri = ")(princ P1)(prompt "m")
    (princ)
    )
     
    scatman99, Jul 22, 2004
    #1
  2. scatman99

    Tom Smith Guest

    I have a lisp file that calculates the area and perimeter of an object in
    m2 and m.

    Not really. It reports area and perimeter in whatever units Acad happens to
    be using at the time, after dividing them by a million and a thousand
    respectively. You're assuming that the drawing units are mm, but there's
    nothing in Acad or your routine to validate this assumption. The units could
    be microns or parsecs.
     
    Tom Smith, Jul 22, 2004
    #2
  3. scatman99

    Rajesh Guest

    To calculate the area enclosed by the picked points, put a temporary polyline through the picked points, then get the area of last object (the temp. polyline), then delete the temporary polyline. I think you can do the amendment now yourself!

    Hope this idea helps.

    Rajesh Patnaik
     
    Rajesh, Jul 22, 2004
    #3
  4. scatman99

    scatman99 Guest

    Ok I’ll re-phrase the question!

    I have a lisp file that reports area and perimeter in whatever units Acad happens to
    be using at the time, after dividing them by a million and a thousand respectively, if the units happen to be mm it calculates the area and perimeter of an object in m2 and m. It only works for closed polylines at the moment, can anyone help me to amend it to work for picked points as well as polylines as the Acad area command does.
     
    scatman99, Jul 22, 2004
    #4
  5. scatman99

    Doug Barr Guest

    Try this...
    Added the stuff to do points/objects, leaving the rest as you had it.
    -doug

    (defun c:aaaa ()
    (princ "\nArea finder - select type:<Points,Object>")
    (setq atype (strcase (getstring)))
    (cond
    ((= atype "P")
    (princ "\nPick first point for perimeter:")
    (setq pt1 (getpoint))
    (command "area" pt1)
    (while
    (setq pt2 (getpoint pt1 "\nNext Point.."))
    (setq ptlist (append ptlist (list pt1)))
    (setq pt1 pt2)
    (command pt2)
    );end while
    (command "")
    )
    ((= atype "O")(command "area" "o" pause))
    )
    (setq A1 (/ (getvar "area") 1000000))
    (setq P1 (/ (getvar "perimeter") 1000))
    (terpri)
    (prompt "Area = ")(princ A1)(prompt "m2")
    (terpri)
    (prompt "Peri = ")(princ P1)(prompt "m")
    (princ)
    )




    and m. It only works for closed polylines at the moment, can anyone help me to
    amend it to work for picked points as well as polylines as the Acad area command
    does.
     
    Doug Barr, Jul 22, 2004
    #5
  6. scatman99

    scatman99 Guest

    Cheers doug,
    thanks very much.
     
    scatman99, Jul 22, 2004
    #6
  7. scatman99

    Doug Broad Guest

    One way:
    (defun c:aaaa ()
    (setvar "cmdecho" 1)
    (command "area")
    (while (= (getvar "cmdactive") 1)
    (command pause))
    (setvar "cmdecho" 0)
    (setq A1 (/ (getvar "area") 1000000))
    (setq P1 (/ (getvar "perimeter") 1000))
    (terpri)
    (prompt "Area = ")(princ A1)(prompt "m2")
    (terpri)
    (prompt "Peri = ")(princ P1)(prompt "m")
    (princ)
    )

    area and perimeter of an object in m2 and m. It only works for closed polylines at the moment, can anyone help me to amend it to
    work for picked points as well as polylines as the Acad area command does.
     
    Doug Broad, Jul 22, 2004
    #7
  8. scatman99

    Doug Barr Guest

    One subtractional thing...<g>
    Take this out:
    (setq ptlist (append ptlist (list pt1)))
    At first I thought I'd need a list of points, but it isn't required.

    btw, the 'other Doug B' has a better handle on some of this, f'rinstance
    "cmdactive", and his is ultimately cleaner than mine. Though I do like the
    rubber bands that mine offers.
    -doug
     
    Doug Barr, Jul 22, 2004
    #8
  9. scatman99

    gert Guest

    the problem is in your command line, where you select o, so only closed
    polylines are messured

    have a look at cmdactive systemvariable to create a temp polyline
    then
    (command "_area" "_o" (lastent))

    good luck

    mfg
    gert
     
    gert, Jul 22, 2004
    #9
  10. scatman99

    scatman99 Guest

    Thanks for all of that, most useful,
    Cheers
     
    scatman99, Jul 22, 2004
    #10
  11. scatman99

    Doug Broad Guest

    Thanks Doug. I took the easy way, since
    he wanted it to act just like the area command.
     
    Doug Broad, Jul 22, 2004
    #11
  12. scatman99

    Doug Barr Guest

    So can 'cmdactive' be used to burst into any command and
    do other 'surreptitious stuff' while the command is still running?
     
    Doug Barr, Jul 22, 2004
    #12
  13. scatman99

    Doug Broad Guest

    Hi Doug,
    I'm not sure I understand the question. (getvar "Cmdactive") can
    be used to detect whether a built in command is running.
    (getvar "Cmdnames") can be used to determine which commands
    are running.

    Many things can be done between (command...) statements
    while a command is active. Since there is no way to check the
    value of the command prompts, however, there is no way to
    use it to predict what would be the correct answer to a prompt.

    Here I was just using it to allow the area command to run to
    its conclusion with whatever input the user wanted and then
    calculating the areas. A commandended reactor could also
    be used but, in this case, it would have been overkill.

    Regards,
    Doug
     
    Doug Broad, Jul 22, 2004
    #13
  14. But if that's how you're going to do it, you don't need the polyline. All
    you need is to feed those points to the Area command, which also gives you
    the area and perimeter. If you want to get that information for use in a
    lisp routine, I'm not sure how you would extract it (either from the Area
    result OR from a polyline, since neither of these is in the assoc/dxf code
    list for the polyline), but I vaguely recall that there might have been a
    similar question raised maybe a few months ago that you could search for on
    the website edition.

    Kent Cooper, AIA


    polyline through the picked points, then get the area of last object (the
    temp. polyline), then delete the temporary polyline. I think you can do the
    amendment now yourself!
     
    Kent Cooper, AIA, Jul 22, 2004
    #14
  15. scatman99

    Tom Smith Guest

    Doug's explanation is pretty good. Generally this trick is used when you
    need to do something after a command is concluded, such as reporting the
    information after running the area command. There's no way to predict how
    many points might be picked, but you can check to see if that command is
    still in progress, and keep pausing for input as long as it's running.

    It's not so much a case of doing stuff while the command is running, it's
    more a matter of needing to know when the command is finished.
     
    Tom Smith, Jul 22, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.