# debug.py import pcbnew import sys ''' Okay, this is for historical record, for others. I nearly cried trying to figure out how to get anything to serialize from a selection or even an item by ref i had (thought) i was directly pointing to... long story short, inheretance is not straightforward as it seems it ought to be. the only thing you can trust is the __dict__ of the selection or item in question, however, this is just part of the stuff it really has... I have not found a clear way to tell what is going to get inheretence as expected. But here is how to begin. I tried all of these bananas and finally found a way to actually get-> then do( stuff ) with a selection. Hope it saves somebody some trouble. ''' def debug_selection(): try: selection = pcbnew.GetCurrentSelection() except Exception as e: print(f"FAILED to call GetCurrentSelection(): {e}") return raw_count = 0 print("iterating->...") try: for item in selection: raw_count += 1 print(f"\n[{raw_count}] selected:") print(f"class: {item.GetClass()}") print(f"type: {type(item)}") print(f"mro: {type(item).mro()}") # Check for UUID methods uuid_val = "NOT FOUND" # 1. Try GetKIID() (Standard) if hasattr(item, 'GetKIID'): try: uuid_val = item.GetKIID().AsString() print(f" Method: GetKIID() -> {uuid_val}") except Exception as e: print(f" Method: GetKIID() -> Error: {e}") ## This is the only one that works, for future reference to others... ## vvvvvvvvv # 2. Try m_Uuid (Property) vvvvvvvv if hasattr(item, 'm_Uuid'): try: uuid_val = str(item.m_Uuid.AsString()) print(f" Property: m_Uuid -> {uuid_val}") except Exception as e: print(f" Property: m_Uuid -> Error: {e}") # ^^^^^^. ^yes this one^ ^^^^^^ ######################################################################### ^^^^^^^^ # 3. Try GetUuid() (Alternative) if hasattr(item, 'GetUuid'): try: uuid_val = item.GetUuid().AsString() print(f" Method: GetUuid() -> {uuid_val}") except Exception as e: print(f" Method: GetUuid() -> Error: {e}") # 4. Try Cast() (Force cast to EDA_ITEM) try: eda_item = pcbnew.Cast_to_EDA_ITEM(item) if hasattr(eda_item, 'GetKIID'): print(f" Cast(EDA_ITEM).GetKIID() -> {eda_item.GetKIID().AsString()}") except: pass except Exception as e: print(f"Error iterating selection: {e}") print("-" * 30) print(f"Raw Selection Count: {raw_count}")