Can I create locations in StationWare by using Python?

Category:
Scripts
Summary

I have a list of all new Locations in a csv file that have to be added in existing StationWare data base. I want to do this automatically by using Python scripts and not manually that would consume a lot of time.  Structure of the csv file is as following Substation_Name/Region_Name/Area_Name. So I would like to create structure of Regions/Areas/Substation in my StationWare.

Answer
  • Select the top level location to create regions/areas/substations. This will be defined in the script itself in the get_parameters() function as obligatory parameter.
def get_parameters():
prLocation=Parameters.Create(Localization.RootLocationIdentifier,Localization.RootLocationName)
prLocation.Description="Select where topology should be created"
prLocation.Type=ParameterType.Location
prLocation.Level=ParameterType.Location
prLocation.Optional=False
Parameters.Add(prLocation)
return
  • Once this was defined we have to get the information on the selected location inside of the execute() function:
def execute():
location=Parameters.Get(Localization.RootLocationIdentifier).Value
Output.AppendLine("Selected Location ID: "+ location)

To avoid creating already existing locations (to avoid having double locations) consider it in you script.

  • Accessing a csv file is also an important topic. For more information on this refer to the FAQ "Is it possible to access and use a csv file via Python Scripts?".
  • To create locations of different location types (regions, areas and substations) use the same simple service method LocationCreate()

if region not "existing":

createdRegion=Service.LocationCreate("PSMS.Custom.Locations.Region",row[position of the name],"description if any to be added",rootOftheRegion,True,DateTime.Now)

else:

do something

 

if area not "existing":

createdArea=Service.LocationCreate("PSMS.Custom.Locations.Area",row[position of the name],"description if any to be added",createdRegion.Id,True,DateTime.Now)

else:

do something

 

if substation not "existing":

createdSubstation=Service.LocationCreate("PSMS.Custom.Locations.Substation",row[position of the name],"description if any to be added",createdArea.Id,True,DateTime.Now)

 

 

Back