juulsA / exportJson

Skill script for Allegro PCB designer, which generates a JSON representation of the board.
MIT License
17 stars 8 forks source link

Can't parse json with cutouts #9

Closed karlsonrwa closed 11 months ago

karlsonrwa commented 11 months ago

Hello @juulsA ! Thanks for a great script!

I try to use it with my boards, I work with 22.1HF005. There is a bug I think. If there are any graphics at the Board geometry/Cutout subclass the json file can not be parsed by the python script. Says something like this:

d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom>python generate_interactive_bom.py AD-FMComms3_revA.json

Loading AD-FMComms3_revA.json
2023-10-27 19:57:01,267 INFO Successfully parsed d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\AD-FMComms3_revA.json
Traceback (most recent call last):
  File "d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\generate_interactive_bom.py", line 84, in <module>
    main()
  File "d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\generate_interactive_bom.py", line 77, in main
    ibom.main(parser, config, logger)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\core\ibom.py", line 327, in main
    pcbdata, components = parser.parse()
                          ^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\genericjson.py", line 149, in parse
    self.add_drawing_bounding_box(drawing, board_outline_bbox)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 136, in add_drawing_bounding_box
    {
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 134, in add_arc
    bbox.add_svgpath(svgpath, width, self.logger)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 237, in add_svgpath
    for segment in parse_path(svgpath, logger):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\svgpath.py", line 507, in parse_path
    Arc(current_pos, radius, rotation, arc, sweep, end))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\svgpath.py", line 131, in __init__
    assert start != end
           ^^^^^^^^^^^^
AssertionError

Is it possible to fix it? I saw another issue where you recommend to comment a line with Cutout subclass. Is it a recommended workaround?

juulsA commented 11 months ago

Hi, I'm glad you like it! I'm still working with 17.4 (but upgrading to 23.1 soon), in my case the cutouts were always parsed correctly ... so maybe the script is not working with 22.1 or - as you mentioned - there is a bug.

Do you use the latest version of the interactiveHtmlBom? Could you share the .brd file (exported for 17.4), this would be much easier for me to debug it?

Is it possible to fix it? I saw another issue where you recommend to comment a line with Cutout subclass. Is it a recommended workaround?

Normally the script should work without any workarounds ... and yes, I think we should be able to fix it.

karlsonrwa commented 11 months ago

Hi, I'm glad you like it! I'm still working with 17.4 (but upgrading to 23.1 soon), in my case the cutouts were always parsed correctly ... so maybe the script is not working with 22.1 or - as you mentioned - there is a bug.

I tried 17.4HF036 - the same issue with cutouts.

Do you use the latest version of the interactiveHtmlBom? Could you share the .brd file (exported for 17.4), this would be much easier for me to debug it?

Yes, I use the latest version, I've checked. In my case your demo board does not work as expected. You simply use "Shape add circle", select board geometry\cutout set it to unfilled and draw anywhere inside a design space, even outside a design outline.

My current python is: Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32

Packages I have:

C:\Users\Karlson>python -m pip list
Package            Version
------------------ ------------------------
attrdict3          2.0.2
attrs              23.1.0
certifi            2023.5.7
charset-normalizer 3.1.0
idna               3.4
jsonschema         4.17.3
numpy              1.25.0rc1
Pillow             9.5.0
pip                23.1.2
pyrsistent         0.19.3
requests           2.31.0
setuptools         65.5.0
six                1.16.0
urllib3            2.0.3
wheel              0.40.0
wxPython           4.2.1a1.dev5584+54b5aa71
karlsonrwa commented 11 months ago

Hm, updated to

C:\Users\Karlson> pip list
Package                   Version
------------------------- ---------
attrdict3                 2.0.2
attrs                     23.1.0
certifi                   2023.7.22
charset-normalizer        3.3.1
idna                      3.4
jsonschema                4.19.1
jsonschema-specifications 2023.7.1
numpy                     1.26.1
Pillow                    10.1.0
pip                       23.3.1
pyrsistent                0.20.0
referencing               0.30.2
requests                  2.31.0
rpds-py                   0.10.6
setuptools                65.5.0
six                       1.16.0
urllib3                   2.0.7
wheel                     0.40.0
wxPython                  4.2.1

Issue is the same:

d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom>python generate_interactive_bom.py AD-FMComms3_revA.json
Loading AD-FMComms3_revA.json
2023-10-28 14:59:19,028 INFO Successfully parsed d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\AD-FMComms3_revA.json
Traceback (most recent call last):
  File "d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\generate_interactive_bom.py", line 84, in <module>
    main()
  File "d:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\generate_interactive_bom.py", line 77, in main
    ibom.main(parser, config, logger)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\core\ibom.py", line 327, in main
    pcbdata, components = parser.parse()
                          ^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\genericjson.py", line 149, in parse
    self.add_drawing_bounding_box(drawing, board_outline_bbox)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 136, in add_drawing_bounding_box
    {
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 134, in add_arc
    bbox.add_svgpath(svgpath, width, self.logger)
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\common.py", line 237, in add_svgpath
    for segment in parse_path(svgpath, logger):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\svgpath.py", line 507, in parse_path
    Arc(current_pos, radius, rotation, arc, sweep, end))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Projects\OrCAD\Scripts\InteractiveHtmlBom\InteractiveHtmlBom\ecad\svgpath.py", line 131, in __init__
    assert start != end
           ^^^^^^^^^^^^
AssertionError

Here is my json: AD-FMComms3_revA.json

Updated to python 3.12.0, issue is the same.

juulsA commented 11 months ago

Ok, thanks for sharing the .json. As you assumed, this has to be a bug in the script, but please be patient, I can't look into this until the end of next week ...

juulsA commented 11 months ago

I don't know if it helps at the moment, but this problem only occurs when using a full arc ... when I draw a rectangle it seems to work ...

juulsA commented 11 months ago

I reported this issue here, because I'm not sure if it is really a problem with the script or the parser ...

karlsonrwa commented 11 months ago

Thank you very much for your time @juulsA ! I saw answer at the iBOM repository. I see what's wrong right now and I can live with that. Of course, if you fix this bug in future it would be very nice!

juulsA commented 11 months ago

No problem! It's on my list, I think next week I'll have a fix for this!

juulsA commented 11 months ago

Please check again with my last commit, it should be working now ...

karlsonrwa commented 11 months ago

Yes, circle cutouts are exported fine! Thank you very much for you work! It helps a lot!