Jump to content

Recommended Posts

Posted

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.

Posted

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 ;)

Posted

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.

Posted

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. :D

Posted
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. :D

 

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...

Posted
I dont know lisp ,so can you do it ...

thanks :D

 

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

Posted
I dont know lisp ,so can you do it ...

thanks :D

 

Not even an attempt? :nono:

 

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.

Posted
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

Posted

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)
)

Posted

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)

Posted

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 :D 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 ?

Posted

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?

Posted
;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)
)

Posted

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.

Posted
Thank you Commandobill it works fine

 

:beer: cheers

 

You will find that help comes much easier when you make an honest effort to learn and do it yourself.

 

:beer:

Posted (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 by jdiala
Text height is base on the current textstyle setting.
Posted

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)
)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...