Guest Posted August 14, 2013 Posted August 14, 2013 I have this total area lisp ;GetArea.lsp - Total the areas of selected polyline entities. (defun C:GetArea() ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n Area = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing (command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m")) ;suppress the last echo (princ) ) I need to add a command change the text size. Quote
CheSyn Posted August 14, 2013 Posted August 14, 2013 Where did you get this LISP from, you should list the source. Use "entmake" instead of the "text" command. Add a prompt to ask for text height, save as a variable, and add to entmake. Show an attempt of how you would add the command, and I can help you through it if necessary. This is CADTutor afterall Quote
Guest Posted August 14, 2013 Posted August 14, 2013 I dont know lisp ,so can you do it ... thanks Quote
ReMark Posted August 14, 2013 Posted August 14, 2013 It is customary when "borrowing" a lisp routine someone else has created to acknowledge the author at the top of the code. It is considered the honorable thing to do. Didn't you write "I need to add a command..."? You did not ask for advice on how or where to add a command. You're going to once again hear about code posting guidelines. Don't say I didn't warn you. Quote
eldon Posted August 14, 2013 Posted August 14, 2013 It looks very similar to Jeffery P Sanders lisp, and it seems to take the current text height. So all you have to do is to draw some text in your drawing at the required height, and then start the lisp. Quote
Commandobill Posted August 14, 2013 Posted August 14, 2013 It looks very similar to Jeffery P Sanders lisp, and it seems to take the current text height. So all you have to do is to draw some text in your drawing at the required height, and then start the lisp. It's definately Jeff's as seen here http://www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp Poor bloke didn't localize his variables though... Quote
Commandobill Posted August 14, 2013 Posted August 14, 2013 I dont know lisp ,so can you do it ...thanks You definately don't seem to be trying to learn anything, but I'll try to teach you without fully giving you the answer straight out. The following line is the line that creates the text: (command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m")) The double quotes after 'pt1' is the spot in the text command that asks for the scale you want. If it's a fixed scale you want, then I would just put the number there. If not, as said previously you should set a variable with (setq variable (getreal)) or another type of code that gets a number. the put that variable at that spot. Good luck Quote
CheSyn Posted August 14, 2013 Posted August 14, 2013 I dont know lisp ,so can you do it ...thanks Not even an attempt? I have a working version of what you are looking for, and really don't mind helping. I gave a starting point, the least you could do is make an effort. Quote
Guest Posted August 15, 2013 Posted August 15, 2013 It is customary when "borrowing" a lisp routine someone else has created to acknowledge the author at the top of the code. It is considered the honorable thing to do. Didn't you write "I need to add a command..."? You did not ask for advice on how or where to add a command. You're going to once again hear about code posting guidelines. Don't say I didn't warn you. I dont know the author . I have this lisp few years Quote
Guest Posted August 15, 2013 Posted August 15, 2013 I try this but is not working ..... ;GetArea.lsp - Total the areas of selected polyline entities. (defun C:GetArea2 (ht scl) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n Ε = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq scl(/ (getreal "\n give scale (100,200,500,etc) : ") 100)) (setq ht(* 0.175 scl)) ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing (command "text" pt1 "" "" (strcat "E = "(rtos myArea 2 2)"sq.m")) ;suppress the last echo (princ) ) Quote
Commandobill Posted August 15, 2013 Posted August 15, 2013 You got the scale, but never put it into the command. (command "text" pt1 scl "" (strcat "E = "(rtos myArea 2 2)"sq.m")) Also, you forgot the '/' when you were trying to localize our variables... (defun C:GetArea2 (/ ent myArea pt1 ht scl) Quote
Guest Posted August 15, 2013 Posted August 15, 2013 Thanks Commandobill it works. Can i ask you samething else ? I do another change and i find a problem. I am trying to learn something so need help !! here is the code ;GetArea.lsp - Total the areas of selected polyline entities. (defun C:GetArea2 (/ ent myArea pt1 h ) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n Ε = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq h (getdist "\n give text size:")) ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing (command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m")) ;suppress the last echo (princ) ) I have a rotation problem .Why ? Quote
Commandobill Posted August 15, 2013 Posted August 15, 2013 Using a "Command line cop-out" as used in this lisp, sometimes is unreliable. You can try this: (defun C:GetArea2 (/ ent myArea pt1 h ) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq h (getdist "\n give text size:")) ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing (command "text" pt1 h 0 (strcat "E = "(rtos myArea 2 2)"sq.m")) ;suppress the last echo (princ) ) But I'm not sure it will do much difference. My only other thought is that perhaps you are on a UCS other than world? Quote
jdiala Posted August 15, 2013 Posted August 15, 2013 ;GetArea.lsp - Total the areas of selected polyline entities. (defun C:GetArea2 (/ ent myArea pt1 ) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [color="red"];(setq h (getdist "\n give text size:"))[/color] ; don't need ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing [color="red"] ;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))[/color] (command "text" pt1[color="red"] 0 [/color](strcat "E = "(rtos myArea 2 2)"sq.m")) ;suppress the last echo (princ) ) Quote
Guest Posted August 15, 2013 Posted August 15, 2013 Thank you Commandobill it works fine cheers Quote
Commandobill Posted August 15, 2013 Posted August 15, 2013 Jdiala - the variable 'h' in the code is for the scale of the text... He would need that as that is what he was initally asking for. Your code doesn't work. You should test your code before posting in the future. Quote
Commandobill Posted August 15, 2013 Posted August 15, 2013 Thank you Commandobill it works fine cheers You will find that help comes much easier when you make an honest effort to learn and do it yourself. Quote
jdiala Posted August 15, 2013 Posted August 15, 2013 (edited) Jdiala - the variable 'h' in the code is for the scale of the text... He would need that as that is what he was initally asking for. Your code doesn't work. You should test your code before posting in the future. Miss the "h" part between post. I tried your code on #13 and didn't work on mine either. There is no height option for the text command on Autocad 2014, that's why I remove it on my post on #14. Command: .text Current text style: "ROMANS" Text height: 0'-10" Annotative: No Justify: Left Specify start point of text or [Justify/Style]: Specify rotation angle of text <18.21>: 0 prodromosm said that he has rotation problem so I guessed "h" was not needed here. Text height is base on the current textstyle setting. Speaking for autocad 2014. Sorry can't test it on previous versions. (command "text" pt1 [color="red"]h[/color] 0 (strcat "E = "(rtos myArea 2 2)"sq.m")) This one perhaps: ;GetArea.lsp - Total the areas of selected polyline entities. (defun C:GetArea2 (/ ent myArea pt1 ) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(setq h (getdist "\n give text size:")) ; don't need ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing ;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m")) [color="red"] (entmakex (list (cons 0 "TEXT") (cons 1 (strcat "E = "(rtos myArea 2 2)"sq.m")) (cons 10 pt1) (cons 11 pt1) (cons 40 10) [color="#2e8b57"];set text height here[/color] (cons 72 1) (cons 73 2) ) )[/color] ;suppress the last echo (princ) ) Edited August 15, 2013 by jdiala Text height is base on the current textstyle setting. Quote
Commandobill Posted August 15, 2013 Posted August 15, 2013 I did say that "Command Line cop-out" was unreliable. I like your change to it, but I didn't want to change it too much on him. However, if you're going to put in entmakex, you should still leave in the option to place a scale, like so. ;GetArea.lsp - Total the areas of selected polyline entities. ;By: Jeff P. Sanders ;Changed multiple times on [url]http://www.cadtutor.net/forum/showthread.php?81125-Total-area-lisp&p=550883#post550883[/url] (defun C:GetArea2 (/ ent myArea pt1 ) ;turn off the system echo (setvar "cmdecho" 0) ;set up a variable to hold the accumulated areas (setq myArea 0) ;while the user keeps making a selection (while(setq ent(entsel)) ;if an entity was selected and not a point in space (if(car ent) (progn ;let AutoCAD get the area of the object...cheap yet effective way out... ;Note: AutoCAD stores the area in the system variable "Area" (command "area" "Object" (car ent)) ;print the area to the command line (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m")) ;accumulate the area if it exist (if (getvar "Area")(setq myArea(+ myArea (getvar "Area")))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (not (setq h (getdist "\n give text size:"))) (setq h 10)) ;ask for a text insertion point (setq pt1(getpoint "\n insert point: ")) ;print the area in the drawing ;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m")) (entmakex (list (cons 0 "TEXT") (cons 1 (strcat "E = "(rtos myArea 2 2)"sq.m")) (cons 10 pt1) (cons 11 pt1) (cons 40 h) ;set text height here ;(cons 72 1) ;I took these out because it will go to defaults ;(cons 73 2) ;I took these out because it will go to defaults ) ) ;suppress the last echo (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.