Code Example and Explanation - Intergraph Smart Electrical - Help - Hexagon

Intergraph Smart Electrical Help

Language
English
Product
Intergraph Smart Electrical
Search by Category
Help
Smart Electrical Version
10

The following example shows how to customize reports that contain load balancing calculated data.

Currently, you can do this for All Feeder Load Summary and in Multi-Sheet Switchboard Summary reports.

Calling the Calculation Function

In order to get calculated data from Smart Electrical, you need to run the calculation function:

Public Function RunLoadCalculationStandAlone(objTree As SmartPlantElectricalClcStAlR.PlantItemsTree, colData As Collection, colOutputData As Collection, objBO As SpelBusinessInf.IBOCommon) As Long

Parameters

  • objTree: an output parameter containing the calculated electrical network.

  • colData: an input parameter which contains the following application data (When running the report from the application, it is possible to get the data from XLAgent.RunLoadCalculationNoMarshalingWithCases function. For details, see Retrieving Input Parameters for Calculation Function at the end of this topic):

    • Key: "SelectedSPIDs", value: a collection of the SP_IDs of the PDBs or buses which are the root items for the drill down calculation. These IDs can be received from the RunLoadCalculationNoMarshalingWithCases function.

    • Key: "ActivePlant", value: <The active plant name> (Example: "EL2015R1_76SC")

    • Key: "SiteServer", value: <The site server name> (Example: "\\isrvspeldb15R1\SmartPlant\Ora2015R1\smartplantv4.ini")

    • Key: "SelectedItemType", value: the selected item type, either "PowerDistributionBoard" or "Bus".

    • Key: "SelectedOperatingCases", value: an object of typeSPELComMediators.Dictionary with the required operating case IDs (See Example: The way to retrieve the operating case IDs is as follows at the end of this topic).

  • colOutputData: an output parameter of type collection, containing the following preferences:

"CalcMode"

Calculation method (Example: "Use bus Coincidence factor")

"Coupling"

Inclusion of coupled buses in All Feeder Load Summary Report. (Example: "Include coupled buses connected by couplers only")

"Losses"

Accounts for converting equipment power losses. (Example: "No calculation for converting equipments losses.")

  • objBO - irrelevant - can be null

Drilling Down the Calculated Data

The drill down calculation calculates the largest load calculation in addition to the regular summary when the Calculate according to largest non-continuous load application preference is set to true.

The RunLoadCalculationStandAlone function returns the objTree output parameter, which contains the RootItems collection, which contains the calculated electrical network.

The RootItems can be one of the following:

  • The items (PDB's or buses) which were selected by the user in the application.

  • The whole calculated electrical network if you did not select any PDB or bus for your report.

  • The whole calculated electrical network if you are customizing a registered report.

Dim objTree As SpelCalcReportsInf.IPlantItemsTree

Dim objPlantItem As SpelCalcReportsInf.IElectricalPlantItem

Dim colOutputdata As Collection

Dim objBO As SPELBusinessInf.IBOCommon

Dim res As Long

...

res = m_objXLAgentStandAlone.RunLoadCalculationStandAlone(objTree, colData, colOutputdata, objBO)

If objTree.RootItems.Count > 0 Then

...

End If

Use the "For Each" loop to drill down the objTree.RootItems to its PDBs or buses:

Dim objPlantItem As SmartPlant ElectricalCalcReportsInf.IElectricalPlantItem

For Each objPlantItem In objTree.RootItems

...

Next

Next, we have to know the item type of the items for which the calculation was carried out. You can get it by using the objPlantItem.ItemType property:

Dim lRes As Long

Select Case objPlantItem.ItemType

Case ePowerDistributionBoardItem

'Call a function that contains a PDB handling code:

lRes = FillPDB(objPlantItem.ToPowerDistributionBoard)

Case eBusItem

'Call a function that contains a bus handling code:

lRes = FillBus(objPlantItem.ToBus, Nothing, 0, True)

End Select

If the root item type is a PDB, then access each PDB through the SpelCalcReportsInf.IPowerDistributionBoard interface:

Dim udPDB As SpelCalcReportsInf.IPowerDistributionBoard

Dim pdbDescription As String 'a PDB attribute

Dim sCaseId As String 'the operating case you want to get the data for.

Access the PDB object using the objPlantItem.ToPowerDistributionBoard function:

For Each objPlantItem In objPlantTree.RootItems

Set udPDB = objPlantItem.ToPowerDistributionBoard

It is possible to get a value of any attribute of the PDB, e.g. Description, by using the ToIElectricalPlantItem method:

pdbDescription = udPDB.ToIElectricalPlantItem.PropertyValue("Description", sCaseId)

(sCaseId is the ID of the requested operating case. It is an optional parameter and relevant only to the operating case data).

Apart from the attributes of the PDB, it is possible to get all the calculated PDB total values by using the PDB function ToElectricalPlantItem, as follows:

udpDB.ToIElectricalPlantItem.[Some_Total_Value]

Next, we want to get the buses which belong to the PDB, through the SpelCalcReportsInf.IBus interface:

Dim udBus As SpelCalcReportsInf.IBus

Dim busYCoincidenceFactor As String 'an example bus attribute

Dim sCaseId As String 'the operating case you want to get the data for.

For Each udBus In udPDB.Buses

...

Next udBus

It is possible to get a value of any attribute of the bus, for example: YCoincidenceFactor, by using the ToIElectricalPlantItem.PropertyValue method:

busYCoincidenceFactor = udBus.ToIElectricalPlantItem.PropertyValue("YCoincidenceFactor", sCaseId)

(sCaseId is the ID of the requested operating case. It is an optional parameter and relevant only to the operating case data).

Every bus object contains a collection of the loads connected directly to the bus:

Dim udLoad As SpelCalcReportsInf.ILoad 'represents a single load

Dim objColLoads As SpelCalcReportsInf.ILoads 'represents the collection of the bus direct loads

Dim loadRatedVoltage As String 'a load attribute

Dim sCaseId As String 'the operating case you want to get the data for.

Set objColLoads = udBus.DirectLoads 'the bus direct load collection.

For Each udLoad In objColLoads

'...

Next udLoad

It is possible to get a value of any attribute of the load, like RatedVoltage, using the ToIElectricalPlantItem method:

loadRatedVoltage = udLoad.ToIElectricalPlantItem.PropertyValue("RatedVoltage", sCaseId)

(sCaseId is the ID of the requested operating case. It is an optional parameter and relevant only to the operating case data).

It is also possible to get all the bus circuits by using the ChildrenByItemType method:

Dim objColCircuits As SpelCalcReportsInf.IElectricalPlantItems

Dim udCircuit As SpelCalcReportsInf.ICircuit

Dim circuitType As String

Dim sCaseId As String 'the operating case you want to get the data for.

Set objColCircuits = udBus.ToIElectricalPlantItem.ChildrenByItemType(eCircuitItem) ' eCircuitItem is a value indicating a circuit item type.

For Each udCircuit In objColCircuits

'...

Next udCircuit

It is possible to get a value of any attribute of the circuit, e.g. CircuitType, by using the ToIElectricalPlantItem method:

circuitType = udCircuit.ToIElectricalPlantItem.PropertyValue("CircuitType", sCaseId)

(sCaseId is the ID of the requested operating case. It is an optional parameter and relevant only to the operating case data).

Retrieving the Calculated Totals

The total values of the calculated buses and circuits can be retrieved from their IElectricalPlantItem interface:

Dim objPlantItem As SpelCalcReportsInf.IElectricalPlantItem

Dim compensatedRatedTotals as Object

Dim unCompensatedRatedTotalsas Object

Dim compensatedConsumedTotals as Object

Dim unCompensatedConsumedTotals as Object

'Examples for total values:

Dim intermittentActive as String

Dim intermittentReactive as String

Dim standbyActive as String

Dim standbyReactive as String

'... Initialize objPlantItem ...

Set compensatedRatedTotals = objPlantItem.TotalCompensatedRated

Set unCompensatedRatedTotals= objPlantItem.TotalUnCompensatedRated

Set compensatedConsumedTotals = objPlantItem.TotalCompensatedConsumed

Set unCompensatedConsumedTotals = objPlantItem.TotalUnCompensatedConsumed

Now it is possible to get the total calculated values. Examples:

intermittentActive = compensatedRatedTotals.IntermittentActive(sCaseId)

intermittentReactive = unCompensatedRatedTotals.IntermittentReactive(sCaseId)

standbyActive = compensatedConsumedTotals.StandbyActive(sCaseId)

standbyReactive = unCompensatedConsumedTotals.StandbyReactive(sCaseId)

This example finds if the largest load was selected for a specific bus and one of its circuits. It then gets the values of the largest load that was selected:

Dim udBus As SpelCalcReportsInf.IBus 'the bus for which the largest load is looked for.

Dim udCircuit As SpelCalcReportsInf.ICircuit 'one of the bus circuits, for which the largest load is looked for.

Dim tempBusLoadItem As SpelCalcReportsInf.ILoad 'the largest bus load

Dim tempCircuitLoadItem As SpelCalcReportsInf.ILoad 'the largest circuit load

Dim largestLoad As SpelCalcReportsInf.ILoad 'the largest load of both the bus and the circuit

Dim sCaseId As String 'the relevant operating case

Dim active As Double 'the largest load active value

Dim reactive As Double 'the largest load reactive value

'... Initialize udBus, udCircuit and sCaseId ...

...

If udBus.LargeIntIsTaken(sCaseId) And udCircuit.LargeIntIsTaken(sCaseId) Then

Set tempBusLoadItem = udBus.LargestIntermittentLoad(sCaseId)

Set tempCircuitLoadItem = udCircuit.LargestIntermittentLoad(sCaseId)

'If this circuit contains the largest load for the bus, get the values for the largest item from the circuit:

If tempBusLoadItem.ToIElectricalPlantItem.SPID = tempCircuitLoadItem.ToIElectricalPlantItem.SPID Then

Set largestLoad = udCircuit.LargestIntermittentLoad(sCaseId)

active = largestLoad .ConsumedActiveLoad(sCaseId)

reactive = largestLoad .ConsumedReactiveLoad(sCaseId)

End If

End If

Retrieving Input Parameters for Calculation Function

You can get all the values required by RunLoadCalculationStandAlone function by running RunLoadCalculationNoMarshalingWithCases function which resides in the SPELXL.dll. Smart Electrical passes SPELXL.dll as a parameter to the BeginReport function in Excel automatically when running a report.

The RunLoadCalculationNoMarshalingWithCases function returns the following application data:

  • The operating case IDs (SPELComMediators.Dictionary). Key: "SelectedOperatingCases" which are the ID's of the cases selected by user in the application.

  • The active operating case id (String). Key: "ActiveOperatingCasesId".

  • The active plant name (String). Key: "ActivePlant".

  • The site server name (String). Key: "SiteServer".

  • The selected item type either "PowerDistributionBoard" or "Bus". Key: "SelectedItemType".

  • The compensated / uncompensated preference value (CompensatedUncompensated enum). Key: "CompensatedUncompensated".

  • The rated / consumed preference value (RatedConsumed enum). Key: "RatedConsumed".

  • A boolean value indicating whether the report was run for a selected group of items or without any selection (for all PDBs). Key: "RunNonSelectedReport".

  • The report type (String). E.g. "Uncompensated Consumed Loads". Key: "ReportType".

  • A collection of the selected SPIDs (of the selected PDBs or buses). Key: "SelectedSPIDs".

Example:

Dim colData As Collection 'Input parameter for RunLoadCalculationNoMarshalingWithCases which will contain the output operating cases IDs

Dim res As Long

Dim operatingCases As SPELComMediators.Dictionary

'RunLoadCalculationNoMarshalingWithCases function will insert the operating case IDs into this collection.

Set operatingCases = New SPELComMediators.Dictionary

Set colData = New Collection

colData.Add operatingCases, "SelectedOperatingCases" 'You get the selected operating cases in this manner.

res = m_objXLAgent.RunLoadCalculationNoMarshalingWithCases(colData, True)

Adding Item Properties to a Report

You can add any property of any item type to a report.

From any plant item implementing IBus, ICircuit, IConvertingEquipment, ILoad and IPowerDistributionBoard interfaces you can get an ElectricalPlantItem object which contains all the plant item properties.

Use the ToIElectricalPlantItem() function to get the ElectricalPlantItem object.

Call the PropertyValue() function to get any property value including user defined fields:

Public Property Get PropertyValue(ByVal PropertyName As String, Optional ByVal sCaseId As String = NoOperatingCaseProperty) As Variant

Example: Getting the DemandFactor property value of a load item:

Dim udLoad As SpelCalcReportsInf.ILoad

Dim sCaseId As String

Dim demandFactor As String

...

demandFactor = udLoad.ToIElectricalPlantItem.PropertyValue("DemandFactor", sCaseId)

Adding a Column to the Report Template

In the shipped reports, every column has a name. If you add your own column, it will not affect our code because we access the columns by their names. Nonetheless, we recommend that you use your custom names for the columns that you add.

For example, if you want to add a column for the UDF1 field, we recommend doing this in the following manner:

  1. In the Excel worksheet, insert a new column in the required place.

  2. Select the column and on the Name Box of the worksheet change the column name to a meaningful name indicating the property to be displayed. The column name should be in accordance with the column naming standard of the excel worksheet. For example, if the column should display the UDF1 property value, and the naming standard is col_<PropertyName>, the column name can be set to col_UDF1.

  3. After the column has been set, set the value by using the ToIElectricalPlantItem function described above to set the required value. For example, if you want to display the value of UDF1 property of the load, you should do the following:

Dim udLoad As SpelCalcReportsInf.ILoad 'the load to work with

Dim ws As Worksheet 'the excel worksheet

Dim lRowCounter as Integer 'indicates the row number

Dim sCaseId as String 'the operating case ID

Dim sSuffix As String 'indicates the operating case column

...

With ws

.Cells(lRowCounter, ThisWorkbook.Names.Item("col_UDF1" + sSuffix).RefersToRange.Column) = udLoad.ToIElectricalPlantItem.PropertyValue("UDF1", sCaseId)

...

End With