Adding Objects to the Database
Objects in PlexosDB represent entities in your PLEXOS model like generators, regions, and nodes.
Basic Object Creation
Section titled “Basic Object Creation”from plexosdb import PlexosDBfrom plexosdb.enums import ClassEnum
# Initialize databasedb = PlexosDB()db.create_schema(version=10)
# Add a generator objectdb.add_object( ClassEnum.Generator, name="Generator1", description="Example generator", category="Thermal")
# Add a node objectdb.add_object( ClassEnum.Node, name="Node1")
# Add a region objectdb.add_object( ClassEnum.Region, name="Region1")Adding Objects with Custom Categories
Section titled “Adding Objects with Custom Categories”You can organize your objects by adding them to specific categories:
# Add generator with custom categorydb.add_object( ClassEnum.Generator, name="Wind_Farm1", category="Renewable", description="Offshore wind farm")Checking if Objects Exist
Section titled “Checking if Objects Exist”Before adding objects, you can check if they already exist:
if not db.check_object_exists(ClassEnum.Generator, "Generator1"): db.add_object(ClassEnum.Generator, "Generator1")else: print("Generator already exists")Listing Objects by Class
Section titled “Listing Objects by Class”You can list all objects of a specific class:
# List all generatorsgenerators = db.list_objects_by_class(ClassEnum.Generator)print(f"Found {len(generators)} generators: {generators}")
# List all generators in a specific categorythermal_generators = db.list_objects_by_class(ClassEnum.Generator, category="Thermal")print(f"Found {len(thermal_generators)} thermal generators")Working with Multiple Objects
Section titled “Working with Multiple Objects”For bulk operations, you can create multiple objects efficiently:
# Create multiple generatorsfor i in range(1, 101): db.add_object( ClassEnum.Generator, name=f"Generator{i}", category="Thermal" if i % 2 == 0 else "Renewable" )