[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
gcode file editing.
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 13
Thread images: 1
File: IMG_20160310_194751.jpg (3 MB, 3120x4160) Image search: [Google]
IMG_20160310_194751.jpg
3 MB, 3120x4160
I have a file text with 20k lines. Each line has an x, y, and z variable.

> X:40.23 Y:10.30 Z:15.13

I need to replace every line with an increase of 40 in the X and Y place. The above line would look like this:

>X:80.23 Y:30.10 Z:15.13

How?

pic related.
>>
>>54386024
Learn to program.
>>
>>54386137
This. I could write a 10 line python script that does this, probably even less.
>>
>>54386024
quick and dirty?

import into excel as custom CSV
map formula onto those two columns, overwrite, export.
>>
>>54386024
Waiting for that sh guru who will solve this in one line.
>>
>>54386024
if this is for cnc machining, you could just set the ucs at the new origin, or work with another zero offset.
>>
>>54386024
sed
>>
>>54386024
Leave the file alone and set an offset
>>
Just change your offsets faggot
Also, what program gets anywhere near 20k lines?
>>
>>54386024
>square caps
why ?
>>
I'm also wondering how this situation arises in the first place, not only do you have 20k lines of code, which I'm having trouble believing because even the most complicated shit reaches 2k lines max if you're any good, and you have some reason to move everything on the x plane +40 units
You better be in base thou or tenthou if you managed to fuck up that bad

Change your tooling offsets, no need to edit the code
>>
ruby:
arr = "X:40.23 Y:10.30 Z:15.13".scan(/\d+[.]\d+/).map!{|element| element.to_f + 40}
puts "X:#{arr[0]} Y:#{arr[1]} Z:#{arr[2]}"

this puts on the screen:
X:80.22999999999999 Y:50.3 Z:55.13

just parse each line
>>
>>54386024
disregarding you said +40 in X and Y and only added 20 for Y, python

def clean(data):
x, y, z = (float(item.split(" ")[0]) for item in data.split(":")[1:])
return "X:{:.2f} Y:{:.2f} Z:{:.2f}".format(x + 40, y + 40, z)

with open("text.txt") as file:
text = file.read()

with open("new-text.txt") as file:
file.write('\n'.join(clean(line) for line in text.split('\n')))
Thread replies: 13
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.