Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Looking for Lisp to Caclulate multiple areas and put text in center of pline

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
616 Views, 13 Replies

Looking for Lisp to Caclulate multiple areas and put text in center of pline

I have see it before but can't find it now. I an looking for a lisp routine that will calculate the area of serval different polylines and put the area in the center of the pline.
The purpose is calculating the areas of multiple rooms and listing that area on the plan.
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

;;; This lisp finds the area of a polyline & writes the result (metric &
imperial) to block attributes.
;;; Adapted from 'getarea.lsp by Omura Illustration (C) 1995 by Bill DeShawn
& are_e.lsp by
;;; Jim (dedalos_2000athotmaildotcom). Further, tiny
;;; modifications by Zac Carey (ZJC), 2002.
;;; Program to simultaneously place metric and imperial area information in
a drawing.
;;; Make sure that the a block called 'areaz.dwg' is located in the support
directory.
;;; This block should contain, as a minimum, two attribute definitions, for
metric and
;;; imperial data which, when writing the block, should be selected in that
order.
;;; Ideally, each of these attribute definitions should be on different, and
readily,
;;; identifiable layers. My block contains a third attribute definition for
specifying the
;;; function that the given area is to be used for - and a fourth for
specifying the floor
;;; no. or no. of floors to which the area data pertains. This is expressly
for the purpose
;;; of exporting the area data to a spreadsheet.
;;; If you create a block with only two attribute definitions then the line;
;;; (command "insert" "areaz" pt sc "" "" ar mar "" "")
;;; should read
;;; (command "insert" "areaz" pt sc "" "" ar mar )
;;; To use, the area must first have a polyline outline
;;; Start plarea, then pick the polyline. Next, pick a point at which
;;; to locate the note. The area is then displayed in square metres and
square feet.

(defun plareaerr ()
(setvar "cmdecho" 1)
(print "ERROR - Command aborted")
(command "_.undo" "_end")
)

(defun c:plarea (/ a ar mar pt sc pt1)
(command "_.undo" "_g")
(setq *error* olderr *error* plareaerr)
(setvar "cmdecho" 0)
(setq sc (getvar "dimscale"))
(setq pt1 (getpoint "Pick a closed polyline: "))
(command "area" "e" pt1)
(setq ar (getvar "area"))
(setq ar (/ ar 1000000))
(setq mar (strcat (rtos (* ar 10.7639104) 2 0)))
(setq ar (strcat (rtos ar 2 1)))
(setq pt (getpoint "select location for area note: "))
(command "insert" "areaz" pt sc "" "" ar mar "" "")
(setq *error* olderr)
(command "_.undo" "_end")
)

wrote in message news:5069787@discussion.autodesk.com...
I have see it before but can't find it now. I an looking for a lisp routine
that will calculate the area of serval different polylines and put the area
in the center of the pline.
The purpose is calculating the areas of multiple rooms and listing that area
on the plan.
Message 3 of 14
Anonymous
in reply to: Anonymous

Thanks for the help. I seen to be having some troubles though. When the lisp routine asks me to pick a Pline I can't select one. It is like autocad is not in the select mode.
Any ideas?
Also anyway to just tag all the plines at once?
Message 4 of 14
Anonymous
in reply to: Anonymous

Sorry, there seems to be a couple of lines missing.
There needs to be some statements added to get the current OSMODE, store it,
and then change the OSMODE to 512, and then back to the old OSMODE at the
end of the routine. I have a version somewhere with these lines coorectly
inserted which I'll post tomorrow - if I remember!.

In the meantime, this is almost right(I think)...

;;; Adapted from 'getarea.lsp by Omura Illustration (C) 1995 by Bill DeShawn
& are_e.lsp by
;;; Jim (dedalos_2000@hotmail.com). Further, tiny
;;; modifications by Zac Carey (ZJC), 2002.
;;; Program to simultaneously place metric and imperial area information in
a drawing.
;;; Make sure that the the block 'areaz.dwg' is located in the support
directory.
;;; This block should contain, as a minimum, two attribute definitions, for
metric and
;;; imperial data which, when writing the block, should be selected in that
order.
;;; Ideally, each of these attribute definitions should be on different, and
readily,
;;; identifiable layers. My block contains a third attribute definition for
specifying the
;;; function that the given area is to be used for - and a fourth for
specifying the floor
;;; no. or no. of floors to which the area data pertains. This is expressly
for the purpose
;;; of exporting the area data to a spreadsheet.
;;; If you create a block with only two attribute definitions then the line;
;;; (command "insert" "areaz" pt sc "" "" ar mar "" "")
;;; should read
;;; (command "insert" "areaz" pt sc "" "" ar mar )
;;; To use, the area must first have a polyline outline
;;; Start plarea, then pick the polyline. Next, pick a point at which
;;; to locate the note. The area is then displayed in square metres and
square feet.

(defun plareaerr ()
(setvar "cmdecho" 1)
(print "ERROR - Command aborted")
(command "_.undo" "_end")
)

(defun c:plarea (/ a ar mar pt sc pt1)
(command "_.undo" "_g")
(setq *error* olderr *error* plareaerr)
(setvar "cmdecho" 0)
(setq osmode (getvar "osmode"))
(setvar "osmode" 512)
(setq sc (getvar "dimscale"))
(setq pt1 (getpoint "Pick a closed polyline: "))
(command "area" "e" pt1)
(setq ar (getvar "area"))
(setq ar (/ ar 1000000))
(setq mar (strcat (rtos (* ar 10.7639104) 2 0)))
(setq ar (strcat (rtos ar 2 1)))
(setq pt (getpoint "select location for area note: "))
(command "insert" "areaz" pt sc "" "" ar mar "" "")
(setq *error* olderr)
(setvar "osmode" osmode)
(command "_.undo" "_end")
)



wrote in message news:5070105@discussion.autodesk.com...
Thanks for the help. I seen to be having some troubles though. When the lisp
routine asks me to pick a Pline I can't select one. It is like autocad is
not in the select mode.
Any ideas?
Also anyway to just tag all the plines at once?
Message 5 of 14
Anonymous
in reply to: Anonymous

I think this script works better...

;;; Adapted from 'getarea.lsp by Omura Illustration (C) 1995 by Bill DeShawn
& are_e.lsp by
;;; Jim (dedalos_2000@hotmail.com). Further, tiny
;;; modifications by Zac Carey (ZJC), 2002.
;;; Program to simultaneously place metric and imperial area information in
a drawing.
;;; Make sure that the the block 'areaz.dwg' is located in the support
directory.
;;; This block should contain, as a minimum, two attribute definitions, for
metric and
;;; imperial data which, when writing the block, should be selected in that
order.
;;; Ideally, each of these attribute definitions should be on different, and
readily,
;;; identifiable layers. My block contains a third attribute definition for
specifying the
;;; function that the given area is to be used for - and a fourth for
specifying the floor
;;; no. or no. of floors to which the area data pertains. This is expressly
for the purpose
;;; of exporting the area data to a spreadsheet.
;;; If you create a block with only two attribute definitions then the line;
;;; (command "insert" "areaz" pt sc "" "" ar mar "" "")
;;; should read
;;; (command "insert" "areaz" pt sc "" "" ar mar )
;;; To use, the area must first have a polyline outline
;;; Start plarea, then pick the polyline. Next, pick a point at which
;;; to locate the note. The area is then displayed in square metres and
square feet.

(defun plareaerr ()
(setvar "cmdecho" 1)
(print "ERROR - Command aborted")
(command "_.undo" "_end")
)

(defun c:plarea (/ a ar mar pt sc pt1)
(command "_.undo" "_g")
(setq *error* olderr *error* plareaerr)
(setvar "cmdecho" 0)
(setq sc (getvar "dimscale"))
(setq os1 (getvar "osmode"))
(setvar "osmode" 512)
(setq pt1 (getpoint "Pick a closed polyline: "))
(command "area" "e" pt1)
(setq ar (getvar "area"))
(setq ar (/ ar 1000000))
(setq mar (strcat (rtos (* ar 10.7639104) 2 0)))
(setq ar (strcat (rtos ar 2 1)))
(setq pt (getpoint "select location for area note: "))
(command "insert" "areaz" pt sc "" "" ar mar "" "" "" )
(setvar "osmode" os1)
(setq *error* olderr)
(command "_.undo" "_end")
)

"laptop" wrote in message
news:5070128@discussion.autodesk.com...
Sorry, there seems to be a couple of lines missing.
There needs to be some statements added to get the current OSMODE, store it,
and then change the OSMODE to 512, and then back to the old OSMODE at the
end of the routine. I have a version somewhere with these lines coorectly
inserted which I'll post tomorrow - if I remember!.

In the meantime, this is almost right(I think)...

;;; Adapted from 'getarea.lsp by Omura Illustration (C) 1995 by Bill DeShawn
& are_e.lsp by
;;; Jim (dedalos_2000@hotmail.com). Further, tiny
;;; modifications by Zac Carey (ZJC), 2002.
;;; Program to simultaneously place metric and imperial area information in
a drawing.
;;; Make sure that the the block 'areaz.dwg' is located in the support
directory.
;;; This block should contain, as a minimum, two attribute definitions, for
metric and
;;; imperial data which, when writing the block, should be selected in that
order.
;;; Ideally, each of these attribute definitions should be on different, and
readily,
;;; identifiable layers. My block contains a third attribute definition for
specifying the
;;; function that the given area is to be used for - and a fourth for
specifying the floor
;;; no. or no. of floors to which the area data pertains. This is expressly
for the purpose
;;; of exporting the area data to a spreadsheet.
;;; If you create a block with only two attribute definitions then the line;
;;; (command "insert" "areaz" pt sc "" "" ar mar "" "")
;;; should read
;;; (command "insert" "areaz" pt sc "" "" ar mar )
;;; To use, the area must first have a polyline outline
;;; Start plarea, then pick the polyline. Next, pick a point at which
;;; to locate the note. The area is then displayed in square metres and
square feet.

(defun plareaerr ()
(setvar "cmdecho" 1)
(print "ERROR - Command aborted")
(command "_.undo" "_end")
)

(defun c:plarea (/ a ar mar pt sc pt1)
(command "_.undo" "_g")
(setq *error* olderr *error* plareaerr)
(setvar "cmdecho" 0)
(setq osmode (getvar "osmode"))
(setvar "osmode" 512)
(setq sc (getvar "dimscale"))
(setq pt1 (getpoint "Pick a closed polyline: "))
(command "area" "e" pt1)
(setq ar (getvar "area"))
(setq ar (/ ar 1000000))
(setq mar (strcat (rtos (* ar 10.7639104) 2 0)))
(setq ar (strcat (rtos ar 2 1)))
(setq pt (getpoint "select location for area note: "))
(command "insert" "areaz" pt sc "" "" ar mar "" "")
(setq *error* olderr)
(setvar "osmode" osmode)
(command "_.undo" "_end")
)



wrote in message news:5070105@discussion.autodesk.com...
Thanks for the help. I seen to be having some troubles though. When the lisp
routine asks me to pick a Pline I can't select one. It is like autocad is
not in the select mode.
Any ideas?
Also anyway to just tag all the plines at once?
Message 6 of 14
Anonymous
in reply to: Anonymous

Laptop -
I must be missing something. I still can't get this to work. When I run the lisp routine it lets me select a pline and quits. Looks like it is messed up when trying to inser 'areaz'. The insert command is not executing.

THanks
Message 7 of 14
EC-CAD
in reply to: Anonymous

Did you make up the block 'areaz', with (2) or (4)
attributes ?, And, is that block on a support path ?

Bob
Message 8 of 14
Anonymous
in reply to: Anonymous

I made it with two atributes. Yes it is in the support directory. I tried inserting it and it seems to insert just fine.
Message 9 of 14
EC-CAD
in reply to: Anonymous

Here is a working copy, modified.
(defun plareaerr ()
(setvar "cmdecho" 1)
(print "ERROR - Command aborted")
(command "_.undo" "_end")
)

(defun c:plarea (/ a ar mar pt sc pt1)
(command "_.undo" "_g")
(setq *error* olderr *error* plareaerr)
(setvar "cmdecho" 0)
;;(setq sc (getvar "dimscale")); changed
(setq os1 (getvar "osmode"))
(setvar "osmode" 512)
(setq pt1 (getpoint "Pick a closed polyline: "))
(command "area" "e" pt1)
(setq ar (getvar "area"))
(setq ar (/ ar 1000000))
(setq mar (strcat (rtos (* ar 10.7639104) 2 0)))
(setq ar (strcat (rtos ar 2 1)))
(setq pt (getpoint "select location for area note: "))
(command "-insert" "areaz" pt "1" "" "" ar mar); changed
(setvar "osmode" os1)
(setq *error* olderr)
(command "_.undo" "_end")
)

Bob
Message 10 of 14
Anonymous
in reply to: Anonymous

We're getting closer. This works up to the point were it inserts the block "areaz". Then the dialogue box comes up asking me for the attributes.
Maybe I have created the block wrong. ECCAD - did you do this? Maybe you could email me a copy of that block.
My email is: cp-energycontrol@qwest.net

Thanks,
Corey
Message 11 of 14
EC-CAD
in reply to: Anonymous

Add this:
(initdia 0); no dialog
(command "-insert" "areaz" pt "1" "" "" ar mar); changed

Bob
Message 12 of 14
EC-CAD
in reply to: Anonymous

You have Mail.
:)
Bob
Message 13 of 14
DbrO
in reply to: Anonymous

Can you send me this file too? I'm also having difficulties with the block I created, probably using wrong tags in the attribute.

d.brorens@home.nl Message was edited by: DbrO
Message 14 of 14
EC-CAD
in reply to: Anonymous

I didn't send a .dwg file, I sent him an E-Mail.
For the code above, you need just (2) attributes
defined in the block. It doesn't matter what the
Tagname is.. Make your attributes Visible, with
no Constant or Default Value. Do fill in a prompt.
In code, do:
(initdia 0)
(command "-insert" "areaz" pt "1" "" "" ar mar)
The above should insert the block at location 'pt',
scale it 1x1, orientation 0, and fill in (2) attributes.

Bob

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost