Skip to content

Commit d8c43a7

Browse files
authored
Environment variable guide (#100)
1 parent 0bea971 commit d8c43a7

3 files changed

Lines changed: 129 additions & 9 deletions

File tree

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* [iTwin CLI Manual](/docs/)
22
* [iTwin 101](/docs/itwin101.md)
33
* [Quickstart](/docs/quickstart.md)
4+
* [Environment](/docs/environment.md)
45
* [Workflows](/docs/workflows/overview.md)
56

67
<hr style="margin: 1em 5em 1em 1em; opacity: 0.1;">

docs/environment.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Environment
2+
3+
To reduce repetition and simplify usage, the CLI provides flexible ways to define your commonly used `iTwin` and `iModel` IDs. Once set, you can run commands without manually passing these IDs every time.
4+
5+
The CLI supports two mechanisms for this:
6+
7+
1. **Environment variables** — set manually in your terminal or CI environment
8+
2. **Local context** — managed via the `itp context` command
9+
10+
Either approach can help streamline your workflow.
11+
12+
---
13+
14+
### Setting environment variables
15+
16+
You can define your default IDs directly in the terminal environment:
17+
18+
```bash
19+
// For macOS, Linux, WSL, Git Bash
20+
export ITP_ITWIN_ID=b1a2c3d4-5678-90ab-cdef-1234567890ab
21+
export ITP_IMODEL_ID=ad0ba809-9241-48ad-9eb0-c8038c1a1d51
22+
```
23+
24+
```powershell
25+
// For PowerShell (Windows)
26+
$env:ITP_ITWIN_ID = "b1a2c3d4-5678-90ab-cdef-1234567890ab"
27+
$env:ITP_IMODEL_ID = "ad0ba809-9241-48ad-9eb0-c8038c1a1d51"
28+
```
29+
30+
These values will be automatically picked up in commands unless overridden by context or flags.
31+
32+
---
33+
34+
### Using the `context` system
35+
36+
The `itp context` command allows you to **save default iTwin and iModel IDs locally**. Once set, these values will persist across CLI sessions and be automatically used in commands.
37+
38+
- Set context:
39+
40+
```bash
41+
itp context set --itwin-id <iTwinId> --imodel-id <iModelId>
42+
```
43+
44+
- View current context:
45+
46+
```bash
47+
itp context info
48+
```
49+
50+
- Clear context:
51+
52+
```bash
53+
itp context clear
54+
```
55+
56+
> ℹ️ Context values take precedence over environment variables.
57+
58+
---
59+
60+
### Using the `--save` flag
61+
62+
You can also update the context automatically during iTwin or iModel creation by using the `--save` flag. This stores the newly created ID into the local context, making it available for subsequent commands.
63+
64+
- Save iTwin to context:
65+
66+
```bash
67+
itp itwin create --class Thing --sub-class Asset --name "Example iTwin" --save
68+
```
69+
70+
- Save iModel to context:
71+
72+
```bash
73+
itp imodel create --name "Example iModel" --save
74+
```
75+
76+
---
77+
78+
### Resolution Order
79+
80+
When determining which `iTwin ID` or `iModel ID` to use, the CLI resolves values in the following order:
81+
82+
1. **Explicit flags passed in the command**
83+
2. **Values saved in `itp context`**
84+
3. **Environment variables (`ITP_ITWIN_ID`, `ITP_IMODEL_ID`)**
85+
4. **If none are provided → error**
86+
87+
---
88+
89+
### Examples
90+
91+
**Without environment or context**
92+
93+
```bash
94+
itp itwin info --itwin-id b1a2c3d4-5678-90ab-cdef-1234567890ab
95+
96+
itp imodel populate --imodel-id b1a2c3d4-5678-90ab-cdef-1234567890ab --file file.dwg --connector-type DWG
97+
98+
itp imodel named-version create --imodel-id ad0ba809-9241-48ad-9eb0-c8038c1a1d51 --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5 --name "Version 1.0" --description "Initial release"
99+
```
100+
101+
**With environment variables or context**
102+
103+
```bash
104+
# Assuming context or env variables are already set
105+
itp itwin info
106+
107+
itp imodel populate --file file.dwg --connector-type DWG
108+
109+
itp imodel named-version create --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5 --name "Version 1.0" --description "Initial design"
110+
```
111+
112+
---
113+
114+
### Summary
115+
116+
- Passing `--itwin-id` or `--imodel-id` directly in a command will always override other sources.
117+
- Values set via `itp context` are stored locally and persist across sessions.
118+
- Environment variables (`ITP_ITWIN_ID`, `ITP_IMODEL_ID`) are ideal for scripting and temporary sessions.
119+
- If no IDs are received from any method, the CLI will return a **missing option** error.

docs/itwin101.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# iTwin 101
22

3-
**A developer-friendly introduction to Bentley's iTwin Platform.**
3+
**A friendly introduction to Bentley's iTwin Platform.**
44

55
The infrastructure industry has undergone a major shift — from static design files to **cloud-connected systems** that reflect how assets behave in real time.
66

7-
This shift is driven by the rise of **digital twins**: living models that combine infrastructure design with data from numerous cloud sources for a complete view of the asset. For example, a dam reporting structural health and energy output, or a smart building tracking occupancy, lighting, and air quality. It’s no longer just about designing — it’s about how an asset lives and performs in the real world.
7+
This shift is driven by the rise of **digital twins**: living models that combine infrastructure data to numerous cloud sources for a complete view of the asset. For example, a dam reporting structural health and energy output, or a smart building tracking occupancy, lighting, and air quality. It’s no longer just about designing infrastructure — it’s about how an asset lives and performs in the real world.
88

9-
**Bentley Systems**, a long-standing leader in infrastructure software, created the **iTwin Platform** to support this evolution. While desktop tools like **MicroStation** and **AutoCAD** have supported infrastructure design for decades, the iTwin Platform brings this data into the cloud — where teams can visualize entire assets, integrate live data, and build connected solutions across industries.
9+
**Bentley Systems**, a long-standing leader in infrastructure software, created the **iTwin Platform** to support this evolution. While desktop tools like **MicroStation** and **AutoCAD** have supported infrastructure design for decades, the iTwin Platform brings infrastructure data into the cloud — where teams can visualize entire assets, integrate live data, and build connected solutions across industries.
1010

11-
Following Bentley’s acquisition of **Cesium**, high-performance 3D geospatial visualization is now a built-in part of the iTwin ecosystem. **Cesium** is an open platform for streaming large-scale 3D data, and its developer sandbox, **Sandcastle**, makes it easy to prototype and interact with infrastructure in a global context.
11+
Following Bentley’s acquisition of **Cesium**, high-performance 3D geo-spatial visualization is now a built-in part of the iTwin ecosystem. **Cesium** is an open platform for streaming large-scale 3D data, and its developer sandbox, **Sandcastle**, makes it easy to prototype and interact with infrastructure in a global context.
1212

1313
The **iTwin CLI** ties it all together — letting you manage iTwins, bring design data into the cloud, and visualize your models in Cesium Sandcastle — all from the command line.
1414

@@ -23,13 +23,13 @@ A **digital twin** is more than a design model. It’s a cloud-based, real-time
2323
- **📈 Sensor Data**: Live IoT data reflecting asset performance, environmental conditions, and more.
2424
- **📂 External Repositories**: Additional cloud data sources that enrich the digital twin's context.
2525

26-
What makes a digital twin powerful is the way these sources come together in the cloud to form a "living" version of an assetsomething that's not just visual, but interactive and analyzable.
26+
What makes a digital twin powerful is the way these sources come together in the cloud to form a "living" version of an assetsomething that's not just visual, but interactive and analyzable.
2727

2828
---
2929

3030
### 🪧 Enter the iTwin
3131

32-
The **iTwin** is Bentley’s implementation of a digital twina central hub that brings together all the data related to an infrastructure asset. It's built to be open, extensible, and deeply interoperable.
32+
The **iTwin** is Bentley’s implementation of a digital twina central hub that brings together all the data related to an infrastructure asset into the cloud. It's built to be open, extensible, and deeply interoperable.
3333

3434
At its core, an iTwin includes several key components:
3535

@@ -40,11 +40,11 @@ An **iModel** is a specialized cloud repository for 3D design data. It acts as a
4040
> Have a Revit file for a building? Add it to the iModel.
4141
> Got utility designs from MicroStation? Add them too.
4242
43-
The iModel isn’t just a storage formatit acts like **Git for infrastructure**. Designers "synchronize" their changes, which are stored as **changesets**. This allows for collaborative workflows, version tracking, and comparison of changes between versions.
43+
The iModel isn’t just a storage formatit acts like **Git for infrastructure**. Designers commit - or in design words - **synchronize** their changes, which are stored as **changesets**. This allows for collaborative workflows, version tracking, and comparison of changes between versions.
4444

4545
#### 🌎 Reality Data: Contextual Visualization
4646

47-
Drones, scanners, and photogrammetry can capture detailed environmental data around your asset. This is imported into the iTwin to create photorealistic context and increase the accuracy of both design and decision-making.
47+
Drones, scanners, and photogrammetry can capture detailed environmental data around your asset. This is imported into the iTwin to create photorealistic context and increase the accuracy of asset visualization and project decision-making.
4848

4949
#### 📊 Sensor Data: Real-Time Awareness
5050

@@ -127,7 +127,7 @@ Design data becomes globally interactive. Combined with reality meshes and IoT d
127127

128128
The iTwin CLI makes it easy to build, manage, and explore digital twins using the iTwin Platform. For anyone interested in geospatial technology and digital twin workflows, it opens a new path to work with infrastructure data at scale, integrate diverse data sources, and publish them to a geospatially rich, interactive viewer.
129129

130-
Whether you’re just exploring or already building, the iTwin CLI is your entry point into a next-generation platform for digital infrastructure.
130+
Whether you’re just exploring or already building, the iTwin CLI is your entry point into the next-generation platform for the infrastructure digital twin.
131131

132132
---
133133

0 commit comments

Comments
 (0)