Item Type Validation Example - Intergraph Smart Electrical - Help - Hexagon

Intergraph Smart Electrical Help

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

The code in the following example allows you to write an item type validation routine that will improve the efficiency of your plant or project.

The following example deals with the item type validation of Motors. The example shows how a motor with a Rated Power of 20hp and Rated Voltage of 460 volts, can only be saved with specific values. In this example these three properties must have specific values in order to save the Motor. The three properties and their values are;

  • Supply = AC

  • Number of phases = 3

  • Frequency = 60Hz

If any of these conditions are not met an error message is displayed.

For this code example to work, prior to implementing the item type validation, you have to create a new custom property for motors in Data Dictionary.

You can use this example code to write your own programming routine for a different item type.

public class class 1 : ISPELItemValidation

{public string _lastErrorMessage {get; private set;}

public bool SavingItem(ISPItem objISPItem)

{

try

{

// Works only for Motor

if (objISPItem.ItemType.Name != "Motor")

{

return true;

}

var supply = objISPItem.Attributes{"Supply AcDCFlag"}.Value as String:

if (supply !="AC")

{

LastErrorMessage = "Motor supply must be AC";

return false;

}

var phaseNum = objISPItem.Attributes{NoOfPhases"].Value as string;

if (phasesNum != "3")

{

LastErrorMessage = "Motor number of phases must be 3";

return false;

}

var frequency =objISPItem.Attributes["Frequency'}.Value as string;

if (frequency !="60Hz")

{

LastErrorMessage = "Motor frequency must be 60Hz";";

return false;

}

catch (exception err)

}

LastErrorMessage = err.message;

return false;

}

}

}