Author Topic: area command ?  (Read 5362 times)

0 Members and 1 Guest are viewing this topic.

fathihvac

  • Guest
area command ?
« on: August 12, 2011, 04:33:28 AM »
Hello,
Can anyone write an autolisp to use area command and insert the result as text string in the drawing :-)

Harrie

  • Guest
Re: area command ?
« Reply #1 on: August 12, 2011, 07:54:03 AM »
With a area macro with DIESEL expressions?
Code: [Select]
^C^C_.-HATCH;_P;_S;\;_.AREA;_O;_L;_.ERASE;_L;;_.-MTEXT;\@0,0;Area= $m=$(fix,$(getvar,area)) mm;;or
Code: [Select]
^C^C-H;P;S;\;AA;O;L;E;L;;-MTEXT;\@0,0;Area= $m=$(fix,$(getvar,area)) mm;;and for square metres
Code: [Select]
-H;P;S;\;AA;O;L;E;L;;-MTEXT;\@0,0;Area= $m=$(fix,$(/,$(getvar,area),1000000)) m;;and for square metres, with no fix but with mode and precision
Code: [Select]
-H;P;S;\;AA;O;L;E;L;;-MTEXT;\@0,0;Area= $m=$(rtos,$(/,$(getvar,area),1000000),2,2) m;;http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/area-command-problems/td-p/2665577
http://www.jefferypsanders.com/autolisp_GetArea.html
http://www.afralisp.net/autolisp/tutorials/working-with-areas-part-1.php

Why text and not fields?
« Last Edit: August 12, 2011, 04:50:14 PM by Harrie »

Chris

  • Swamp Rat
  • Posts: 544
Re: area command ?
« Reply #2 on: August 12, 2011, 08:16:40 AM »
I'm sure that lots of people here can write one, but as Harrie asked, why not just use a field with the data linked to the area property of the selected objects?
Christopher T. Cowgill, P.E.
AEC Collection 2018 (C3D)
Win 10

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: area command ?
« Reply #3 on: August 12, 2011, 08:50:47 AM »
My point exactly. I prefer using the attached's DimArea (though that places the field into an existing text). To only use text (no fields), perhaps something like this:
Code: [Select]
(vl-load-com)

(setq *AreaSettings*
       '(("Prefix" . "AREA: ")
         ("Suffix" . " m")
         ("Source" . "sq mm")
         ("Target" . "sq m")
         ("Format" 2 2)
        )
)
(defun c:PlaceArea (/ en area pt eo space Area->Text AddText)
  (setq space (apply (if (or (= (getvar 'TileMode) 1) (> (getvar 'CVport) 1))
                       'vla-get-ModelSpace
                       'vla-get-PaperSpace
                     )
                     (list (vla-get-ActiveDocument (vlax-get-acad-object)))
              )
  )
  (defun Area->Text (area /)
    (strcat (cdr (assoc "Prefix" *AreaSettings*))
            (apply 'rtos
                   (cons
                     (cvunit area (cdr (assoc "Source" *AreaSettings*)) (cdr (assoc "Target" *AreaSettings*)))
                     (cdr (assoc "Format" *AreaSettings*))
                   )
            )
            (cdr (assoc "Suffix" *AreaSettings*))
    )
  )
  (defun AddText (area pt /)
    (vla-AddText space (Area->Text area) (vlax-3D-point pt) (getvar 'TextSize))
  )
  (while (setq en (entsel "\nPick entity for source of area (Enter to exit): "))
    (if (setq area (vlax-curve-getArea (car en)))
      (if (setq pt (getpoint "\nPick point for placing text: "))
        (if (vl-catch-all-error-p (setq eo (vl-catch-all-apply 'AddText (list area pt))))
          (prompt (strcat "\nError placing text: " (vl-catch-all-error-message eo)))
          (progn
            (vla-put-Layer eo (getvar 'CLayer))
            (vla-put-StyleName eo (getvar 'TextStyle))
            (prompt "\nArea text placed.")
          )
        )
        (prompt "\nInvalid point, restarting.")
      )
      (prompt "\nThat entity doesn't have an area. Try again.")
    )
  )
  (princ)
)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: area command ?
« Reply #4 on: August 12, 2011, 10:05:16 AM »

fathihvac

  • Guest
Re: area command ?
« Reply #5 on: August 13, 2011, 06:26:13 AM »
To achieve my request Here is the code that i want to correct.Please help

HofCAD

  • Guest
Re: area command ?
« Reply #6 on: August 13, 2011, 08:11:14 AM »
To achieve my request Here is the code that i want to correct.Please help
Why not remove in GA.lsp http://www.jefferypsanders.com/autolisp_GetArea.html
the 2 lines:
Code: [Select]
(command "text" "Justify" "Center" Pt tht 0 myNum)
Code: [Select]
(command "text" "Justify" "Center" (polar Pt (* pi 1.5) (* 2.0(* tht 1.5))) tht 0 (strcat "PERIMETER=" (rtos myPerim)))But if you insist on simplicity:
Code: [Select]
(defun c:test (/ AreaTxt pt)
  (command "_.AREA" "_O" pause)
  (setq AreaTxt (strcat (rtos (getvar "AREA")) " m")
  )
  (if (setq pt (getpoint "\n Select text insertion point : "))
    (command "_.TEXT"
     "_J"
     "_C"
     pt
     (getvar "TEXTSIZE")
     0
     AreaTxt
    )
  )
)

HofCAD CSI
« Last Edit: August 13, 2011, 08:23:55 AM by HofCAD »

fathihvac

  • Guest
Re: area command ?
« Reply #7 on: August 13, 2011, 08:27:39 AM »
Thanks hotcad I mean to keep autocad area command as it is so it prompts me to select points that makes the boundaries and at the end i can insert areatxt where i want.

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: area command ?
« Reply #8 on: August 13, 2011, 08:32:15 AM »
This seems very similar to this recent thread. 

HofCAD

  • Guest
Re: area command ?
« Reply #9 on: August 13, 2011, 08:38:07 AM »
Thanks hotcad I mean to keep autocad area command as it is so it prompts me to select points that makes the boundaries and at the end i can insert areatxt where i want.
Something like this:
Code: [Select]
(defun c:test2 (/ pt)
  (vl-cmdf "_.AREA")
  (while (/= 0 (getvar 'CMDACTIVE))
    (vl-cmdf pause)
  )
  (if (setq pt (getpoint "\n Select text insertion point : "))
    (command "_.TEXT"
     "_J"
     "_C"
     pt
     (getvar 'TEXTSIZE)
     0
     (strcat (rtos (getvar 'AREA)) " m")
    )
  )
)

HofCAD CSI
« Last Edit: August 13, 2011, 08:50:07 AM by HofCAD »

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: area command ?
« Reply #10 on: August 13, 2011, 08:51:22 AM »

fathihvac

  • Guest
Re: area command ?
« Reply #11 on: August 13, 2011, 08:52:04 AM »
Great ! it works
Many thank to you Hofcad
Can you make it so the DIMDEC equal 2 because it gives 4 after dot althoug my dimdec is 2 i dont understand where is the problem

HofCAD

  • Guest
Re: area command ?
« Reply #12 on: August 13, 2011, 08:55:47 AM »
Great ! it works
Many thank to you Hofcad
Can you make it so the DIMDEC equal 2 because it gives 4 after dot althoug my dimdec is 2 i dont understand where is the problem
Replace
Code: [Select]
(strcat (rtos (getvar 'AREA)) " m")with
Code: [Select]
(strcat (rtos (getvar 'AREA) 2 2) " m")Are you drawing in metres, otherwise you must divide by 1000000?

HofCAD CSI
« Last Edit: August 13, 2011, 09:08:31 AM by HofCAD »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: area command ?
« Reply #13 on: August 13, 2011, 09:30:47 AM »
Are you drawing in metres, otherwise you must divide by 1000000?
That's why I had the cvunit thing in mine. Many in the building industry draw in mm but give areas in sqm. Same as drawing in inches but areas in sqft. The cvunit makes it a bit simpler to convert, since you don't need to remember the ratios (especially since area is squared).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.