Place references in the center of footprints

In my libraries I place the footprint references in the positions I wish.
Now I’m working on a large schematic made by a colleague and all the references are randomly placed around the footprints.

Is there a simple way to automatically place all the references in the center of the related footprint? Then it would be easier to manually correct the ones that don’t fit there. I’m talking in the PCB Editor, not in the Footprint Editor.

I think not, but it wouldn’t be too difficult to write a small python script to do that. It would need only a small loop for all board footprints which changes the reference coordinates to the footprint anchor coordinates.

Well, I haven’t explored the Python scripting yet but actually I wrote a couple of lines that did the trick:

import pcbnew

board = pcbnew.GetBoard();
for fp in board.Footprints():
  p = fp.GetPosition()
  fp.Reference().SetPosition(p)

board.Save("test.kicad_pcb")

I had to write these lines in the scripting console. Now I’m going to find out how to update the file without saving it with another name, and how to call this script from my own directory (I don’t want to wrtite a plugin right now).

1 Like

You can see the location of the KiCad’s python console startup script when you open the console. You can add a function there and call it later. To apply the changes call pcbnew.Refresh().

1 Like

Changing reference of footprint (I never tried to do it in PCB) probably shifts the 3D models.

Why would it? Reference is just text.

My mistake. I understood that it was footprint References and not element References.

1 Like

I don’t understand how you understood it, because Reference is the reference designator, a text item which is always in the footprint properties and in the official libraries is in the Silk layer. It is the footprint Reference, and I don’t know what you mean by “element”.

For me footprint reference is what you set (in footprint editor) with the button “Place footprint reference anchor”. I don’t have V6 yet as I work at Win7 PC so may be the wording was changed.
Till that moment I didn’t know what the ‘anchor’ word means but I didn’t needed it to understand what I am doing (a minute ago I just found what anchor means). So using that button I always thought that I am setting the footprint reference.
And in my library I have changed some THT footprint references from their pin 1 to their center. For example I am using 5 pin 2mm pin headers to connect between PCBs. PCBs are round so my reference is not the PCB egde but its axis and the mid pin of pin header have to be at axis. This is project I done in Protel when I used mils and not mm. So when designing PCB that have to fit to the other one I have to work in mils so it is much simpler to have reference at pin 3 because you will not do any mistake counting 0 mils to mm to position that connector.
The other situation - I am using 3 pin 2mm SMD pin header at one PCB and THT pin socket at the other. SMD has reference in its center, and THT at its pin 1. Even for simplicity we assume we work only in mm the task to find right places for them at both PCBs is not simple as that footprints are rotated 35°. So I decided to change 3 pin socket reference point to its center (like that SMD element has) and everything becomes simple.
I think that in footprint libraries keeping THT references at pin 1 has only a historical justification. And when we came to mixing THT and SMD we got in some trouble with the best solution by setting the THT footprint references to their centers.
So when I read in first post:

I understood that it is about something like what I am doing in my libraries.

I don’t know the internal PCB file structure so the script text tells me nothing about what is really changed.

My changing of footprint reference positions need the 3D model to be shifted.

For me R1,R2,R3,… are element (resistors, capacitors, transistors,…) references and not footprint references.

I hope now you understand what path my thoughts took.

I think the confusion is between footprint “Reference Designator” and footprint “Origin”

Yes, it was confusing. The word “reference” isn’t used in the footprint editor for the anchor.

I don’t like the word anchor, created an issue before: FPE: command "Place the Footprint Anchor" wording and location GUI menu (#9162) · Issues · KiCad / KiCad Source Code / kicad · GitLab :grin:

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