Getting a list of all footprints used in a PCB?

I was just wondering - what is the recommended way of obtaining a list of all footprints used in a PCB, along with their properties/parameters?

So far, I just found that I could use grep from the command line - say, if the project is in /tmp/xx, I can do:

$ grep module /tmp/xx/xx.kicad_pcb
    (modules 18)
  (module Housings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mm (layer F.Cu) (tedit 54130A77) (tstamp 58E39F92)
  (module Pin_Headers:Pin_Header_Straight_2x02 placed (layer F.Cu) (tedit 58E3A479) (tstamp 58E1D9D8)
  (module Pin_Headers:Pin_Header_Straight_1x02 placed (layer F.Cu) (tedit 58E343F1) (tstamp 58E1D9EE)
  (module Resistors_SMD:R_0603_HandSoldering placed (layer F.Cu) (tedit 58E34419) (tstamp 58E1DA23)
  (module Resistors_SMD:R_0805_HandSoldering placed (layer F.Cu) (tedit 58E3444D) (tstamp 58E1DA29)
  (module Resistors_SMD:R_0603_HandSoldering placed (layer F.Cu) (tedit 58E3441D) (tstamp 58E1DA2F)
  (module Resistors_SMD:R_0805_HandSoldering placed (layer F.Cu) (tedit 58E343AD) (tstamp 58E1DA35)
  (module Resistors_SMD:R_0805_HandSoldering placed (layer F.Cu) (tedit 58E3442E) (tstamp 58E1DA41)
  (module Resistors_SMD:R_0603_HandSoldering placed (layer F.Cu) (tedit 58E3446A) (tstamp 58E1DA89)
  (module Resistors_SMD:R_0603_HandSoldering placed (layer F.Cu) (tedit 58E34465) (tstamp 58E1DA8F)
  (module Resistors_SMD:R_0603_HandSoldering placed (layer F.Cu) (tedit 58E34425) (tstamp 58E1DAAD)
  (module Socket_Strips:Socket_Strip_Straight_2x20 (layer B.Cu) (tedit 0) (tstamp 58E39F58)
  (module TO_SOT_Packages_SMD:SOT-23 (layer F.Cu) (tedit 553634F8) (tstamp 58E39F83)
  (module TO_SOT_Packages_SMD:SOT-23-6 (layer F.Cu) (tedit 53DE8DE3) (tstamp 58E39F89)
  (module project_footprints:NPTH_3mm_ID (layer F.Cu) (tedit 58E34364) (tstamp 58E3B082)
  (module project_footprints:NPTH_3mm_ID (layer F.Cu) (tedit 58E34364) (tstamp 58E3B086)
  (module project_footprints:NPTH_3mm_ID (layer F.Cu) (tedit 58E34364) (tstamp 58E3B08A)
  (module project_footprints:NPTH_3mm_ID (layer F.Cu) (tedit 58E34364) (tstamp 58E3B08E)

… and so far, I gather that:

  • No keyword means “Free” “Move and Place”
  • placed keyword means “Lock pads” “Move and Place”
  • locked keyword means “Lock footprint” “Move and Place”

Also:

  • layer F.Cu means copper layer, “Board side” “Front”
  • layer B.Cu means copper layer, “Board side” “Back”

Is this correct so far; and is there an alternative way to obtain a similar list?

1 Like

What do you plan to do with this list? (Maybe there is a finished tool that does what you want.)

2 Likes

I guess the official way is Pcbnew->File->Fabrication Outputs->Footprint Report.

2 Likes

Thanks for the responses!

I plan to use it to inspect which (if any) of the footprints are on the Back side, in case I cannot move a footprint with block selection move, as described in Cannot move previously locked footprint with block selection?

Many thanks for that - I didn’t even think of looking in Fabrication Outputs!

Just a note - this report looks like this:

$ cat /tmp/xx/myrep/xx.rpt | head --lines 20
## Footprint report - date Wed Dec 13 12:48:59 2017
## Created by Pcbnew version kicad (2017-11-13 revision d98fc85)-master
## Unit = mm, Angle = deg.

$BeginDESCRIPTION

$BOARD
upper_left_corner 20.270962 45.070000
lower_right_corner 229.835715 137.596401
$EndBOARD

$MODULE "U2"
reference "U2"
value "CAT24C32"
footprint "Housings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mm"
attribut smd
position 66.201200 74.316400  orientation 180.00
layer front
$PAD "1"
Shape Rect Layer front

… so actually, for my use case (quickly finding out if there are components on back of bard), grepping through the .kicad_pcb file seems a tad bit more convenient…

Thanks again!

1 Like

With KiCommand, something like this would work:

modules copy IsFlipped call filter select

That would select all modules that are flipped to the back of the board.

1 Like

Many thanks for this, @HiGreg :

I tried installing kicommand, and I did have some trouble doing so, but I think I managed to get it installed - see Cannot register external action plugins in Pcbnew?

Now, I tried entering your command, modules copy IsFlipped call filter select - but all I get is 2 operands left on the stack. :

Is there anything else I’d need to do to see modules listed in output?

1 Like

You may have to switch canvases to Legacy and back to OpenGL to see the selected modules. You can use F9 and F11 for that. You can also use the command stack to see what is in the stack or print to see the top of the stack.

1 Like

Thanks for the pointers @HiGreg - unfortunately I still cannot get it to work:

In my case, my KiCad opens by default in Legacy canvas, and that is how I tried the modules copy IsFlipped call filter select command earlier. I switched to OpenGL canvas, tried command again, again “2 operands left on the stack.” Switched back to Legacy canvas, tried command again, again “2 operands left on the stack.”

Am I supposed to see elements indicated on the canvas, or get a textual list in the kicommand window?

If I run stack command, there is absolutely no change, no new messages are output in the debug window, and no obvious indication on the canvas either.

If I run print, I get: Error 1 on line 219: list index out of range in a popup window…

If you have some other suggestions I can try, please let me know. Thanks!

1 Like

ok. “list index out of range” means there are no items on the stack, so the print and stack commands will not output anything. (perhaps I can print a better message). The message “2 operands left on the stack” is from a command being used by the commands you entered.

try the following command to list the modules that are flipped:

modules copy IsFlipped call filter print

This should list the modules, although in a hard-to-use format.

To list the references, try

modules copy IsFlipped call filter referencetext print

Does either command print anything?

1 Like

Thanks again, @HiGreg :

YES! Finally, modules copy IsFlipped call filter print does print this to the command window:

3 operands left on the stack. 
[<pcbnew.MODULE; proxy of <Swig Object of type 'MODULE *' at 0xa8b34cf8> >] 
2 operands left on the stack. 
4 operands left on the stack. 
[<pcbnew.MODULE; proxy of <Swig Object of type 'MODULE *' at 0xa8b34d28> >] 
3 operands left on the stack. 

Indeed, it is hard to read, but at least I get some indication. Also, the above output is from running modules copy IsFlipped call filter print twice, one after another - and I can notice the number of “operands left on the stack” keeps increasing.

Here I get this:

5 operands left on the stack. 
5 operands left on the stack. 
[u'REFPOT_I2', u'REFPOT_I1', u'REFPOT_M', u'REFPOT_O1', u'REFLED_I1', u'REFLED_MY', u'REFMO', u'REFTO2', u'REFNI2', u'REFR3', u'U2', u'J6', u'J9', u'R6', u'R7', u'R8', u'R9', u'R11', u'R23', u'R24', u'R29', u'J3', u'Q1', u'Q2', u'H1', u'H2', u'H3', u'H4', u'REFNI1', u'REFTO1', u'REFMI', u'REFBPT', u'REFLED_PB', u'REFLED_I2', u'REFPOT_O2', u'JP1'] 
5 operands left on the stack. 

So, the number of operands again tends to increase if I call the command a second time, except it directly increases by 2 (so running it after the above snippet, writes out “7 operands left on the stack.” three times); and I think the references shown here are from all of the parts I have in the schematic, not just the flipped one.

I’m pretty sure modules copy IsFlipped call filter print gets the right module (there should be only one module that is flipped) - if one could just get its reference to print, that would be great…

1 Like

Try this:

clear modules copy IsFlipped call filter referencetext stack

That should print out the references (and clear the stack prior to command execution. Not sure what is being left on the stack, the final stack command should print all items on the stack.

In the development version of KiCommand, I’ve fixed:

  • Better error when no items are on the stack during print, stack.
  • Still prints number of items on the stack (only when 1 or more) at end of all commandstrings.
  • removed “intermediate stack printing” when calling commandstring commands within another command
  • automatically create USERSAVEDIRECTORY ~/kicad/kicommand
1 Like

It looks like referencetext is printing all references. Sorry, referencetext is designed for printing all of them. The correct command is:

clear modules copy IsFlipped call filter GetReference call stack

That should print only the modules left on the top of the stack.

1 Like

Once you get it to work, you can define it as a command:

: getflipped "Elements Print references of all flipped modules" modules copy IsFlipped call filter GetReference call print ;

Then save as a user command:

getflipped.txt save

You should be able to load the command like this:

getflipped.txt load

This will be saved in ~/kicad/kicommand/getflipped.txt

Hmm. There doesn’t seem to be a way to save user commands that automatically load in future sessions. I should fix that. Perhaps saving to a file called “autoload” will automatically load them (in a future version of KiCommand).

1 Like

Awesome @HiGreg - finally it works

Yes, this one now prints both the module reference, and all reference texts, as you noted:

However, this:

… works as expected:

2 operands left on the stack. 
[u'J3'] 
1 operands left on the stack. 

… and indeed, I remember now it was J3 that was flipped - so, it finally works! :slight_smile:

Thanks for the tip - will try to experiment with that, too…

Thanks, much appreciated - just for the record, I’m still using the “old” one (6c5cbfc Updated and added several commands and tests), and I’m quite happy it works!

Thanks again - cheers!

2 Likes

Super! Let me know if you find any thing else or have suggestions for improvement!

@HiGreg emails me, so I will have a chance to see a post you need help with.

Thanks again, and super glad it works for you.

2 Likes