pygerber icon indicating copy to clipboard operation
pygerber copied to clipboard

[PyGerber]: When I try to render with .gbr files, getting error pyparsing.exceptions.ParseException

Open Rajkisan opened this issue 1 year ago • 5 comments

PyGerber Bug Report

Mandatory checks

Checks listed below are mandatory for opening a new issue.

If haven't done any of the checks listed below, please do that, we will not look into the issue until all of the checks in mandatory checks section are checked.

Before opening this issue:

  • [x] I have reviewed the README for guidelines and haven't found a solution there.
  • [x] I have reviewed the PyGerber documentation and haven't found a solution there.
  • [x] I have reviewed the existing open issues and verified that this is not a duplicate.
  • [x] I have reviewed the existing closed issues and verified that this was already resolved or marked as won't fix.
  • [x] I have reviewed the existing pull requests and verified that this is not a already known issue.
  • [x] I have reviewed the existing discussions and verified that this is not a already known issue.

This is my code

from pygerber.examples import ExamplesEnum, get_example_path
from pygerber.gerberx3.api.v2 import ColorScheme, GerberFile, PixelFormatEnum

GerberFile.from_file(
    "GerberKicad/dse_vmj_ex_004_legend_top.gbr",
).parse().render_raster(
    "output.png",
    dpmm=100,
    color_scheme=ColorScheme.COPPER_ALPHA,
    pixel_format=PixelFormatEnum.RGBA,
)

It shows

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/rajki/Downloads/Glonix/vm.py", line 6, in <module>
    ).parse().render_raster(
      ^^^^^^^
  File "/Users/rajki/Downloads/Glonix/.venv/lib/python3.12/site-packages/pygerber/gerberx3/api/_v2.py", line 197, in parse
    tokens = Tokenizer().tokenize(self.source_code)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rajki/Downloads/Glonix/.venv/lib/python3.12/site-packages/pygerber/gerberx3/tokenizer/tokenizer.py", line 49, in tokenize
    return self._tokenize_grammar(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rajki/Downloads/Glonix/.venv/lib/python3.12/site-packages/pygerber/gerberx3/tokenizer/tokenizer.py", line 84, in _tokenize_grammar
    ast = grammar.parse_string(source, parse_all=parse_all)[0]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rajki/Downloads/Glonix/.venv/lib/python3.12/site-packages/pyparsing/core.py", line 1216, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected End of file, found '%'  (at char 198), (line:4, col:1)

Expected behavior

It has to render the image of the layer

Environment:

Please complete the following information:

  • Operating system: [macOS24.04]
  • Python version: [3.12.0]
  • PyGerber version: [2.4.2]

Rajkisan avatar Jan 12 '25 18:01 Rajkisan

Contents of top.gbr file

top.zip

Rajkisan avatar Jan 12 '25 18:01 Rajkisan

I got same error message when I parse a GBS file. here is my code:

from pygerber.gerberx3.api.v2 import FileTypeEnum, GerberFile
parsed_file = GerberFile.from_file(
    "./80600_50_6-ISS1/80600_50_6-ISS1_bott_resist.GBS",
    file_type=FileTypeEnum.INFER_FROM_ATTRIBUTES
).parse()
print(parsed_file.get_info())
print(parsed_file.get_file_type())

here I attach my gerber zip file: 80600_50_6-ISS1.zip

please advise how to solve it. Thanks, Lily 80600_50_6-ISS1.zip

lily-PHP avatar Jan 14 '25 09:01 lily-PHP

@Rajkisan the problem in with your file is cause by incorrect zero coding mode. D is not an accepted value accoring to Gerber standard. Do you know how this zero coding mode should be interpreted?

%FSDAX44Y44*%

Argmaster avatar Jan 20 '25 03:01 Argmaster

What Can I do now?

Rajkisan avatar Jan 20 '25 03:01 Rajkisan

Change declared coordinate format. Try L or T instead of D in FS extended fommand and see if one of them yields reasonable results.

If you determine and share here how to interpret D coordinate coding I can add support for it in PyGerber to mitigate this issue in the future.

Argmaster avatar Jan 24 '25 10:01 Argmaster