PSI Data Export CLI
Command-line tool for exporting ERP data from AFTEC/UniData. Provides both WCF-based and direct database access methods for extracting BOMs, products, and where-used data.
Overview
The PSI Data Export CLI (psi-export.exe) is a .NET command-line tool that exports data from the AFTEC ERP system. It supports multiple export methods with different performance characteristics.
| Method | Backend | Performance | Use Case |
|---|---|---|---|
WCF (bom) | PSI Local Service | ~5-7 min/project | Interactive use, debugging |
Direct (direct-bom) | UODOTNET (legacy) | ~6-10 sec/project | Batch exports |
Direct + U2 (direct-bom --u2) | U2 Toolkit | ~3-5 sec/project | Production, fastest |
Location: C:\GIT\PSI.All\PSI.DataExport.CLI
Output: bin\Release\net48\psi-export.exe
Installation
Build from Source
cd C:\GIT\PSI.All\PSI.DataExport.CLI
# Restore packages
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" `
PSI.DataExport.CLI.csproj -t:Restore -p:Configuration=Release
# Build
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" `
PSI.DataExport.CLI.csproj -p:Configuration=ReleaseNote: Must use MSBuild, not
dotnet build(PSI libraries have WPF/LC dependencies).
Dependencies
| DLL | Purpose | Required For |
|---|---|---|
| PSI.UniSessionManager.dll | UniData session management | Legacy backend |
| UODOTNET.dll | UniData .NET API (deprecated) | Legacy backend |
| U2.Data.Client.dll | U2 Toolkit for .NET | U2 backend |
| PSI.DataAccess.dll | WCF data access | WCF commands |
| PSI.Common.dll | Common utilities | All |
| PSI.Common.Models.dll | Credential decryption | U2 backend |
Commands
bom - BOM Export (WCF)
Export Bill of Materials using the WCF service layer.
# Basic usage
psi-export bom 2356 # Export BOM for job 2356
# Options
psi-export bom 2356 -o output.csv # Specify output file
psi-export bom 2356 -f json # Export as JSON
psi-export bom 2356 -t part # Export for a part number
psi-export bom 2356 -t so # Export for a sales order
psi-export bom 2356 --no-children # Top level onlyOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output file path | stdout |
-f, --format | Output format (csv/json) | csv |
-t, --type | Request type (job/part/so) | job |
--flat | Flattened output | true |
-c, --children | Include all child levels | true |
direct-bom - Direct Database BOM Export
Export BOM bypassing WCF for significantly faster performance. Uses VB_BOMX.REV1 subroutine directly.
# Single project (legacy UODOTNET backend)
psi-export direct-bom 2356 -o bom_2356.csv
# Single project (U2 Toolkit backend - recommended)
psi-export direct-bom 2356 --u2 -o bom_2356.csv
# Test mode (check mlevel behavior)
psi-export direct-bom test
psi-export direct-bom 2356 # Test specific project
# Batch export (U2 Toolkit recommended for best performance)
psi-export direct-bom -b projects.csv -o BOM_Exports --u2
psi-export direct-bom -b projects.csv -o BOM_Exports --u2 -r # Resume modeOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output file/folder | - |
-b, --batch | Batch mode with CSV input | - |
-r, --resume | Skip existing exports | false |
--u2 | Use U2 Toolkit backend (faster) | false |
Backend Comparison:
| Backend | Flag | Speed | Notes |
|---|---|---|---|
| UODOTNET (legacy) | (default) | ~700 parts/sec | Deprecated, uses PSI.UniSessionManager |
| U2 Toolkit | --u2 | ~1300 parts/sec | Modern, recommended for production |
Recommendation: Use
--u2for all production workloads. See U2 Toolkit Migration Guide for technical details.
Batch Input Format:
CSV file with ProjectNo column:
ProjectNo,Description
2356,Machine A
2357,Machine Bbatch-bom - Parallel BOM Export (WCF)
Export multiple BOMs in parallel using WCF connections.
psi-export batch-bom projects.csv -o BOM_Exports -p 4
psi-export batch-bom projects.csv -o BOM_Exports -r # ResumeOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output folder | BOM_Exports |
-p, --parallel | Concurrent exports | 4 |
-r, --resume | Skip existing | false |
fast-bom - Fast Parallel Export
Faster batch export with parallel connections and recursive child fetching.
psi-export fast-bom projects.csv -o BOM_Exports -p 6Options:
| Option | Description | Default |
|---|---|---|
-o, --output | Output folder | BOM_Exports |
-p, --parallel | Parallel connections | 6 |
-r, --resume | Skip existing | false |
parallel-bom - TRUE Parallel Export
Maximum parallelism using Parallel.ForEach.
psi-export parallel-bom projects.csv -o BOM_Exports -p 8Options:
| Option | Description | Default |
|---|---|---|
-o, --output | Output folder | BOM_Exports |
-p, --parallel | Parallel workers | 8 |
-r, --resume | Skip existing | false |
categories - Product Categories
Export product categories from PRODUCT.CLASS.1287.
psi-export categories # Export all categories
psi-export categories -c # Include product counts
psi-export categories -f json # JSON format
psi-export categories -o cats.csv # Specify outputOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output file | auto |
-f, --format | Format (csv/json) | csv |
-c, --counts | Include counts | false |
products - Product Lookup
Lookup part classification or export all products.
psi-export products 715099 # Lookup single part
psi-export products --all # Export all products
psi-export products --all -f json # JSON formatOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output file | - |
-f, --format | Format (csv/json) | csv |
-a, --all | Export all products | false |
whereused - Where-Used Query
Find all jobs and assemblies that use a part.
psi-export whereused 715099 # Find usage of part
psi-export whereused 715099 -r # Recursive (all parents)
psi-export whereused -p parts.txt # Batch from fileOptions:
| Option | Description | Default |
|---|---|---|
-o, --output | Output file | auto |
-f, --format | Format (csv/json) | csv |
-r, --recursive | Find all parent assemblies | false |
-p, --parts-file | Batch input file | - |
Output Formats
BOM CSV Format
| Column | Description |
|---|---|
| Level | Hierarchy depth (0 = top) |
| WbsNumber | Work breakdown structure ID |
| ParentPartNumber | Parent in hierarchy |
| PartNumber | Part number |
| Description | Part description |
| GTCode | Group technology code |
| Quantity | Total quantity |
| QtyPerParent | Qty per parent assembly |
| QtyPerLeg | Qty in this leg |
| OnHand | Inventory on hand |
| OnOrder | Quantity on order |
| Available | Available quantity |
| TotalAllocated | Total allocated |
| HasChildren | Has child components |
| IsPurchased | Purchase part flag |
| IsManufactured | Manufactured part flag |
| JobNumber | Associated job |
| ExportDate | Export timestamp |
Where-Used CSV Format
| Column | Description |
|---|---|
| QueryPartNumber | Part searched for |
| QueryPartDescription | Part description |
| ParentPartNumber | Parent assembly |
| ParentDescription | Parent description |
| ParentGTCode | Parent GT code |
| JobNumber | Job using this part |
| Quantity | Quantity used |
| Level | Hierarchy level |
| WbsNumber | WBS ID |
| ExportDate | Export timestamp |
Architecture
WCF Flow (Slow)
CLI → PSI.DataAccess → WCF Service → PSI Local Service
→ UniData Subroutine → AFTEC Database
Each BOM level requires a separate WCF call with 100-500ms overhead. A project with 2,000 parts needs 100-200+ sequential calls.
Direct Database Flow (Fast)
Two backend options for direct database access:
Legacy Backend (UODOTNET)
CLI → PSI.UniSessionManager → UDSessionController → UODOTNET.dll
→ VB_BOMX.REV1 → AFTEC Database
- Uses deprecated
UODOTNET.dllviaPSI.UniSessionManager - ~700 parts/second throughput
- Default behavior (no flag needed)
U2 Toolkit Backend (Recommended)
CLI → U2.Data.Client.dll → UniSession → CreateUniSubroutine()
→ VB_BOMX.REV1 → AFTEC Database
- Uses modern
U2.Data.Client.dlldirectly - ~1300 parts/second throughput (~2x faster)
- Enable with
--u2flag - Officially supported by Rocket Software
See U2 Toolkit Migration Guide for implementation details.
Key Subroutine: VB_BOMX.REV1
Both backends use VB_BOMX.REV1 for BOM explosion:
Parameters:
- Company (always “1”)
- ReqType (“JOB” or “PART”)
- IncludeParts (“1”)
- MLevel (“0” - handled in code)
- LDS (“0”)
- PartNumber (job or part number)
- Qty (“1”)
- WBS (work breakdown structure)
- RawData (output)
- MessageInfo (output)
Returns immediate children only; the CLI recursively fetches all levels.
Performance Comparison
| Method | Backend | Time/Project | 100 Projects | Parts/sec |
|---|---|---|---|---|
bom (WCF) | WCF Service | ~5-7 min | ~10 hours | ~5 |
batch-bom (4x parallel) | WCF Service | ~5-7 min | ~2.5 hours | ~20 |
direct-bom | UODOTNET | ~6-10 sec | ~15 min | ~700 |
direct-bom --u2 | U2 Toolkit | ~3-5 sec | ~8 min | ~1300 |
Recommendation: Use direct-bom --u2 for all batch exports.
Common Use Cases
Export All Project BOMs (Fastest)
# Create project list from recent projects
# (assumes you have a CSV with ProjectNo column)
# Fast batch export with U2 Toolkit and resume capability
psi-export direct-bom -b shipped_projects.csv -o BOM_Exports --u2 -rLookup Part Usage
# Find all jobs using a specific part
psi-export whereused 715099 -r -o whereused_715099.csvExport Product Classifications
# Export all products with their categories
psi-export products --all -o products_with_class.csvTroubleshooting
”Failed to establish database session”
- Ensure you’re logged into Windows with a valid PSI account
- Check that PSI Local Service is running (for WCF commands)
- Verify UniData connectivity
”The user name or password provided is incorrect” (Error 80011)
When using --u2 flag:
- Credentials must be decrypted before use
- Ensure PSI.Common.Models.dll is available for
EncryptionService - See credential decryption section
”User/pool limit reached” (Error 39134)
When using --u2 flag:
- Connection pooling requires specific server license
- The CLI disables pooling by default to avoid this
- If you see this error, ensure
Pooling = falsein connection string
”No BOM data returned”
- Verify the job/project number exists
- Check if the project has a released BOM
- Try the WCF
bomcommand to compare results
Slow Performance
- Use
direct-bom --u2instead ofbomfor batch operations - Check network connectivity to UniData server
- Consider running during off-peak hours
Source Files
Key implementation files in PSI.DataExport.CLI:
| File | Purpose |
|---|---|
Commands/DirectBomCommand.cs | CLI command handler |
Services/DirectBomExporter.cs | Legacy UODOTNET implementation |
Services/U2ToolkitBomExporter.cs | U2 Toolkit implementation |
Helpers/UniDynArrayParser.cs | Parses U2 Toolkit results |
Future Commands
Planned additions based on available UniData subroutines:
| Command | Priority | Description |
|---|---|---|
direct-parts | High | Part master export |
direct-jobs | High | Work order data |
direct-inventory | Medium | Inventory levels |
xref | Low | Part cross-reference |
Related Pages
- U2 Toolkit Migration Guide - UODOTNET to U2 migration
- PSI.All Architecture - Codebase and subroutines
- Data Brain - Data sources and systems
- Data Brain - Master data reference
- Terminology - BOM and part terms
Last updated: February 2025