-
Notifications
You must be signed in to change notification settings - Fork 2
Add transformation sheet sample #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
131f3f8
ddc71cc
f399322
0c90340
45007e1
fe61558
66cd244
6d6b053
3bb7ca5
6c502ac
c9390eb
451bb7f
a66b703
c1bfc3e
74c6505
61140c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,156 @@ | ||||||
| # Example Transformation for sheets | ||||||
|
|
||||||
| ## Overview | ||||||
|
|
||||||
| This example shows how to transform a sheet and all its content into a target iModel using the `SheetTransformer` classes. The goal of this transformation was to copy a 2d sheet and its contents from a bim file to another iModel using the `@itwin/imodel-transformer` client. | ||||||
|
|
||||||
| ## Example Code | ||||||
|
|
||||||
| ```typescript | ||||||
|
|
||||||
| import { | ||||||
| Element, | ||||||
| IModelDb, | ||||||
| Sheet, | ||||||
| SheetModel, | ||||||
| SnapshotDb, | ||||||
| } from "@itwin/core-backend"; | ||||||
| import { DbResult, Guid, Id64String } from "@itwin/core-bentley"; | ||||||
| import { | ||||||
| Code, | ||||||
| ElementProps, | ||||||
| GeometricModel2dProps, | ||||||
| IModel, | ||||||
| RelatedElement, | ||||||
| SheetProps, | ||||||
| } from "@itwin/core-common"; | ||||||
| import { | ||||||
| IModelImporter, | ||||||
| IModelTransformer, | ||||||
| } from "@itwin/imodel-transformer"; | ||||||
|
|
||||||
| import { CreateSheetProps, SHEET_CONSTANTS } from "../../common/SheetCommandIpc"; | ||||||
| import { logError } from "../util/ErrorUtility"; | ||||||
| import { DPChannelApi } from "./DPChannelApi"; | ||||||
|
|
||||||
| export namespace SheetApi { | ||||||
|
|
||||||
| export const insertSheet = async (sheetName: string, createSheetProps: CreateSheetProps): Promise<Id64String> => { | ||||||
| const iModel: IModelDb | undefined = StudioHost.getActiveBriefcase(); | ||||||
| let seedDb: SnapshotDb | undefined; | ||||||
| let transformer: IModelTransformer | undefined; | ||||||
| try { | ||||||
| if (!iModel) { | ||||||
| throw new Error("iModelDb undefined"); | ||||||
| } | ||||||
| if (!sheetName) { | ||||||
| throw new Error("A sheet must be named."); | ||||||
| } | ||||||
|
|
||||||
| // create a blank sheetModelId(where we will insert the sheet data), create documentListModel (where we will insert list of document elements) | ||||||
|
||||||
| const [sheetModelId, documentListModelId] = await createSheetInternal(createSheetProps, iModel, sheetName); | ||||||
derbynn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| const seedFileName = | ||||||
| "D:\\testmodels\\transformingSheetsIssue\\source.bim"; | ||||||
| seedDb = SnapshotDb.openFile(seedFileName); | ||||||
| if (!seedDb) { | ||||||
| throw new Error("Failed to open snapshot iModel."); | ||||||
| } | ||||||
|
|
||||||
| // Get the sheet data from the snapshot (this will contain the sheet data) | ||||||
derbynn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| const arr: any = []; | ||||||
| const query = "SELECT * FROM BisCore.Sheet"; | ||||||
| seedDb.withPreparedStatement(query, (statement) => { | ||||||
| while (statement.step() === DbResult.BE_SQLITE_ROW) { | ||||||
| const row = statement.getRow(); | ||||||
| arr.push(row); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| const importer = new IModelImporter(iModel); | ||||||
| importer.doNotUpdateElementIds.add(documentListModelId); // Do not update the documentListModelId, this is the one we've created for this iModel to receive the sheet template. | ||||||
|
||||||
| importer.doNotUpdateElementIds.add(documentListModelId); // Do not update the documentListModelId, this is the one we've created for this iModel to receive the sheet template. | |
| importer.doNotUpdateElementIds.add(documentListModelId); // Do not update the documentListModelId, this is the one we've created for this iModel to receive the sheet template. We do this in order to keep the properties of the documentListModel that we set in `createSheetInternal`. Without this line the documentListModel's properties in the source iModel overwrite the target iModel's documentListModel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you format this? It might need to be on two lines if its too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Uh oh!
There was an error while loading. Please reload this page.