Author Topic: Reading in Coordinate and Attributes  (Read 2705 times)

0 Members and 1 Guest are viewing this topic.

wannabe

  • Guest
Reading in Coordinate and Attributes
« on: April 15, 2009, 07:35:37 AM »
Just on a theoretical level, although examples of code wouldn't be perturbing, I'm contemplating the best way to read in coordinates and attributes from a file. The obstacle in my mental design pattern at the moment is distinguishing between attributes.

Say for example I read from the stream having already format the file to show coordinates and attributes for each block all on the same line. Here's the hurdle: how can I distinguish where there is a space in the text that will be used for the block's first attribute ( eg "block one") and a space between the information that will be used to populate the next field (eg "Block one's type").

My current logic is that maybe I should have the attribute label specified in the file prior to the vallue - this wouldn't make my program much of an improvement to a script file, though - if at all.

Checking if there are two consective blank spaces seems to be the pinnacle of my current intentions. This would be flawed fundamentally if the file being read was a .CSV.though.

All contributions welcome.

Glenn R

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #1 on: April 15, 2009, 07:57:19 AM »
You need a delimiter and it sounds like a comma (CSV) would fit the bill.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reading in Coordinate and Attributes
« Reply #2 on: April 15, 2009, 08:02:17 AM »
Agree with Glenn: If your reading/writing simple text files csv should do the trick, failing that xml.

If you're reading/writing binary files you could just use the the null char or some low ascii (< 32) values as field sentinels/flags/markers.

Am I understanding the question correctly?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Glenn R

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #3 on: April 15, 2009, 08:06:23 AM »
Actually, I'll second MP's XML suggestion as well - it is well suited to this sort of thing.

Draftek

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #4 on: April 15, 2009, 08:10:22 AM »
I would go with XML also.

wannabe

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #5 on: April 15, 2009, 08:29:10 AM »
I was hoping that my application would be robust enough to deal with a number of filetypes: .txt, .csv, .doc. Have I correctlly inferred that your suggesting I should convert all the files to XML first and then let the core of my application deal with XML files. So there is methodology, or just a method, to convert my original file to XML and then the core components of my application to populate a collection with a record from each line of the XML file?

My knowledge of XML needs some development, so tonight I will do a bit of research.

Thanks for the input.

Glenn R

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #6 on: April 15, 2009, 08:31:34 AM »
Without seeing your 'files', we'd only be guessing.

wannabe

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #7 on: April 15, 2009, 08:39:38 AM »
I'll extrapolate the non-confidential data in some files and send them across when possible. Basically I get .txt. .csv, .xls and .doc files that contain an X,Y coordinate and optionally some information which will be used to populate the attributes in a block.

My goal is to be able to automate and minimise as much of the work as possible and eclipse the proficiency of a "faffy" script file that does a similar job.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reading in Coordinate and Attributes
« Reply #8 on: April 15, 2009, 09:18:45 AM »
Generally speaking, I'd code the data normalization part of the application (read/parse .txt, .csv files yada) as a separate module/library (you may find the bulk of the work here has already been done many times before), as that activity is not unique to your application greater. The actual solution would expect data in precisely one format, as indicated by it's exposed interface. Said modularization would be transparent to the user/batch mechanism. MP wanders off to find a coffee ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

wannabe

  • Guest
Re: Reading in Coordinate and Attributes
« Reply #9 on: April 15, 2009, 12:44:59 PM »
 Have you ever tried green or white tea?

Anyway, enjoy your coffee and thanks for the comments. Quite helpful.