Is there a way to get 3d models via pcbnew API?

I want to get a list of 3d models for each board object and then if necessary change the model reference.

It appears the Models() function returns a C++ object which I have no idea how to handle in Python. Is there a way to get a list of the model filenames, and update it?

def pcbfunc(Filename = None):
    if Filename: 
        my_board = pcbnew.LoadBoard (Filename)
    else:
        my_board = pcbnew.GetBoard()

    # for v5 use GetLibItemName() instead of GetFootprintName()
    for module in my_board.GetModules():
        models = module.Models()

        print ("%s \"%s\"  " % ( module.GetReference(), 
                                    module.GetValue() ))
                                    #module.GetModels() ) )

        print models

Console output:

execfile ("C:/github/kicad3Dmodels/scripts/gen_model/gen_model/gen_model.py")
REF** "WC1602A"  
<Swig Object of type 'DLIST< S3D_MASTER > *' at 0x0000000021b2c990>
R1 "1000"  
<Swig Object of type 'DLIST< S3D_MASTER > *' at 0x00000000219d2240>
R2 "220"  
<Swig Object of type 'DLIST< S3D_MASTER > *' at 0x0000000021b2cb70>
R3 "330"  
<Swig Object of type 'DLIST< S3D_MASTER > *' at 0x0000000021b2cb40>
R4 "4700"  
<Swig Object of type 'DLIST< S3D_MASTER > *' at 0x00000000219d2240>

Hi bobc,

I don’t know about python, but in C++ you can check this lines:

Its gets the modules from
m_settings.GetBoard()->m_Modules
Then it checks if

!module->Models().empty()

then:

    // Get the list of model files for this model
    auto sM = module->Models().begin();
    auto eM = module->Models().end();

The filename is at

sM->m_Filename

Another example:

What is stranger is that the Models() are now a list of MODULE_3D_SETTINGS (if I am correct) and the S3D_MASTER is by a long time ago removed from the source code.

Forgot to mention I was looking at 4.0.x API, I will have another look at v5 API !

For now I will probably process the file directly, later try to make it API compatible.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.