[5.99] Moving Footprint with Python

Howdy. I am making PCBs with a similar layout/consistent spacing between some of the items. I am new to trying to interface with the scripting console and do not quite understand the best way to achieve my goal of having the parts matching a certain reference ID being placed into a specific pattern on the pcbnew window.

I managed to identify all the footprints with the relevant ID, and assign the footprint object reference to module. From there I try and use set position. That’s where I am having issues.

If I use
module.SetPosition = pcbnew.wxPoint(0,-180)
I’d expect that to change the position of the part once the window is refreshed with pcbnew.refresh

It is not, however. I am able to grab the position with module.GetPosition and view them accordingly. If I print(module.SetPosition) it shows the new coordinates I set.

How do I actually apply the position change itself, or am I using this wrong? Finding information for the new changes is pretty difficult right now.

Thanks in advance!

Coordinates in pcbnew api are in nm (nanometers). 0, -180 will be pretty hard to tell apart from 0,0.
You can directly multiply as needed or use pcbnew.FromMM(), pcbnew.wxPointMM() helpers.

It isn’t near 0,0 either is the part that I am confused about. The footprint in question is at like 400,400 or something out of the way.

Works fine for me

If you share your code I may be able to help more

FindModuleByReference doesn’t exist in 5.99, I thought. I thought there was a swap to FindFootprintByReference and then a rework from there. None of the older syntax (like you just showed) has been working for me.

Works exactly the same in 5.99 (you should have specified that in the first post btw. edit:scratch that, my bad, it’s in the title)

Just change “module” for “footprint”

I put it in the title, but wouldn’t have hurt to have it in the post too I suppose. I’ll check this again in about an hour when I am able to check my design computer again, but I’m nearly positive it wasn’t working with that identical syntax last night. I appreciate the help though.

I remember there were some fixes related to pcbnew.refresh recently, you may want to update your nightly too.

3 Likes

pcbnew.refresh() works for me, I can set the position and it’s reflected in the view after refreshing. (5.99.0-10547-g25b766e8d7)

I updated and checked my syntax over from the start and got it working now. Thank you for your help and providing a much needed sanity check.

2 Likes

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