Page
The PageOperations module handles page settings, title block, and grid configuration.
sch = kicad.get_schematic()
page = sch.page
Page Settings
get_page_settings()
Gets the current page settings.
settings = sch.page.get_page_settings()
print(f"Size: {settings.width_mm} x {settings.height_mm} mm")
print(f"Portrait: {settings.portrait}")
print(f"Paper: {settings.paper_size}")
set_page_settings(**kwargs)
Sets page settings.
# Use standard paper size
sch.page.set_page_settings(paper_size="A4")
# Custom size
sch.page.set_page_settings(
width_mm=297,
height_mm=210,
portrait=False
)
Paper sizes: "A0", "A1", "A2", "A3", "A4", "A5", "Letter", "Legal", "Ledger", "User"
Title Block
get_title_block()
Gets the title block information.
title = sch.page.get_title_block()
print(f"Title: {title.title}")
print(f"Date: {title.date}")
print(f"Revision: {title.revision}")
print(f"Company: {title.company}")
set_title_block(**kwargs)
Sets title block fields.
sch.page.set_title_block(
title="Power Supply Unit",
revision="1.0",
date="2024-01-15",
company="Acme Electronics",
comment1="Designed by: John Doe",
comment2="Approved by: Jane Smith",
comment3="",
comment4=""
)
Grid Settings
get_grid()
Gets the current grid settings.
grid = sch.page.get_grid()
print(f"Grid size: {grid.size_mm} mm")
set_grid(size_mm)
Sets the grid size.
sch.page.set_grid(size_mm=2.54) # 100 mil grid
sch.page.set_grid(size_mm=1.27) # 50 mil grid
Formatting Settings
get_formatting_settings()
Gets schematic formatting settings.
formatting = sch.page.get_formatting_settings()
print(f"Default text size: {formatting.default_text_size_mils} mils")
print(f"Label offset: {formatting.label_offset_ratio}")
set_formatting_settings(**kwargs)
Sets formatting settings.
sch.page.set_formatting_settings(
default_text_size_mils=50,
default_line_width_mils=6,
pin_symbol_size_mils=25,
junction_size_mils=40
)
Sheet Properties
get_sheet_name()
Gets the current sheet name.
name = sch.page.get_sheet_name()
get_sheet_number()
Gets the current sheet number.
sheet_num = sch.page.get_sheet_number()
total_sheets = sch.page.get_total_sheets()
print(f"Sheet {sheet_num} of {total_sheets}")
Example: Configure a New Schematic
from kipy import KiCad
kicad = KiCad()
sch = kicad.get_schematic()
# Set page size
sch.page.set_page_settings(paper_size="A3")
# Set title block
sch.page.set_title_block(
title="Main Controller Board",
revision="A",
date="2024-01-15",
company="My Company Inc.",
comment1="Project: Smart Home Controller"
)
# Configure grid
sch.page.set_grid(size_mm=2.54)
# Configure formatting
sch.page.set_formatting_settings(
default_text_size_mils=50,
default_line_width_mils=6
)
print("Schematic configured successfully")
Example: Update Revision
# Get current title block
title = sch.page.get_title_block()
# Parse revision and increment
current_rev = title.revision
if current_rev.isdigit():
new_rev = str(int(current_rev) + 1)
else:
# Handle letter revisions (A -> B)
new_rev = chr(ord(current_rev) + 1)
# Update title block
import datetime
sch.page.set_title_block(
revision=new_rev,
date=datetime.date.today().isoformat()
)
print(f"Updated revision: {current_rev} -> {new_rev}")