PDA

View Full Version : Autocad distance measurement to excel



virendra.chavda697831
2015-04-14, 04:16 PM
Hi everyone,

i am new to autolisp. apologies if i mention stupid things. i work as a quantity surveyor in building projects. We mostly get autocad drawings from consultants and prepare quantities spreadsheets. I wonder if i have a routine which can directly export data from autocad to excel.

The routine should ask for options (what you want to export) i.e. distance, length, area or text. once we make a choice it will ask for appropriate selection. For example, for distance it will ask select first point then second point. In third step it may ask for "Specify column range in excel" i.e. A,B,C etc. (I assume that file name and sheet name are predefined. plz guide me on this)

On execution of command, it will find non empty cell in specified workbook and puts the value.

i know i won't get cake on this but bread will be fine. i also checked getexcel.lsp. But, it lacks the functionality i need. i am ready to learn autolisp. Suggest me some good resources to achieve my objective.

thank you

virendra

LSElite
2015-04-15, 01:23 AM
Hey Virendra, welcome to the forum.

I have had the same need in the past and have found a simple work around to be, to write the information to text files and use a simple vba macro to read and write into excel.
There are a lot of great resources for reading and writing to text files in both lisp and VBA.
It might prove to be an easier approach than interfacing directly with excel from lisp.
It also has the benefit of keeping your autocad routine quick.
Hope this helps.

virendra.chavda697831
2015-04-17, 02:40 PM
Hi LSElite,

Thanks a lot for the reply. as u said i googled it. but couldnt get appropriate resources. importantly, distance measurement export. i.e. u select two points and distance between them exported to text file or excel. or else, can u direct me to your resources??

thanks again

virendra

LSElite
2015-04-19, 11:47 PM
No worries mate.
I would first get the 2 points from the user

(setq p1 (getpoint "Select First Point: "))
(setq p2 (getpoint "Select Second Point: "))

Then you would get the distance between the 2 points.

(setq dist (distance p1 p2))

Then you need this write the distance out to a text file.
Here are some handy resources for text file handling:
http://www.jefferypsanders.com/autolispintr_rw.html
http://www.afralisp.net/autolisp/tutorials/file-handling.php

That will get you half way the next step would then be to read it from a macro in excel.
Here is a reference which should help:
http://www.excel-easy.com/vba/examples/read-data-from-text-file.html

If you need any more help let me know.
If you want I can give you a few more tips when you get to the VBA macro.