Lisp to change layers based on polygon OD

Lisp to change layers based on polygon OD

Sasa_MacuraFQQQL
Community Visitor Community Visitor
609 Views
5 Replies
Message 1 of 6

Lisp to change layers based on polygon OD

Sasa_MacuraFQQQL
Community Visitor
Community Visitor

Hi, 
I've been using this forum to help with some lisp routines over the years and am working on one where I'm stuck enough that I finally decided to post.  
I have a .dwg file with some hex objects from the FCC site that I would like to isolate and highlight.  The polygons have object data that references a hex id. 
The objective of my routine is to be able to select a .csv file with those hex8id values, and have the lisp routine change the layers and of all the polygons who have matching object data to the list. 

The .csv has the id information in Column L


In this example the dwg has the information in:
OD:West_Virginia_hex9s
h3index

Any guidance would be of great help. I've been trying to find the answer online for a while now.  I have found a routine that identifies the OD but it doesn't show the h3index so I'm back to the beginning. 

0 Likes
610 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

I can not test but something like this.

 

(setq ent (car (entsel "\n Select Polyline (or press Enter to Exit): ")))
(setq odname (ade_odgettables ent))
(setq ans (ade_odgetfield ent odname "h3index" 0))

 Its not supported in my Bricscad. 

0 Likes
Message 3 of 6

hosneyalaa
Advisor
Advisor

It is preferable that the data be in an Excel file

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@hosneyalaa wrote:

It is preferable that the data be in an Excel file


A .csv file is a type of Excel file [a spreadsheet], and is far preferable to a .xlsx file if that's what you mean, for purposes of reading data into AutoCAD.

 

If I use (open) with their .csv file, and (read-line) twice to get past the header line and pull the first row of actual data from it, I get:

 

"0005283221,130788,MCTV,1056486024,40,200,15,1,X,WV,5.4069E+14,892aaac2623ffff"

 

which can be separated around the commas for usable pieces of data.  But if I simply save it to Excel .xlsx format, without doing anything at all to it otherwise [no formatting, font assignment, etc.], by the same process, for the first (read-line) which should be the header line, I get this entirely un-usable return:

 

"PK\003\004\024\000\006\000\010\000\000\000!\000bîh^\001\000\000\004\000\000\023\000\010\002[Content_Types].xml ¢\004\002( \000\002\000\ .... and over 500 more \000\ entries that I deleted .... \000\000¬”ËNÃ0\020E÷HüCä-Jܲ@\0105í‚Ç\022*Q>Àēƪc[žiiÿž‰û\020B¡\025j7±\022ÏÜ{2ñÍh²nm¶‚ˆÆ»R\014‹ÈÀU^\e7/ÅÇì%¿\027\031’rZYï \024\e@1\031__f›\000˜q·ÃR4DáAJ¬"

 

And if I do (read-line) again, hoping for the first line of actual data, it returns nil.

 

If I save the .csv to the older .xls format, the first (read-line) is at least a heck of a lot shorter, but still useless:

"ÐÏ\021ࡱ"

But the second still returns nil.

 

Or do I misunderstand what you mean by an Excel file being preferable?  Do you mean something other than .xls or .xlsx file type?  Are you talking about an entirely different way of pulling data from it than the typical (open) / (read-line) approach?

Kent Cooper, AIA
0 Likes
Message 5 of 6

hosneyalaa
Advisor
Advisor

Thanks for the explanation

There is a problem when separating a line into words and from one version of Excel to another Sometimes it is, or; or ...

So I prefer Excel

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Yes depending on where you are in the world matching a language pack, the Excel -> csv will use either a Comma "," or a semi colon ";" when using one of the strip csv line into a list just make sure using correct character is used as delimiter. It's pretty obvious when a sample csv is supplied. Don't see a problem, end user knows which type they have.

 

I use a method by Lee-mac

; tab 9 space 32 comma 44 semicolom 59

; thanks to Lee-mac for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position 32 str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
)

 Very simple to change to correct character.