From 33a4c9b08e040a17daefae9069fdf834063555b4 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Sun, 2 Jan 2022 20:21:07 -0800 Subject: [PATCH] FOOTPRINT::GetProperty() swig extension --- pcbnew/python/swig/footprint.i | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pcbnew/python/swig/footprint.i b/pcbnew/python/swig/footprint.i index 8b970f84f3..80ee85f123 100644 --- a/pcbnew/python/swig/footprint.i +++ b/pcbnew/python/swig/footprint.i @@ -31,6 +31,7 @@ %template(MAP_STRING_STRING) std::map; %rename(GetPropertiesNative) FOOTPRINT::GetProperties; +%rename(GetPropertyNative) FOOTPRINT::GetProperty; %rename(SetPropertiesNative) FOOTPRINT::SetProperties; %rename(MODULE_3D_SETTINGS_VECTOR3D) MODULE_3D_SETTINGS::VECTOR3D; %feature("flatnested"); @@ -66,6 +67,13 @@ properties = self.GetPropertiesNative() return {str(k): str(v) for k, v in properties.items()} + def GetProperty(self, key): + """ Returns property with a given key if it exists, throws KeyError otherwise. """ + if self.HasProperty(key): + return self.GetPropertyNative(key) + else: + raise KeyError("Property not found: " + key) + def SetProperties(self, properties): """ Sets footprint properties map. """ wxproperties = MAP_STRING_STRING()