yaqwsx / PcbDraw

Convert your KiCAD board into a nicely looking 2D drawing suitable for pinout diagrams
MIT License
1.13k stars 90 forks source link

"AttributeError: 'NoneType' object has no attribute 'attrib'" when using "res_band" in custom footprint #116

Open dhaillant opened 1 year ago

dhaillant commented 1 year ago

I'm creating a set of custom footprints for PcbDraw. And lately, I tried to add the res_band feature for the axial resistors, with no luck.

Once I add a rectangle named res_band1, pcbdraw crashes with this message:

Traceback (most recent call last): File "/home/david/.local/bin/pcbdraw", line 8, in sys.exit(run()) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/populate.py", line 300, in populate parsed_content = generate_images(parsed_content, board, prepare_params(header["params"]), File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/populate.py", line 193, in generate_images generate_image(boardfilename, x["side"], x["components"], File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/populate.py", line 212, in generate_image plot.main(args=plot_args) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/david/.local/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/ui.py", line 174, in plot image = plotter.plot() File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 1053, in plot plotter.render(self) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 812, in render plotter.walk_components(invert_side=False, callback=self._append_component) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 1084, in walk_components callback(lib, name, ref, value, pos) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 840, in _append_component ret = self._create_component(lib, name, ref, value) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 890, in _create_component self._apply_resistor_code(component_element, id_prefix, ref, value) File "/home/david/.local/lib/python3.8/site-packages/pcbdraw/plot.py", line 928, in _apply_resistor_code s = band.attrib["style"].split(";") AttributeError: 'NoneType' object has no attribute 'attrib'

The rectangle is copied/pasted from one of the resistors in pcbdraw-lib.

Inkscape is V1.2 (1:1.2.1+202207142221+cd75a1ee6d)

Is there any setting, configuration that must be applied to the svg for the res_band feature to be recognized?

Thanks!

dhaillant commented 1 year ago

BTW, this is with populate command.

Electro707 commented 1 year ago

Did you add the other res_bands (from 1 to 4)? This could be because it is crashing when it is trying to find the other bands after it finds the first one

dhaillant commented 1 year ago

Indeed, it looks like in my first attempt, somehow the script couldn't find one or more of the 3 next bands.

So I copy/pasted the 4 bands at once from a resistor in the official lib to my custom lib and now it works. As @Electro707 suggested, if I remove just one of the 3 bands (not the #1), it rises this error.

I think I understand what happened: In my first attempt, I copy/pasted only one band and renamed it. This was clearly not the right method.

Thanks!