PDA

View Full Version : Attribute extraction to xls file


lee.johnson
2008-07-09, 02:23 AM
First off I haven't really done any Lisp programming since Rel 14.I have usally used the attribute extraction tool in autocad. Starting with 2006 the tool changed, I have been saving the dwg to 2000 and using the extraction tool to copy the attributes in Excel. I have done this to the present day.Each new versaion we get of AutoCAD, the Extraction tool gives me more junk that i don't need.If we ever get 2009, it probally be worse, so I decided to look into using lisp to extract just the stuff I want (ie. x,y cords, block name, up to 4 device addresses, and candela ratings).
I have looked into some tutorials and went to the online Lisp site, but I seem to find any thing that can help me.So, at this point I don't even know where to start. I know you need to get a selection set but how do you do it without picking the device or devices (globally)?

Thanks

Confused

jmcshane
2008-07-09, 01:27 PM
I am not really sure what you mean by "4 Device Addresses, and candela ratings".
Are these attributes?
Maybe you could post and example of what you need


Here is one that I use sometimes to export to a csv.
It gathers the block name, x coord, ycoord and the attribute value of a block we use for spot levels.



(defun c:DataOut (/ f Linetowrite ctr item Obj)
(setq f (open "c:\\DataOut.csv" "w"))
(setq Linetowrite (setq ob (ssget "x" '((0 . "INSERT") (2 . "SPOT LEVEL")))))
(princ "\nNow Writing to File C:\Points.csv : ")
(progn
(setq ctr 0)
(repeat (sslength Linetowrite)
(setq item (ssname Linetowrite ctr))
(setq Obj (vlax-ename->vla-object item))
(write-line
(strcat
(vla-get-name Obj)
","
(rtos
(car (vlax-safearray->list
(vlax-variant-value (vla-get-InsertionPoint Obj))
)
)
)
","
(rtos
(cadr (vlax-safearray->list
(vlax-variant-value (vla-get-InsertionPoint Obj))
)
)
)
","
(vla-get-textstring
(nth 0
(vlax-safearray->list
(variant-value
(vla-getattributes
Obj
)
)
)
)
)
)
f
)
(setq ctr (1+ ctr))
)
)
(close f)
(princ)
)

lee.johnson
2008-07-09, 03:56 PM
Yes, "4 Device Addresses, and candela ratings" are attribute. I work designing fire alarm systems. So, basically the "device address" is the circuit and were thedevice fall in that circuit. Some devices have one circuit and others have two. Certian devices have the "candela rating" associated with it. Depending on the candela rating the current draw for each device can change.
attached is a sample xls file that I use as a Data Dump and have another files that manipultes the data for my calculations

I hope this clears it up more

Thanks

jmcshane
2008-07-11, 10:42 AM
Hi Lee,

I'm sorry I haven't had time to return to this, maybe someone else out there can jump in
and give you a hand.

If not I will try next week.

Does each block have all of these attributes?
Are the tags for each attribute the same as the top line of the sample .XLS?

John

irneb
2008-07-11, 02:35 PM
Why not simply use the Express tool ATTOUT. It saves to a tab delimited TXT file which can also be opened in Excel, modified there & then re-imported into your drawing using ATTIN.

I use this very often for changing batches of door types for my schedule.

lee.johnson
2008-07-11, 04:11 PM
irneb,

Attout is one of those things I haven't used in years so i forgot it was there. I tried it this morning. All the Attributes I need are there.

I mainly use the data for battery & and voltage drop calaculations so there is no need to for the attin part of the code. I just need to find out how to load the text file and bypass the three dialog boxes to open a txt file. Can the attout.lsp code be changed to save it to a csv file? Once I get the data in to excel, I can manipulate the data from there.

Thanks for reminding me of that command

Lee

irneb
2008-07-11, 04:36 PM
Well, with some time on your hands I suppose the ATTOUT can be modified to use CSV instead. But to open the TXT file, right-click on it & choose Open With & Select Excel. If Excel's not listed there use the Choose Program... option at the bottom which should open the dialog to select one of your installed programs (as 3rd Capture). See the screen captures.

irneb
2008-07-11, 04:43 PM
The other solution would be to use the Data Extraction system, the benefit here is you can perform multiple drawings in one step. In 2008 it's called Data Extraction, previously it had some other name ... can't remember just now.

Anyway, the D.E. can extract to an AutoCAD table / directly into a CSV / XLS / XLSX file. If you've chosen a Table, then you can select the table, right-click on it & Export to CSV - the table can then be updated by simply Updating Data links. You don't have to go though the whole process again.

lee.johnson
2008-07-11, 04:49 PM
John,

Not all blocks have the same attribute, but each group type have the same

Initiation devices have 1 to 2 attributes, and signaling devices have 2 to 4 attributes.

I think Attout.lsp can give me what I want. can this lisp routine be change to meet my needsor would that violate the copyright law.

The changes I would like are: Multi-files attout, file format to csv instead of txt

one step at a time.