-
Notifications
You must be signed in to change notification settings - Fork 19
Python API (Cable Design API)
Getting the API
factory = CdbApiFactory(cdb_url)
cable_design_api = factory.getCableDesignItemApi()
Fetching all cables can be achieved by running cable_design_api.get_cable_design_item_list()
. An optional argument include_connections
or include_md_locations=True
can also be specified.
cables = cable_design_api.get_cable_design_item_list(include_connections=True, include_md_locations=True)
# Print connection list of last cable.
print(cables[-1].connection_list)
[{'item_connector_name': '1',
'md_connector_name': 'LB61_TO_A',
'md_item_id': 177276,
'md_item_name': 'S04-DIAG:RR00:PP1'},
{'item_connector_name': '2',
'md_connector_name': 'TO_A',
'md_item_id': 184709,
'md_item_name': 'S05A:P2:BPP'}]
Inteface and all arguments.
cable_design_api.add_or_update_cable_design(**kwargs)
-
id
(int): DB ID of the cable. When none specified, item will be created. -
qr_id
(int): Cable design qrId (-1 to clear) -
name
(str): Cable design name. -
alternate_name
(str): Cable design alternate name. -
description
(str): Description of the cable design. -
item_project_ids
(list[int]): Project IDs. -
technical_system_ids
(list[int]): Technical System IDs. -
cable_type_id
(int): Cable Type ID (-1 to clear). -
end1_machine_design_id
(int): Endpoint 1 machine design ID. (Must be specified to make any changes to endpoint 1) -
end1_device_port_name
(str): Endpoint 1 device port name. -
end1_connector_name
(str): Endpoint 1 connector name. -
end2_machine_design_id
(int): Endpoint 2 machine design ID. (Must be specified to make any changes to endpoint 2) -
end2_device_port_name
(str): Endpoint 2 device port name. -
end2_connector_name
(str): Endpoint 2 connector name.
To create a cable design no id
should be specified. All the required aruments must be provided such as name, technical system, project, and endpoints.
All commented out arguments are optional.
cable_design = cable_design_api.add_or_update_cable_design(
name="API TEST Cable",
# qr_id=1234
# description="A cable created from API for test",
item_project_ids=[3],
technical_system_ids=[44],
# Clear cable type with -1
# cable_type_id=-1,
# cable_type_id=305012,
end1_machine_design_id=177276,
# end1_device_port_name="LB61_TO_A",
# end1_connector_name="e1-1",
end2_machine_design_id=184709,
# end2_device_port_name="TO_A",
# end2_connector_name="e2-1"
)
To update a cable an ID must be provided. When updating only the provided variables will be used for update. With exception of endpoints, if new endpoint is provided new connector and port names must also be provided.
cable_design = cable_design_api.add_or_update_cable_design(
id=1234
name="API TEST Cable New Name")
Function used to add or update cable endpoints. Certain arguments are not needed based on which operation is performed.
-
cable_design_id
(int): DB ID of the cable. -
endpoint_relationship_id
(int): DB ID of the cable relationship. Update when provided or create. -
cable_end
(int): Cable End - 1 or 2. Required for new endpoints. -
machine_design_id
(int): Endpoint Machine design ID. -
device_port_name
(str): Device port name. -
connector_name
(str): Connector name.
Example to create a new cable design endpoint
cable_design = cable_design_api.add_or_update_cable_design_endpoint(
cable_design_id=cable_design.id,
# endpoint_relationship_id=166355,
cable_end=1, # Only required for new endpoints. Can be supplied to update later
machine_design_id=7570,
# device_port_name="port 3",
# connector_name="e1-1",
)
Update existing cable endpoint.
cable_design = cable_design_api.add_or_update_cable_design_endpoint(
cable_design_id=1234,
endpoint_relationship_id=166355,
machine_design_id=7570,
device_port_name="port 3",
connector_name="e1-1"
)
This function is used to delete a cable design endpoint. It requires the cable design ID and the endpoint relationship ID to identify the specific endpoint to be deleted.
-
cable_design_id
(int): DB ID of the cable design. -
endpoint_relationship_id
(int): DB ID of the cable relationship.
To delete a cable design endpoint, provide the necessary IDs:
deleted_endpoint = cable_design_api.delete_cable_design_endpoint(
cable_design_id=1234,
endpoint_relationship_id=166355
)
## Update cable design metadata
Cable design metadata could be updated using an object ItemDomainCableDesignMetadata.
This object includes cable design metadata fields.
### `ItemDomainCableDesignMetadata` Fields
- `cable_design_id`: int - ID of the cable design to update.
Metadata fields:
- `external_cable_name`: str
- `import_cable_id`: str
- `alternate_cable_id`: str
- `laying`: str
- `voltage`: str
- `routed_length`: str
- `route`: str
- `total_req_length`: str
- `notes`: str
- `endpoint1_description`: str
- `endpoint1_route`: str
- `endpoint1_end_length`: str
- `endpoint1_termination`: str
- `endpoint1_pinlist`: str
- `endpoint1_notes`: str
- `endpoint1_drawing`: str
- `endpoint2_description`: str
- `endpoint2_route`: str
- `endpoint2_end_length`: str
- `endpoint2_termination`: str
- `endpoint2_pinlist`: str
- `endpoint2_notes`: str
- `endpoint2_drawing`: str
### Usage
```python
from cdbApi import ItemDomainCableDesignMetadata
# Only update the external cable name metadata field. The other fields will be ignored.
metadata_to_update = ItemDomainCableDesignMetadata(cable_design_id=347891,
external_cable_name="TEST")
updated_metadata = cable_design_api.update_cable_design_metadata(metadata_to_update)
Full metadata can also be fetched and passed into the update function:
fetched_metadata = cable_design_api.get_cable_design_metadata(347891)
fetched_metadata.voltage = "120V"
updated_metadata = cable_design_api.update_cable_design_metadata(fetched_metadata)
Example with all of the fields:
metadata_to_update = ItemDomainCableDesignMetadata(
cable_design_id=347891,
external_cable_name="HighVoltage-123",
import_cable_id="IMP-456",
alternate_cable_id="ALT-789",
laying="Underground",
voltage="11kV",
routed_length="150m",
route="Substation A to Transformer B",
total_req_length="160m",
notes="Ensure compliance with safety standards. Check for potential interference with existing utilities.",
endpoint1_description="Substation A - Main Panel",
endpoint1_route="Cable Tray 1",
endpoint1_end_length="5m",
endpoint1_termination="Ring Terminal",
endpoint1_pinlist="Pin A1, Pin A2",
endpoint1_notes="Verify connection integrity and insulation.",
endpoint1_drawing="Drawing-SubA-Panel.pdf",
endpoint2_description="Transformer B - Input Terminal",
endpoint2_route="Cable Duct 3",
endpoint2_end_length="4m",
endpoint2_termination="Lug Terminal",
endpoint2_pinlist="Pin B1, Pin B2",
endpoint2_notes="Ensure proper grounding and secure connections.",
endpoint2_drawing="Drawing-TransB-Terminal.pdf"
)
updated_metadata = cable_design_api.update_cable_design_metadata(metadata_to_update)