Newbie scripting problem, can't get rotate to accept parameters

Hi All,

I have a board with around 10,000 LEDs on it and I need each one rotating through 90 degrees. I started by doing them by hand (around 800 of them), but found the scripting interface and thought I could use that. No matter what I do I can’t get the syntax of the angle parameter to the footprint.rotate function right. Here’s what I have:

import sys
import pcbnew

b = pcbnew.GetBoard()

for m in b.GetFootprints():
s = m.GetReference()
if (s[0] == ‘D’) :
if s >= “D818” :
m.Rotate(pcbnew.VECTOR2I(0, 0), pcbnew.EDA_ANGLE.m_Angle90))

I have tried VECTOR2D in place of m_Angle90, but that complains about not knowing what a VECTOR2D is!!!

Any help much appreciated.

Thanks,

Paul

  1. What’s your kicad version? Pcbnew python interface changes significantly each version.
  2. What is the error you are getting? It should tell you what the expected parameter types are and what are you passing.

But either way I suspect you actually want SetOrientation() instead of Rotate()
https://docs.kicad.org/doxygen-python-7.0/classpcbnew_1_1FOOTPRINT.html#ab1238ed25704a0ef930f45f749c5d8a8

Apologies, I really should have added that info in the first place:

  1. Version 7
  2. TypeError: in method ‘BOARD_ITEM_Rotate’, argument 3 of type ‘EDA_ANGLE const &’

There are a number of different ways of specifying the angle, but I can’t get any of them to run.

I’ll check out the SetOrientation

Perfect, and I learned a bit of Python in the process :grinning:

Resulting code was:

for m in b.GetFootprints():
	ref = m.GetReference()
	if (ref[0] == 'D') :
		if (int(ref[1:]) > 818) :
			print ("* Module: %s"%ref)
			m.SetOrientationDegrees(0)

Turns out they were already at 90 degrees, so needed to set them to 0

Thanks for your help

Paul

(edit by qu1ck: code formatting to preserve whitespace, critically important in python)

1 Like

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