Adding attribute value column into block data export csv through lisp

Adding attribute value column into block data export csv through lisp

abdul.raufJJ89F
Advocate Advocate
3,765 Views
22 Replies
Message 1 of 23

Adding attribute value column into block data export csv through lisp

abdul.raufJJ89F
Advocate
Advocate

Hi all,

I have a lisp that export block data (block name, Rotation, Layer and co-ordinates) to CSV into the same location as of dwg. It has two options -either for all blocks or layer-wise.
So I need to add one more column for an attribute value in the CSV. The blocks will always have a single attribute tag (although block name and tag name will vary from case to case).

Please find the attached sample Image (additional column required highlighted by yellow) showing the desired result required with sample dwg.
Also, please find the attached lisp file.
Thanks



0 Likes
Accepted solutions (1)
3,766 Views
22 Replies
Replies (22)
Message 2 of 23

dlanorh
Advisor
Advisor
If you post a drawing saved as AutoCAD 2010 or earlier, I can update my lisp.

I am not one of the robots you're looking for

0 Likes
Message 3 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh  Please find the attached dwg in the 2010 version.


0 Likes
Message 4 of 23

dlanorh
Advisor
Advisor
One question, does this require sorting on the contents (textstring) of the attribute? I will be busy for the next couple of hours but after that it shouldn't take more than an hour.

I am not one of the robots you're looking for

0 Likes
Message 5 of 23

abdul.raufJJ89F
Advocate
Advocate

Yes I want them sorted in order from lowest to highest value

0 Likes
Message 6 of 23

dlanorh
Advisor
Advisor

Attached is adapted lisp. Please check that this is to requirements, and if not let me know what need altering.

 

The current sort is by attribute string, block then layer.

 

I am not one of the robots you're looking for

0 Likes
Message 7 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 

Thanks but it seems there is an issue with sorting. Here I am attaching the sample drawing in 2010 format and snap of output CSV. It sorts as T-1, T-10,T-11 rather than as T-1, T-2, T-3 etc.

Please have a look

0 Likes
Message 8 of 23

dlanorh
Advisor
Advisor

It's not an issue, I am sorting the text as text, not number and this usually happens when you do that. That was my oversight.

 

I think I have something somewhere, or can find something on the forums to sort this out.

I am not one of the robots you're looking for

0 Likes
Message 9 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 

I would like to mention that attribute value will be of either a prefix (letter) - number or simply number for all the cases.

0 Likes
Message 10 of 23

dlanorh
Advisor
Advisor

OK. Attached is the revised lisp. This should sort properly. I have tested it in your supplied drawing by copying and adjusting the attribute text.

I am not one of the robots you're looking for

0 Likes
Message 11 of 23

dlanorh
Advisor
Advisor

@abdul.raufJJ89F wrote:

@dlanorh 

I would like to mention that attribute value will be of either a prefix (letter) - number or simply number for all the cases.


Is this a mix and match? If so does the prefix need to be taken into account in the sort?

I am not one of the robots you're looking for

0 Likes
Message 12 of 23

Sea-Haven
Mentor
Mentor

The simplest way to fix the sort problem is t-1,t-10,t-11 etc use t-01,t-02 etc 

 

I am pretty sure like you that this sort problem has been solved tried to find for something else I think it was one of Lee-mac's brilliant Lambda's. looks at ascii codes for numbers.

0 Likes
Message 13 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 

There will be no mix cases. It will be either of two types-
       a. The attribute will be of the format prefix (letter)-number
            Eg- T-1, T-2,T-3,...........
                   AB-10, AB-20,AB-30,.............

       b.The attribute will be simply a number or with a numeric prefix 
          Eg- 1,2,3,.........
                  501,502,503,..............
                   4-1, 4-2,4-3,................

0 Likes
Message 14 of 23

dlanorh
Advisor
Advisor
Accepted solution

Try the attached.

 

 

I am not one of the robots you're looking for

Message 15 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh  Much thanks..It is working fine!

Message 16 of 23

dlanorh
Advisor
Advisor

Excellent.😁

I am not one of the robots you're looking for

Message 17 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 
I hope you are doing well!
I need your additional help with this case where the block will have two attributes. I want only the second attribute value in the excel as a column (and not the first one) in this case.
Note that the second attribute has the property set as "Invisible" and here I don't require attribute data to be sorted in any specific order.

I am attaching the sample dwg (2010 version), your original blkdata lisp and the desired result image.
Thanks


0 Likes
Message 18 of 23

dlanorh
Advisor
Advisor

Attached is modified lisp. I have renamed it CP_ID and this is also the command to run it. Also attached is produced csv file. This has also been renamed to *- CP_ID Block Data". If you want something else you can change it in the lisp.

 

 

I am not one of the robots you're looking for

Message 19 of 23

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 

You are amazing. Thanks for your help. 
I would like to mention that the tag name will not be constant (CP_ID) for various cases but it will be always invisible for all cases. 
Just for depicting my case to you, I have randomly put "CP_ID" in the CSV column heading which I can change along with output CSV filename later on. in the lisp, as you mentioned above.
I just want to ensure that your lisp runs for any tag name. 

In addition to the above-

Just one more thing I would like to ask, in future I may need to get both attributes values in the excel column.- Sequence (same as per the above sorting logic done by you) and CP_ID.I am attaching an Image depicting the format of the desired output.
You can use the above dwg attached for this one.
Thanks for the consideration!!












0 Likes
Message 20 of 23

dlanorh
Advisor
Advisor

Will try to sort it out later this afternoon. 

I am not one of the robots you're looking for