# AdapterForSpid

## Introduction

The purpose of **AdapterForSpid** is to extract data used by Intergraph Smart® P&ID (SPID) into a local `UPVP` database for use with UDiTH.

## Graphical User Interface (GUI)

### Invoking **AdapterForSpid**

After starting, the following UI will appear:

<img src="./media/AdapterForSpid_image10.png" width="490" height="331">

### Loading a plant

The software automatically connects to the active plant. It is displayed in the field **Plant** and can be changed using the **Change active plant\...** button.

From the **Open plant structure** dialogue, you can select another plant from the active site. Plants from other sites can be accessed by using the **Site server\...** button.

<img src="./media/AdapterForSpid_image11.png" width="424" height="243">

Before loading the plant data, the **Output Access file** must be specified using the **Browse\...** button.

## Extracting data

Clicking the **Extract** button starts extraction from the selected plant. The following extraction options are available: **All**, **Selected drawings**, **Associated data**, and **Extract drawing files**.

### General extraction settings

#### All

The **All** option extracts all plant data without requiring further configuration.

#### Selected drawings

The **Selected drawings** option starts the extraction with a dialogue in which the required drawings can be selected.

A list of available drawings from the active project appears.
Select the required drawings in the dialogue and press **OK** to start the extraction.

<img src="./media/AdapterForSpid_image12.png" width="251" height="227">

<img src="./media/AdapterForSpid_image13.png" width="256" height="265">

In Connected Workshare projects, drawings that belong to the satellite are displayed in red so that the user is informed about their status.

#### Associated data

The **Associated data** option starts the extraction with a dialogue in which the required data can be defined by using SQL statements.

<img src="./media/AdapterForSpid_image14.png" width="685" height="313">

For example, the statement shown above extracts only pipe runs whose tags begin with `05`.

In the same way, it is possible to extract only pipe runs with `FluidSystem` set to `Water` or `Nominal Diameter` set to `100 mm`.

The same interface can also be used to search data, for example to check whether a certain sequence number has been used in the plant. The yellow bar can be used to enter a search string without performing the extraction:

<img src="./media/AdapterForSpid_image15.png" width="586" height="183">

#### Revision

The **Revision** option allows extraction of frozen data, but only for revisions that have an associated version. The dialogue allows you to select either the **Last Revision** data or the data for a specific revision:

![](./media/AdapterForSpid_image16.png)

### Settings related to the from/to calculation

The following options can be used when extracting the from/to information:

![](./media/AdapterForSpid_image17.png)

**Only equipment tag:** Reports only equipment tags, not nozzle tags.

**No branches:** Does not report branch connections.

**Use component description if no tag:** Reports the `Piping Component Description` attribute if the component tag is empty and if the component is an `EndComponent`.

In addition to these settings the following changes were implemented:

#### Tema heat exchangers

![](./media/AdapterForSpid_image18.png)

If the front and rear sections do not have their own item tags defined, the shell item tag is also extracted as from/to information for pipe runs connected to the front or rear section.

In the example above, all runs connected to the parts of the heat exchanger have `W-170` as from or to information.

#### Equipment with no tag

For equipment without a tag, it is possible to use a variable that tells the software which attribute to use as from/to information, for example `Name` or `Description`.

This is done by using the PID ReportAdapter `.ini` file:

`...\Program Files (x86)\CAXperts\IntelliPID Adapter\IntelliPID Adapter.ini`

```ini
[FROM_TO]
Equipment_NoTag=Name
```

## Additional SQL statements 

### Create additional SQL statements

SQL statements can be used to extend standard output tables with user-defined attributes or to perform other tasks, such as creating additional tables or queries. These statements can be defined using **Tools → Additional SQL statements**. They are executed automatically after the extraction process has been completed.

The additional SQL statements can be entered in the **Additional SQL statements to be processed after extraction** field. They should follow the format shown in the following examples:

`SQL1=ALTER TABLE Equipment ADD COLUMN [MyAttribute] VARCHAR(255)`

`SQL2=UPDATE [Equipment] SET [MyAttribute] = 'Test'`

![](./media/AdapterForSpid_image19.png)

The tables that can be used in the queries are those created during extraction. Additional tables, if required, must be copied before extraction into the `template.mdb` database, which can be found in the application folder.

### Use query builder

The included query builder can help you create SQL statements.
Create a new statement with the **Add** button and add one of the **Available SQL query templates** to it. Clicking **Add query**, or double-clicking a list item, inserts the query at the cursor position or replaces the selected text.

The **Available SQL query templates** look like this:

`UPDATE [%TABLE1%] SET [%TABLE1%].[%COLUMN1%]=`

When the template is used, the `%TABLE1%` and `%COLUMN1%` placeholders are filled with the table name and column name selected in the corresponding fields.

The `%TABLE1%` and `%COLUMN1%` fields are filled from the Access database defined for extraction output, which also includes the tables from `Template.mdb`. This means that the fields are filled only after extraction has been performed at least once.

If the **Show hidden tables** option is selected, all tables in the database can be chosen when building the query. If it is not selected, only the tables displayed in **UniversalReporter** are available, and tables created for internal use are hidden.

### Create new SQL query template

User-defined **SQL query templates** can be created. To add a new template, click the **Add** button and enter the template name.

<img src="./media/AdapterForSpid_image21.png" width="523" height="210">

Enter the SQL statement text and the placeholders for the **Tables and columns to be used by query** text boxes by using the `%TABLE1%` and `%COLUMN1%` buttons.

User-defined templates can be deleted or modified by using the **Remove** or **Edit** buttons.

> The SQL text boxes support syntax highlighting.

### Additional Settings
To ensure correct extraction for projects with a large number of P&IDs, it is recommended to set the parameter `BigPlant=1`.

For projects that include P&IDs with auxiliary graphics, you can use the parameter `auxiliary=1` to divide the full auxiliary graphics into individual graphical elements.

![](./media/AdapterForSpid_image48.png)

These parameters can be added to the `IntelliPID Adapter.ini` file located in the adapter installation folder.

![](./media/AdapterForSpid_image47.png)

## Configure attributes

### General functions

Select **Tools -\> Attribute configuration\...** to open the **Attribute
configuration** dialog.
Select **Tools -> Attribute configuration...** to open the **Attribute configuration** dialogue.

![](./media/AdapterForSpid_image22.png)

The following window appears.

![](./media/AdapterForSpid_image23.png)

In this dialogue, you can define the attributes to be extracted.

At present, attributes can be added for the following object types: `InlineComp_Prun`, `Eqp_Nozzle`, `PlantItems`, `Instruments`, `ItemNotes`, `OPCs`, and `Drawings`.

Additional attributes, which are not available in SmartPlant P&ID and are created during extraction, are displayed in blue, for example `End_2_ConnectedPiperunID` in the screenshot above.

The numbers displayed on the right side of the tables correspond to the number of available attributes on the left and the number of selected attributes on the right.

Expand the tables and select the required attributes. These can then be transferred to, or removed from, the **Attributes to be used** pane by using the `>` and `<` buttons.

### Filter
You can also search for specific attributes by using wildcard filters. In the following example, the search is for an attribute name containing `Flui` in the `InlineComp_Prun` table.

><img src="./media/AdapterForSpid_image1.png" width="675" height="435">

### Saving attribute configuration
The attribute configuration is saved in the folder `%APPDATA%\CAXperts\IntelliPID Adapter\` with the file name `PlantName.ini`. The attribute configuration can also be saved for backup or for batch-mode extraction by using:

![](./media/AdapterForSpid_image24.png)

## Attribute configuration specialties:

### ParentPlantGroup and UnitCode

For SPEM hierarchies such as `Plant\Area\Unit`, it is possible to extract both the `ParentPlantGroup` information and the `UnitCode` information:

![](./media/AdapterForSpid_image25.png)

This allows easy filtering, for example by area. The selection is available for all objects except `ItemNotes` and `OPCs`.

### PipingPoint attributes including ConnectedPiperunID

For piping connection points `1` to `4`, it is possible to extract attributes such as nominal diameter and description, as well as the `SP_ID` of the connected pipe run. This information can be used to create a report showing the pipe run connected to the second side of a pressure-reducing valve.

![](./media/AdapterForSpid_image26.png)

The result in **UniversalReporter** looks like this:

![](./media/AdapterForSpid_image27.png)

### CaseProcess SI values (also other properties SI values)

The SI values can also be selected for extraction.

![](./media/AdapterForSpid_image28.png)

### Filename and quantity

If `Filename` is selected at the `PlantItem` object level, the symbol name is also extracted, making it possible to see how often a symbol is placed on a drawing.

If `Quantity` is selected, which is available on all object levels, each extracted object is assigned the quantity `1`. In **UniversalReporter**, it is then possible to create `Sum_of_quantity` in order to identify the total number of valves, for example.

![](./media/AdapterForSpid_image29.png)

### Connectivity attributes for the relations "Equipment to PipeRun" and "Instruments to PipeRuns or Equipments"

Although they are not visible in the attribute configuration interface, the following two attributes are extracted:

-   **Nozzle_ConnectedPipeRunID** for the `Eqp_Nozzle` table

-   **Instrument_ConnectedItemID** for the `Instruments` table

These attributes can be used to create reports in which the pipe runs connected to an item of equipment are listed, starting at the equipment object level, or to identify instrument connections, which may be to pipe runs or equipment nozzles.

![](./media/AdapterForSpid_image30.png)

![](./media/AdapterForSpid_image31.png)

**Example for the Equipment_PipeRun Relation**:

![](./media/AdapterForSpid_image32.png)

**Example for the Instrument Connection Report**:

There are multiple ways to connect instruments to nozzles or pipe runs.

The following connections, related to piping components placed between the connected pipe run or connected equipment nozzle and the instrument, have been modified in PID ReportAdapter:

**A**: The instrument is connected to a valve placed in a branch of the main pipe run. The branch is returned as the connected object.

**B**: The instrument is connected to a valve that is connected to a nozzle, where the pipe run type is `Conn to process/Supply`. In this case, the nozzle is returned as the connected object.

**C**: The instrument is connected to a valve that is connected to a nozzle through a `ZeroLength` pipe run. In this case, the nozzle is returned as the connected object.

**D**: The instrument is connected to a valve placed in a pipe run that is itself connected to a nozzle. The pipe run has a special line type. In this case, the nozzle is returned as the connected object. In the example below, the line type is `Components only`.

The definition of the pipe run type can be set in `..\PID ReportAdapter.ini` with the following entry:

```ini
[Instr_Conn]
Nozzle_Pruntype = "Components only"
```

![](./media/AdapterForSpid_image33.png)

![](./media/AdapterForSpid_image34.png)

Details for C and D:

![](./media/AdapterForSpid_image35.png)

Result:

![](./media/AdapterForSpid_image36.png)

### Disconnected piperuns having the same ItemTag

If `NotConnectedRuns` is selected at the `InlineComp_Prun` object level under `Others`, the number of disconnected pipe runs with the same tag is calculated for the extracted dataset.

![](./media/AdapterForSpid_image37.png)

![](./media/AdapterForSpid_image38.png)

Within a drawing, the function checks whether the runs are graphically connected. Across drawings, it checks whether the pipe runs are connected via `OPCs`. Any result greater than `0` indicates duplicate pipe run tags that are not graphically connected.

Warning whenever the database is opened.

The extraction of `NotConnectedRuns` can take some time for larger datasets.

### Identify number of LineNumberLabels placed on a piperun

For all pipe runs, except instrument runs and zero-length pipe runs, if the attribute `NumberofLabels` is selected and the label name or names are defined in the plant-specific `.ini` file, the number of labels placed on each pipe run is calculated during extraction.

In the `.ini` file, located at `.UserProfile\AppData\Roaming\CAXperts\AdapterForSpid\`

`<PlantName>.ini`, the relative path for the line label or labels to be checked must be added:

![](./media/AdapterForSpid_image39.png)

To define more than one label for checking, separate the labels with a semicolon, as shown in the following example:

`Piping=\Piping\Labels - Piping Segments\Line Number.sym;\Piping\Labels - Piping Segments\Line Number_old.sym`

All results different from `1` should be checked. `0` means that no label is placed, while values greater than `1` mean that more than one label is placed on the same run.

![](./media/AdapterForSpid_image40.png)

### Identify the "Parent" relationship between components

By using the attribute `SP_PartOfId`, which is available in the `PlantItem` area for all components, it is possible to extract relationships between an actuator and a valve, an equipment component and its equipment, and similar relationships.

![](./media/AdapterForSpid_image41.png)

![](./media/AdapterForSpid_image42.png)

### SymbolName and coordinates

The `Symbol` table has been added to the extraction interface so that fields from the symbol table can be selected, including the calculated field `Name`, which refers to the name of the symbol, for example `Gate Valve`.

![](./media/AdapterForSpid_image43.png)

### MultiRep for equipment

A new attribute called `MultiRep` has been added to the `Equipment_Nozzle` attribute configuration in the `Others` area:

![](./media/AdapterForSpid_image44.png)

It is calculated during extraction and shows the value `True` for MultiRepresentation equipment and `False` for other equipment.

## Command line mode

**AdapterForSpid** can also be used in command-line mode in order to extract all data from a plant to a `UPVP` file automatically from a batch script.

Use the following command to display the available command-line arguments:

![](./media/AdapterForSpid_image45.png)

Command line arguments:

<img src="./media/AdapterForSpid_image46.png" width="629" height="207">

**Examples:**

`"C:\Program Files (x86)\CAXperts\IntelliPID Adapter\IntelliPID Adapter.exe" -upvp:"d:\temp\PlantA.upvp"`

`"C:\Program Files (x86)\CAXperts\IntelliPID Adapter\IntelliPID Adapter.exe" -upvp:"d:\temp\PlantA.upvp" -site:"d:\Site1\smartplantv4.ini" --plant:PlantA --parentplant:PlantA --config:"d:\PlantA.ini"`

`"C:\Program Files (x86)\CAXperts\IntelliPID Adapter\IntelliPID Adapter.exe" -upvp:d:\temp\1.upvp -pbs:Refining Area\Recovery Unit;\Refining Area\Distillation Unit\a_*`

> This saves all drawings with names starting with `a_` and located in `Refining Area\Recovery Unit` or `Refining Area\Distillation Unit`.

`"C:\Program Files (x86)\CAXperts\IntelliPID Adapter\IntelliPID Adapter.exe" -upvp:d:\temp\1.upvp -unitcode:03`

> This saves all drawings located below the unit with the unit code `03`.

The parameters `-pbs` and `-unitcode` must be used separately, that is, either `-pbs` or `-unitcode`.

The attribute configuration `.ini` file, used in the command line with the `-config` parameter, can be created by using the menu **File - Save settings to file**.

The options **Extract Drawing Files** and **Extract From-To relations for InlineComp_Prun** from interactive mode are saved in the file

`%APPDATA%\CAXperts\IntelliPID Adapter\config.ini`

for example `C:\Documents and Settings\UserName\Application Data\CAXperts\IntelliPID Adapter\config.ini`.

In command-line mode, these two options are read from `config.ini` and used for extraction.

