Jump to content

Insert separator lines of coordinates in a txt file


teknomatika

Recommended Posts

Greetings.

Is it possible, with a routine autolisp, read a txt file and enter each line type a comma separator in line position to be determined by routine?

Specifically, I have a file of coordinates but no tab for it and wanted to enter their tabs, showing the position of each.

 

Example of what I have:

 

5001100926.946000096.8278000221.264000NL

5001101025.256000096.9432000220.437800NE

5001101122.944000097.0376000219.154600NE

5001101222.372000096.9222000218.697200NM

 

Example of what I want:

 

50011009,26.9460000,96.8278000,221.264000,NL

50011010,25.2560000,96.9432000,220.437800,NE

50011011,22.9440000,97.0376000,219.154600,NE

50011012,22.3720000,96.9222000,218.697200,NM

 

I appreciate the help

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • MSasu

    10

  • teknomatika

    10

  • pBe

    6

  • eldon

    1

Top Posters In This Topic

Posted Images

This is entirely possible as long there is a criteria to use when split the source strings.

Which is the source of that data?

Link to comment
Share on other sites

That's a programmers nightmare if i see one.

 

5001100926.946000096.8278000221.264000NL

 

could be any of the possible combinations

 

50011009,26.9460000,96.8278000,221.264000NL

50.01100,926.946.0000,96827.8000,221.264000,NL

500,1100926.94600009,68.278000,221.264000NL

5001100926,94.0000,968278.000,221.264000NL

....

....

 

What will be the basis then?

Edited by pBe
Link to comment
Share on other sites

This is entirely possible as long there is a criteria to use when split the source strings.

Which is the source of that data?

 

Msasu,

It is a file in txt format, consisting of lines, equal or similiar my example. Of course, the number of lines can be different.

In alternative is a file type (SDR produced by a surveying equipment Sokkia).

I can easily debug the SDR file, but not on the question of introduction of comma separators.

I do not know if I did not realize or understand the question.

Link to comment
Share on other sites

As pBe pointed, without unequivocal criteria for separation, one can place any number of commas in any locations to get (at least theoretical) an infinity of different results.

Can you get a separator other than comma from the said equipment?

Link to comment
Share on other sites

Or, can you get from said equipment the data separated on lines - I mean one data per one line? This format can be easily converted into rows of data if you know for sure that 5 (as example) consecutive lines will be joined with comma to form a row.

Link to comment
Share on other sites

The data looks like a simple space delineated file, with columns 1 to 8 as the identifier, columns 9 to 18 as coordinate 1, columns 19 to 28 as coord 2, columns 29 to 38 as coord 3, and columns 39 and 40 as another identifier.

 

I am afraid that pBe introduced a red herring on the combinations of data, as the OP had clearly stated the required output in the original post.

 

Personally, I would do that with Excel which can split up data according to the columns and then save as a CSV file.

Link to comment
Share on other sites

Pbe,

MSasu:

 

In fact, each line in the source has this setting type:

 

09F1500110036.2210000096.1930000267.875600ND

 

The first five characters (09F15001) I can easily delete using an editor like notepad or notepad + +

 

Then, using the routine autolisp, I wanted to add a comma separator defining the position previously. In the example:

 

1003,6.22100000,96.1930000,267.875600, ND

 

This corresponds to the order: point number, X coordinate, Y coordinate; Z coordinate; code.

 

I apologize if I did not yet understand.

Link to comment
Share on other sites

That's a programmers nightmare if i see one.

 

5001100926.946000096.8278000221.264000NL

 

could be any of the possible combinations

 

50011009,26.9460000,96.8278000,221.264000NL

50.01100,926.946.0000,96827.8000,221.264000,NL

500,1100926.94600009,68.278000,221.264000NL

5001100926,94.0000,968278.000,221.264000NL

....

....

 

What will be the basis then?

 

Pbe,

Yes, any combination is possible.

What I want is that the routine, step by step, let me take control in the positioning of the comma separator.

 

 

The data looks like a simple space delineated file, with columns 1 to 8 as the identifier, columns 9 to 18 as coordinate 1, columns 19 to 28 as coord 2, columns 29 to 38 as coord 3, and columns 39 and 40 as another identifier.

 

I am afraid that pBe introduced a red herring on the combinations of data, as the OP had clearly stated the required output in the original post.

 

Personally, I would do that with Excel which can split up data according to the columns and then save as a CSV file.

 

The reasoning seems correct, but in fact there is no space as the delimiter. It would be good because it would facilitate the task.

Link to comment
Share on other sites

The data looks like a simple space delineated file, with columns 1 to 8 as the identifier, columns 9 to 18 as coordinate 1, columns 19 to 28 as coord 2, columns 29 to 38 as coord 3, and columns 39 and 40 as another identifier.

If this is the case, then is very easy to treat the data programmatically. But I still tend to agree with @pBe - what if the coordinates are smaller/bigger than 2 digits and/or have a smaller/bigger number of decimals?

Link to comment
Share on other sites

I am afraid that pBe introduced a red herring on the combinations of data, as the OP had clearly stated the required output in the original post.

 

Well, not really Eldon

 

Notice clearly there are no space in the example:

5001100926.946000096.8278000221.264000NL

 

How could you determine that the first "," goes before 26.946

50011009,26.9460000,96.8278000,221.264000,NL

 

Whats preventing you from putting the frist comma before 9?

 

Yes , The OP did show an output, now we can say comma goes before 2, we can determine that now because the output is shown. but that will be assuming the Y coordinate is always 2 numbers before decimals. and that IMO is not good programming

 

And yeah, i might have exag a bit to prove a point :)

Link to comment
Share on other sites

If @eldon is correct, then try:

(setq stringTemp "5001100926.946000096.8278000221.264000NL")
(setq stringNew (strcat (substr stringTemp  1   ","
                       (substr stringTemp  9 10) ","
                       (substr stringTemp 19 10) ","
                       (substr stringTemp 29 10) ","
                       (substr stringTemp 39)))

But again, this works only if the structure of data is constant!

Link to comment
Share on other sites

But again, this works only if the structure of data is constant!

 

And THAT exactly is what i'm drving at.

 

In fact, each line in the source has this setting type:

09F1500110036.2210000096.1930000267.875600ND

The first five characters (09F15001) I can easily delete using an editor like notepad or notepad + +

Then, using the routine autolisp, I wanted to add a comma separator defining the position previously. In the example:

1003,6.22100000,96.1930000,267.875600, ND

 

Take this for example.

OUTPUT

1003,6.22100000,96.1930000,267.875600, ND

 

Why not

100,36.221000009,6.193000026,7.875600, ND

 

The point is ,HOW can you tell where the value starts and ends?

 

100926.946000096.8278000221.264000NL

10036.2210000096.1930000267.875600ND

Link to comment
Share on other sites

If this is the case, then is very easy to treat the data programmatically. But I still tend to agree with @pBe - what if the coordinates are smaller/bigger than 2 digits and/or have a smaller/bigger number of decimals?

 

Mircea,

I understand. In fact in some lines there may be a major / minor number of decimal places. Consider the following sequence, the first line, which verifies that the positioning point may move to the right, depending on the units of each coordinate (units, tens, hundreds). In these cases, the difference of characters is offset by the elimination of decimal places in the same coordinated.

 

In these cases, besides the importance of being able to define the routine placement of the comma separator, I have to be careful in treating these lines eventually treating them separately. I do not see another way to fix the problem.

 

09F15004128012.1640000103.357600113.245600OD

09F1500412818.69700000100.978600142.721400RD

09F1500412824.80900000101.967000112.053400RD

09F1500412834.72000000101.520800112.992800RD

09F1500412843.94700000102.08440067.2318000RD

09F1500412851.67800000103.435000351.147600RD

09F1500412861.76000000103.541200226.526200RD

09F1500412878.81200000100.714400187.285600RD

Link to comment
Share on other sites

In these cases, besides the importance of being able to define the routine placement of the comma separator, I have to be careful in treating these lines eventually treating them separately. I do not see another way to fix the problem.

And how the routine will know to skip such lines?!?

 

What really confuse me in this case is that the data exported by your equipment is intended to be used later in electronic format; other what's the purpose of having it as a file too? For this reason I think that there may be a setting of the said machine that you missed. Did you checked his manual carefully?

Link to comment
Share on other sites

And THAT exactly is what i'm drving at.

 

 

 

Take this for example.

OUTPUT

1003,6.22100000,96.1930000,267.875600, ND

 

Why not

100,36.221000009,6.193000026,7.875600, ND

 

The point is ,HOW can you tell where the value starts and end?

 

The structure of each line is this: See attached image:

cadtutor_coords.jpg

Link to comment
Share on other sites

And how the routine will know to skip such lines?!?

 

What really confuse me in this case is that the data exported by your equipment is intended to be used later in electronic format; other what's the purpose of having it as a file too? For this reason I think that there may be a setting of the said machine that you missed. Did you checked his manual carefully?

 

Mircea,

The truth is that we are now without reading the program data and have access to only the source files from a Compact Flash Card. Then I need to process them and then to import via autocad, also using a autolisp routine.

It was not this problem, the equipment allows to export files separated by commas.

While not having the software, I have to solve some work with this feature.

Link to comment
Share on other sites

If you are absolutely sure that the data lies on constant width columns, then try to adjust the example that I gave you. But, please, don't forget to double check each and every result after processed.

 

Mircea,

Yes, the sample result.

Unfortunately I do not have sufficient knowledge to integrate this code in a routine to do line by line from the reading of a file. Hence my request for help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...