'magically' provide the total sum!

Discussion in 'AutoCAD' started by jon, Dec 13, 2004.

  1. jon

    jon Guest

    i've created boundaries for a set of lots - and defined the area in s.f. i'm need of a routine which will enable me to 'window cross' all the text and then 'magically' provide the total sum! or even better - 'window cross' all the bounderies!! any such thing?

    thanks!
     
    jon, Dec 13, 2004
    #1
  2. jon

    T.Willey Guest

    You can try this.

    Tim

    (defun c:calc(/ app cal n l nu1 nu2 nu3 nu4 nu5 tx1 tx2 tx3 tx4)

    (initget "+ - * /")
    (setq app(getkword "\nWhat application would you like to do:\(+,-,*,/)"))
    (if(or (= app "-")(= app "/"))(princ "\nDon't forget order counts. So pick carefully."))
    (princ "\nSelect numbers to calculate:")
    (setq cal(ssget '((0 . "TEXT"))))
    (setq n 0)
    (setq l(sslength cal))
    (while(/= l n)
    (get_info)
    (if(= nu3 0.0)
    (progn
    (ssdel (ssname cal n) cal)
    (setq l(- l 1))
    (setq n(- n 1))
    )
    )
    (setq n(+ n 1))
    )
    (setq n 0)
    (setq l(sslength cal))
    (cond
    ((= app "+")
    (addc))
    ((= app "-")
    (subc))
    ((= app "*")
    (multc))
    ((= app "/")
    (divdc))
    )
    (initget "Replace Write")
    (princ "\nAnswer= ")
    (princ nu5)
    (setq tx1(getkword"\nWhat do you want do with the answer\(Replace, Write to screen):"))
    (cond
    ((= tx1 "Replace")
    (setq tx2(ssget '((0 . "TEXT"))))
    (setq n 0)
    (setq l(sslength tx2))
    (while(/= n l)
    (setq tx3(entget(ssname tx2 n)))
    (setq tx4(subst(cons 1 (rtos nu5 2 1))(assoc 1 tx3) tx3))
    (entmod tx4)
    (setq n(+ 1 n))
    )
    )
    ((= tx1 "Write")
    (setq nu5(rtos nu5 2 1))
    (princ "\nPick point for text insertion")
    (command "text" "j" "m" pause "" "" nu5 )
    )
    )

    (princ)

    )



    (defun get_info()
    (setq nu1(entget (ssname cal n)))
    (setq nu2(cdr(assoc 1 nu1)))
    (setq nu3(atof nu2))
    )

    (defun addc()
    (get_info)
    (setq nu4 nu3)
    (setq n(+ 1 n))
    (while(/= l n)
    (get_info)
    (setq nu5(+ nu4 nu3))
    (setq nu4 nu5)
    (setq n(+ 1 n))
    )
    )

    (defun subc()
    (get_info)
    (setq nu4 nu3)
    (setq n(+ 1 n))
    (while(/= l n)
    (get_info)
    (setq nu5(- nu4 nu3))
    (setq nu4 nu5)
    (setq n(+ 1 n))
    )

    )


    (defun multc()
    (get_info)
    (setq nu4 nu3)
    (setq n(+ 1 n))
    (while(/= l n)
    (get_info)
    (setq nu5(* nu4 nu3))
    (setq nu4 nu5)
    (setq n(+ 1 n))
    )
    )


    (defun divdc()
    (get_info)
    (setq nu4 nu3)
    (setq n(+ 1 n))
    (while(/= l n)
    (get_info)
    (setq nu5(/ nu4 nu3))
    (setq nu4 nu5)
    (setq n(+ 1 n))
    )
    )
     
    T.Willey, Dec 13, 2004
    #2
  3. jon

    Dann Guest

    You can modify this to fit your needs:

    (vl-load-com)
    (defun C:t_area (/ tarea are objs num inc)
    (setq tarea 0)
    (setq are 0)
    (setq objs (ssobj))
    (setq num (length objs))
    (setq inc 0)
    (repeat num
    (setq obj (nth inc objs))
    (if (vlax-property-available-p obj 'Area)
    (setq are (vla-get-Area obj))
    (princ "**WARNING** Some Objects Selected Have No Area:\n ")
    )
    (setq tarea(+ tarea are))
    (setq inc(+ inc 1))
    )
    (princ (strcat "Total Area = " (rtos tarea 2 2)))
    (princ)
    )


    (defun ssobj (/ ss1 num inc lstobj) ;usage = (setq lsobj(ssobj))
    (setq ss1 (ssget))
    (setq num (sslength ss1))
    (setq inc 0)
    (setq lstobj (list a))
    (repeat num
    (setq obj (vlax-ename->vla-object (ssname ss1 inc)))
    (setq lstobj (append lstobj (list obj)))
    (setq inc (+ inc 1))
    )
    (setq lstobj (cdr lstobj))
    (princ)
    lstobj ;returns result for use in calling program
    )



    i've created boundaries for a set of lots - and defined the area in s.f. i'm need of a routine which will enable me to 'window cross' all the text and then 'magically' provide the total sum! or even better - 'window cross' all the bounderies!! any such thing?

    thanks!
     
    Dann, Dec 13, 2004
    #3
  4. jon

    jon Guest

    i'm new to 'customization' - so in short - w/ the information you've provided - how do i go about creating the action?
    "Dann" <NoneSpecified> wrote in message You can modify this to fit your needs:

    (vl-load-com)
    (defun C:t_area (/ tarea are objs num inc)
    (setq tarea 0)
    (setq are 0)
    (setq objs (ssobj))
    (setq num (length objs))
    (setq inc 0)
    (repeat num
    (setq obj (nth inc objs))
    (if (vlax-property-available-p obj 'Area)
    (setq are (vla-get-Area obj))
    (princ "**WARNING** Some Objects Selected Have No Area:\n ")
    )
    (setq tarea(+ tarea are))
    (setq inc(+ inc 1))
    )
    (princ (strcat "Total Area = " (rtos tarea 2 2)))
    (princ)
    )


    (defun ssobj (/ ss1 num inc lstobj) ;usage = (setq lsobj(ssobj))
    (setq ss1 (ssget))
    (setq num (sslength ss1))
    (setq inc 0)
    (setq lstobj (list a))
    (repeat num
    (setq obj (vlax-ename->vla-object (ssname ss1 inc)))
    (setq lstobj (append lstobj (list obj)))
    (setq inc (+ inc 1))
    )
    (setq lstobj (cdr lstobj))
    (princ)
    lstobj ;returns result for use in calling program
    )



    i've created boundaries for a set of lots - and defined the area in s.f. i'm need of a routine which will enable me to 'window cross' all the text and then 'magically' provide the total sum! or even better - 'window cross' all the bounderies!! any such thing?

    thanks!
     
    jon, Dec 13, 2004
    #4
  5. jon

    Dann Guest

    Save the info I provided to your harddrive as T_Area.lsp
    Type "Appload" in AutoCAD, find the file and load it.
    Tyle T_Area at the command line.
    i'm new to 'customization' - so in short - w/ the information you've provided - how do i go about creating the action?
    "Dann" <NoneSpecified> wrote in message You can modify this to fit your needs:

    (vl-load-com)
    (defun C:t_area (/ tarea are objs num inc)
    (setq tarea 0)
    (setq are 0)
    (setq objs (ssobj))
    (setq num (length objs))
    (setq inc 0)
    (repeat num
    (setq obj (nth inc objs))
    (if (vlax-property-available-p obj 'Area)
    (setq are (vla-get-Area obj))
    (princ "**WARNING** Some Objects Selected Have No Area:\n ")
    )
    (setq tarea(+ tarea are))
    (setq inc(+ inc 1))
    )
    (princ (strcat "Total Area = " (rtos tarea 2 2)))
    (princ)
    )


    (defun ssobj (/ ss1 num inc lstobj) ;usage = (setq lsobj(ssobj))
    (setq ss1 (ssget))
    (setq num (sslength ss1))
    (setq inc 0)
    (setq lstobj (list a))
    (repeat num
    (setq obj (vlax-ename->vla-object (ssname ss1 inc)))
    (setq lstobj (append lstobj (list obj)))
    (setq inc (+ inc 1))
    )
    (setq lstobj (cdr lstobj))
    (princ)
    lstobj ;returns result for use in calling program
    )



    i've created boundaries for a set of lots - and defined the area in s.f. i'm need of a routine which will enable me to 'window cross' all the text and then 'magically' provide the total sum! or even better - 'window cross' all the bounderies!! any such thing?

    thanks!
     
    Dann, Dec 13, 2004
    #5
  6. jon

    BillZ Guest

    Code:
    ;12/13/04 Bill Zondlo
    (defun c:AddBoundaryAreas (/ cnt ss)
    (princ "\nSelect boundaries.\n")
    (setq ss (ssget '((0 . "POLYLINE,LWPOLYLINE"))))
    (setq cnt 0
    total 0)
    (repeat (sslength ss)
    (setq ent (ssname ss cnt)
    cnt (1+ cnt))
    (command "_.area" "O" ent)
    (setq total (+ total (getvar "area"))
    )
    )
    total
    )
    Bill
     
    BillZ, Dec 13, 2004
    #6
  7. jon

    Dann Guest

    What if the boundary is a Region?
     
    Dann, Dec 13, 2004
    #7
  8. jon

    BillZ Guest

    Code:
    ;12/13/04 Bill Zondlo
    (defun c:AddBoundaryAreas (/ cnt ss total)
    (princ "\nSelect boundaries.\n")
    (setq ss (ssget '((0 . "POLYLINE,LWPOLYLINE,REGION"))))
    (setq cnt 0
    total 0)
    (repeat (sslength ss)
    (setq ent (ssname ss cnt)
    cnt (1+ cnt))
    (command "_.area" "O" ent)
    (setq total (+ total (getvar "area"))
    )
    )
    total
    )
    Bill
     
    BillZ, Dec 13, 2004
    #8
  9. jon

    jon Guest

    thanks everyone!
     
    jon, Dec 13, 2004
    #9
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.