Bouni / kicad-jlcpcb-tools

Plugin to generate BOM + CPL files for JLCPCB, assigning LCSC part numbers directly from the plugin, query the JLCPCB parts database, lookup datasheets and much more.
MIT License
1.08k stars 102 forks source link

Plugin fails on components without pads #488

Open ms270169 opened 1 week ago

ms270169 commented 1 week ago

I am working on Plugin Version 2024.06.04 and KiCad Version 8.0.3-rc1

I want to use component with multiple footprints, for example an Arduino Nano component consisting of two 15 pin Sockets, and get all production data automatically without manual post processing.

Because this use case is not supported by KiCad at the moment, I solve this demand in the following way:

1) Create a Arduino symbol with all 30 pins, but without LCSC field. 2) Bind that to a PCB footprint with all 30 pads on proper location. 3) Create an "empty" symbol with LCSC field for 15 pin header. 4) Creating PCB footprint for the "empty" symbol without Pads, but with F-Fab circles on proper pad location. 4) Adding the "empty" symbol two times in the schematic. 5) Locating the F-Fab circles exactly over the 30 pads of the Arduino footprint.

Inside KiCad everything works perfect. Bill of material and location data ar generated with proper values. No ERC and DRC error or warning is generated.

When starting the JLCPCB Tools plugin, everything works without warning or errors, but no BOM file is generated and the CPL file only has parts with identifiers before the "empty" symbol part.

As soon as I add one pad in the "empty" symbol footprint, the plugin works as desired, but then I get DRC errors because pad is now two times on same location. To move the pad outside of print is also not working, because the plugin is using the wrong pad location and not the correct footprint location.

I see no solution, as long as the plugin needs a footprint with pad for proper run.

ms270169 commented 1 week ago

This solution on file fabrication.py line 102 solves the problem.

Original version of method get_position():

def get_position(self, footprint):
        """Calculate position based on center of bounding box."""
        pads = footprint.Pads()
        bbox = pads[0].GetBoundingBox()
        for pad in pads:
            bbox.Merge(pad.GetBoundingBox())
        return bbox.GetCenter()

Problem fixed with:


 def get_position(self, footprint):
        """Calculate position based on center of bounding box."""
        try:
            pads = footprint.Pads()
            bbox = pads[0].GetBoundingBox()
            for pad in pads:
                bbox.Merge(pad.GetBoundingBox())
            #self.logger.info(" => %s", bbox.GetCenter())
            return bbox.GetCenter()
        except:
            self.logger.info("WARNING footprint %s: original position used", footprint.GetReference())
            return footprint.GetPosition()
``
Bouni commented 3 days ago

Can you provide a screenshot? I don't get what exactly you try to achieve. Also, a broad except is not a good thing to do, can you let me know what exception you get for your part so that we can handle this properly?

ms270169 commented 2 days ago

You get an "Index out of bound" Exception because in fabrication.py#L105 you access pads[0], but if there are no pads you get an exception. Because you never catch any exceptions in your plugin, the script is aborted without any error dialog to the user. I would also recommend to add an exception catch at the plugin start to ensure an error dialog if anything goes wrong.

The basic "routing" problem (multiple footprints for one component which is not supported by KiCad) is described at the beginning of this issue. I look for any solution in the KiCad community, get some hints but no good solution. The procedure I described above works fine, and it is not a big concern to add a try/catch on proper location in plugin.

klaus-liebler commented 12 hours ago

Same problem in my use case: I use pad-less footprints to place silkscreen drawings (polarity hint, warning symbols...) on my pcb. The project is here: https://github.com/klaus-liebler/labathome/tree/master/labathome_pcb15

Regards, Klaus