3D model file in BOM export (KiCad 6)

Is there a away to add the selected 3D model file used by the footprint in python scripts that generates the BOM ? Right know, the footprint and symbol can be included but it does not look there is a way to get the 3D model (filename) as well ? (Eschema > Tools > Generate BOM)
Looked through the API documentation have not found something yet.

It is possible. Easier to do if you generate bom from pcb side where footprints are already loaded. Footprint class has Models() method that returns a list of FP_3DMODELS which have a filename.

1 Like

Excellent. Thanks a lot, Going to look at that.

@qu1ck
it would be nice to have a list of 3d model names also in your InteractiveHtmlBom plugin

I have a hard time imagining a use case for this.

You can write a 5 line script that will copy model to a custom field and use it in interactive bom.

1 Like

in 3D viewer to i.e. anchor fp the user can attach screws, enclosure etc…
then this option would be useful to have a BOM of mechanical parts (typically on virtual fp)

would you please post an example?

It’s working in the pcbnew script console, but wish to get this from eschema. Ofcourse the footprints in
eSchema need to match those in from Pcbnew.

P.S: The use case here is from a consistency point of view. Partnumbers can be prefedefined to use a certain model file. A check can be done to assure the models used is the approved model for a certain partnumber. The 3D step model of the board should then better guarantee to match the physical dimension for further inclusion in other CAD packages. when running it from eSchema it also can guarantee that the footprint data for the symbols was imported from the layout.

Here’s a full plugin

import pcbnew

class Model2Field(pcbnew.ActionPlugin):
    def defaults(self):
        super().defaults()
        self.name = "Models 2 field"
        self.description = "Save 3d models to custom field"

    def Run(self):
        board: pcbnew.BOARD = pcbnew.GetBoard()

        f: pcbnew.FOOTPRINT

        for f in board.Footprints():
            props: dict = f.GetProperties()
            model: pcbnew.FP_3DMODEL

            for model in f.Models(): # type: pcbnew.FP_3DMODEL
                if model.m_Show:
                    props["3dmodel"] = model.m_Filename
                    break

            f.SetProperties(props)

Model2Field().register()

After running it run ibom and you will get
image

Tweak the code if you want path var expansion or extract just the file name from full path.

2 Likes

To do this from eeschema (i’m assuming you are using the bom generator tool that passes xml to a script) you’ll have to get the footprint and library id’s, load the footprint and get models from there.

Yes, using the BOM generator from eschema → Tools → Generate BOM → (running a customized script). Thanks a lot for the hints. Going to look into how to do it from eschema. The pcnew output might still useful to create a check and compare it with the eschema data. guess the other way is to combine eschema with pcnew output to get the desired result.

Just FYI pcb already has all the eeschema data, including custom fields. You can easily create a bom just from that, that’s how my plugin works.
It doesn’t have footprints explicitly marked as exclude from board but those are usually excluded from bom too.

Thanks. Just considering a situation where a person changes the footprint in Pcbnew from the one in eSchema and then does not port the footprint back to eschema ?

Make a checklist.
Before you create Gerbers to be sent to a PCB fab you should do a bunch of checks to make sure you have done what you can to give them good information. Running ERC, updating the PCB from the schematic and running DRC should be a part of such a checklist.

Is there a way to get all the 3d models added to a fp?
ATM the plugin gets only the first 3D model assigned to a fp and ignores the others.

remove ```
if model.m_Show:

@debug
this doesn’t solve the issue
I have i.e. two models assigned to a single footprint and I would like to get both in the 3D field

    (model "${KIPRJMOD}/model1.step"
      (offset (xyz 0 0 0))
      (scale (xyz 1 1 1))
      (rotate (xyz 0 0 0))
    )
    (model "${KIPRJMOD}/model2.step"
      (offset (xyz 0 0 0))
      (scale (xyz 1 1 1))
      (rotate (xyz 0 0 0))
    )
            models = []
            for model in f.Models():
                if model.m_Show:
                    models.append(model.m_Filename)
            props["3dmodel"] = ", ".join(models)
2 Likes

@ qu1ck Thanks for all. The only thing missing now is the symbol lib and filename. Can the symbol be found using the pcbnew object ? I am running the script not in a plugin but outside of kicad on the command line.

No, not in pcbnew api. You’ll have to get that from xml file.

1 Like

paulvdh Thanks, yes all done that. DRC, ERC all are warning/error/less, ported component data back to eschema , checklists in place. it “should” not go wrong. But we’ll you never know…

qu1ck Thanks as well. Guess I’ll script it to cross check the eschema BOM output with the pcnew BOM just as an addtional automatic final check to be safe.