TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: fathihvac 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 :-)
-
With a area macro with DIESEL expressions?
^C^C_.-HATCH;_P;_S;\;_.AREA;_O;_L;_.ERASE;_L;;_.-MTEXT;\@0,0;Area= $m=$(fix,$(getvar,area)) mm²;;
or
^C^C-H;P;S;\;AA;O;L;E;L;;-MTEXT;\@0,0;Area= $m=$(fix,$(getvar,area)) mm²;;
and for square metres
-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
-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?
-
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?
-
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:
(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)
)
-
Another variant:
http://lee-mac.com/areastofield.html (http://lee-mac.com/areastofield.html)
-
To achieve my request Here is the code that i want to correct.Please help
-
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:
(command "text" "Justify" "Center" Pt tht 0 myNum)
(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:
(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
-
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.
-
This seems very similar to this (http://www.cadtutor.net/forum/showthread.php?61805-Help-with-Area-command) recent thread.
-
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:
(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
-
Related, by Alanjt:
http://www.theswamp.org/index.php?topic=37824 (http://www.theswamp.org/index.php?topic=37824)
-
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
-
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
(strcat (rtos (getvar 'AREA)) " m²")
with
(strcat (rtos (getvar 'AREA) 2 2) " m²")
Are you drawing in metres, otherwise you must divide by 1000000?
HofCAD CSI
-
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).