Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Vector Optimizer
artecuser
Newbie
Posts: 9
Permalink
Post Vector Optimizer
on: June 13, 2020, 21:34
Quote

Dear polargraphers,
I would like to run vector optimizer with the file "test.txt", but I can´t get it to work (file is attached here).
In Windows PowerShell (Win 10) appears:

PS C:\Users\Windows\Desktop\Polargraph\polargraph-optimizer-master\polargraph-optimizer-master> python process.py test_1.txt > test_2.txt
Problem with instructions in glyph:
C02,4.05,END (other)
C31,1722.0,END (other)
C32,1242.0,END (other)
C14,END (penup)
Total Glyphs: 67090
Traceback (most recent call last):
File "process.py", line 26, in <module>
print("Initial penup distance: %9d" % total_penup_travel(glyphs), file=sys.stderr)
File "C:\Users\Windows\Desktop\Polargraph\polargraph-optimizer-master\polargraph-optimizer-master\lib.py", line 136, in total_penup_travel
return sum(distance_between_each_pair(gs))
File "C:\Users\Windows\Desktop\Polargraph\polargraph-optimizer-master\polargraph-optimizer-master\lib.py", line 133, in distance_between_each_pair
yield prev.distance_to(g)
File "C:\Users\Windows\Desktop\Polargraph\polargraph-optimizer-master\polargraph-optimizer-master\lib.py", line 58, in distance_to
return max(abs(other.start[0] - self.end[0]), abs(other.start[1] - self.end[1]))
TypeError: 'NoneType' object has no attribute '__getitem__'

Please, could you see what´s the problem?
---
Win 10, 64bit
Python 2.7.10
test_1.txt is made with polargraphcontroller (export queue)

Best regards,
ArtecUser

sandy
Administrator
Posts: 1443
Permalink
sandy
Post Re: Vector Optimizer
on: June 13, 2020, 21:42
Quote

Hiya, perhaps there's a typo here, but if you're trying to optimise the content of test.txt then the command should be

python process.py test.txt > test_2.txt

I _think_ the output is saying that it can't find test_1.txt - which is fair if the file is actually called test.txt 🙂

sn

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 13, 2020, 21:52
Quote

ah. When I tried, the file was named correct. - Typo is not possible.

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 13, 2020, 21:56
Quote

When I try it with "map.txt", is seems to work, but it results in a bigger file. And when I import this optimized file as queue in polargraphcontroller, there appears no drawing.

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 13, 2020, 22:00
Quote

Here you can download the files:
test_1.txt
map2.txt (optimized)
https://we.tl/t-5IsSbIIa8T

sandy
Administrator
Posts: 1443
Permalink
sandy
Post Re: Vector Optimizer
on: June 14, 2020, 00:54
Quote

This is really interesting, it's a character encoding issue in the result file.

The polargraphcontroller outputs and reads text files with UTF-8 character encoding, but the optimiser script has outputted text files with UCS-2 LE BOM character encoding. I admit I hadn't ever seen any examples of this encoding before.

To find this out, I loaded map2.txt into polargraphcontroller and saw the queue looked like this - with all the little empty boxes being where the polargraphcontroller has interpretted multi-byte character values as multiple separate characters!

Image

To fix this, I simply changed the encoding to be UTF-8 and it loaded ok. I loaded the file into notepad++ and then clicked Encoding-> convert to UTF-8. It also brings the file size down to 1.4MB.

I imagine there is a setting somewhere in your OS or your installation of python that sets the default text file format to be UCS-2 LE BOM, and that's why it's happening without you asking for it.

However, there's something else obviously odd that's going on here if these two txt files are of the same artwork (I can't really tell because my machine is a different size so the actual preview is distorted). The artwork in the first file (test_1.txt) is full of line instructions targetting the 1000-1800 space. That means the instructions are usually telling the polargraph cables to be between 1000 and 1800 steps in length. That might be up at the top of the machine.

The second file (map2.txt) has completely different numbers in it - all from the 2000 to 7000 space! This indicates a slightly deeper problem than just character encoding.

Is there any chance these files are of different pieces of artwork?

sn

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 14, 2020, 10:31
Quote

Yes, these files are of different pieces of artwork. Sorry, I did not mention this:

map2.txt = optimized map.txt file from you. Encoding to UTF-8 also works for me with this file.

But I still have problems optimize my own file: test_1.txt = artwork from me. Trying to optimize it, an error message appears (See my first posting).

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 14, 2020, 14:31
Quote

Now it works partially with my own files. I have to delete these lines at the beginning (see my first posting):
C02,4.05,END (other)
C31,1722.0,END (other)
C32,1242.0,END (other)
C14,END (penup)

As I said: With little files (about 200 KB) it works. But with my desired file (5.220 KB) it lasts very loooong. Now I´m wating 30 Minutes. Will python do it? I will report here.

sandy
Administrator
Posts: 1443
Permalink
sandy
Post Re: Vector Optimizer
on: June 15, 2020, 00:00
Quote

Do you mean the optimisation process takes a long time? I can't remember if it gives any progress messages while it works.

I did notice that loading the long queue into the polargraphcontroller seemed to take two goes - Like I had to go import queue and find the file, but the queue wouldn't show up until I clicked "import queue" again. Then it appeared instantly.

sn

artecuser
Newbie
Posts: 9
Permalink
Post Re: Vector Optimizer
on: June 15, 2020, 22:48
Quote

Yes, I mean the optimisation process takes a long time with a big file. After 1,5 hours I stopped the process (File size was 5 MB).

Therefore I minified my svg file with svgminify.com and deleted some lines in the drawing. So my queue file shrinked to 2 MB. After 40 Minutes the process was done!

I´m happy - it works now. 😀

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.017 seconds.