kicad-jlcpcb-tools icon indicating copy to clipboard operation
kicad-jlcpcb-tools copied to clipboard

"Do not place" attribute ignored when creating BOM file

Open ms270169 opened this issue 7 months ago • 2 comments

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

When creating the production files, I was wondering, that JLCPCB Bill of Material list includes components which are marked in KiCad with the attribute "Do not place" (in german version "Nicht bestücken").

That causes the need to manually exclude these parts. With the following change in fabrication.py method generate_bom() it is possible to solve this problem.

Original version:

def generate_bom(self):
        """Generate BOM file."""
        bomname = f"BOM-{Path(self.filename).stem}.csv"
        add_without_lcsc = self.parent.settings.get("gerber", {}).get(
            "lcsc_bom_cpl", True
        )
        with open(
            os.path.join(self.outputdir, bomname), "w", newline="", encoding="utf-8"
        ) as csvfile:
            writer = csv.writer(csvfile, delimiter=",")
            writer.writerow(["Comment", "Designator", "Footprint", "LCSC"])
            for part in self.parent.store.read_bom_parts():
                if not add_without_lcsc and not part[3]:
                    continue
                writer.writerow(part)
        self.logger.info("Finished generating BOM file %s", os.path.join(self.outputdir, bomname))

Improved version:

def generate_bom(self):
        """Generate BOM file."""
        bomname = f"BOM-{Path(self.filename).stem}.csv"
        add_without_lcsc = self.parent.settings.get("gerber", {}).get(
            "lcsc_bom_cpl", True
        )
        with open(
            os.path.join(self.outputdir, bomname), "w", newline="", encoding="utf-8"
        ) as csvfile:
            writer = csv.writer(csvfile, delimiter=",")
            writer.writerow(["Comment", "Designator", "Footprint", "LCSC"])
            for part in self.parent.store.read_bom_parts():
                components = part[1].split(",")
                for component in components:
                    for fp in self.board.Footprints():
                        if fp.GetReference() == component and fp.IsDNP():
                            components.remove(component)
                            part[1] = ','.join(components)
                            self.logger.info("Component %s has 'Do not placed' enabled: removing from BOM", component)
                if not add_without_lcsc and not part[3]:
                    continue
                writer.writerow(part)
        self.logger.info("Finished generating BOM file %s", os.path.join(self.outputdir, bomname))

The "Do not place" parts are now not in the BOM-file, but they remain in the CPL file. That causes the following warning message when the files are imported in JLCPCB web-page:

Error

The below parts won't be assembled due to data missing.
R23,R25,R28,R1,R6,R9,R31,C3,J6,R10 designators don't exist in the BOM file.

I think it is a good idea to let popup this warning, because it indicates that some parts are not ordered and placed, and you can see which parts are concerned. If everything is ok, you can close the message dialog and proceed the order flow...

ms270169 avatar Jul 01 '24 07:07 ms270169