Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
中国BDN社区
  • Welcome to Bentley Communities
  • Bentley's Communities
  • 中国BDN社区
  • Cancel
中国BDN社区
中国BDN社区-威客 关于如何导入与导出imodel中schema文件
    • Sign In
    • 中国BDN社区-威客
    • -iTwin.js编程
      • iModel.js Front-End简介
      • iModel.js 样例项目配置与运行
      • iModel.js.UI开发基本介绍
      • iModel.js前端统一选择一致性机制
      • iModel.js基本查询
      • iModel.js若干前端功能开发样例
      • imodel图形显示简单介绍
      • iModel文件的合并等操作
      • Redux基本使用
      • simple-viewer-app源码简单分析
      • TypeScript基本介绍及环境配置
      • 下载视口截图
      • 关于imodel测量单位的转换
      • 关于如何导入与导出imodel中schema文件
      • 基于PresentationRules个性化显示iModel的内容
      • 如何在视窗内添加自定义装饰
      • 如何将2个bim中的图形模型显示在一个视图中
      • 用户选择保存感兴趣的视图
    • +MicroStation CONNECT版SDK的新变化
    • +MicroStation编程技巧
    • +OpenRoads中国版平台开发指南
    • +ORD SDK二次开发编程
    • +一步步学习ABD-CE开发
    • +一步步学习MicroStation CE Addin开发
    • 一步步学习MicroStation CE MDL开发
    • +一步步学习ProjectWise编程
    • 中国优先社区二次开发精华帖汇总
    • +学习Microstation交互式工具开发
    • +过期帖,留存仅供参考
    • +非Bentley社区分享的文章
    • C#、C/C++相关的编程知识汇总

     
     Questions about this article, topic, or product? Click here. 

    关于如何导入与导出imodel中schema文件

    关于如何导入与导出imodel中schema文件

    我们使用imodel.js后端代码可以将schema文件导入到imodel中,也可以将imodel中的schema文件导出到指定的路径。

    需要首先打开一个imodel文件,然后进行相关schema导入/导出操作(如果是导入需要以可写模式打开),最后关闭imodel文件。

    导入schema示例代码如下:

      public async ImportSchema(schemaFilePath: string) {
        if (this._imodel == undefined) {
          return;
        }
        //导入Schema.
    
        let imodel = this._imodel;
        imodel.importSchemas(this.requestContext, [schemaFilePath]);
      }

    导出schema示例代码如下:

      public async ExportEchema(savedSchemaPath: string) {
        if (this._imodel === undefined) {
          return;
        }
        if (
          DbResult.BE_SQLITE_OK ===
          this._imodel.nativeDb.exportSchemas(savedSchemaPath)
        ) {
          console.log("schema导出成功");
        } else {
          console.log("schema导出失败");
        }
      }

    整个应用代码如下所示:

    import { BackendRequestContext, SnapshotDb } from "@bentley/imodeljs-backend";
    import { DbResult } from "@bentley/bentleyjs-core";
    
    class ImportAndExportSchema {
      public constructor() {}
      public async CreateIModelFromSeed(
        seedFileName: string,
        MyiModelFileName: string
      ) {
        const seedDb: SnapshotDb = SnapshotDb.openFile(seedFileName);
        this._imodel = SnapshotDb.createFrom(seedDb, MyiModelFileName);
        if (this._imodel) {
          console.log("imodel创建成功");
        } else {
          console.log("imodel创建失败");
        }
        seedDb.close();
      }
      public async ImportSchema(schemaFilePath: string) {
        if (this._imodel == undefined) {
          return;
        }
        //导入Schema.
    
        let imodel = this._imodel;
        imodel.importSchemas(this.requestContext, [schemaFilePath]);
      }
      public async ExportEchema(savedSchemaPath: string) {
        if (this._imodel === undefined) {
          return;
        }
        if (
          DbResult.BE_SQLITE_OK ===
          this._imodel.nativeDb.exportSchemas(savedSchemaPath)
        ) {
          console.log("schema导出成功");
        } else {
          console.log("schema导出失败");
        }
      }
      public async dispose() {
        if (this._imodel != undefined) {
          this._imodel.close();
        }
      }
      public InspectSchema(schemaName: string) {
        if (this._imodel === undefined) {
          return;
        }
        const versinon = this._imodel.querySchemaVersion(schemaName);
        if (versinon) {
          console.log("版本=" + versinon);
        }
      }
      private requestContext = new BackendRequestContext();
      private _imodel: SnapshotDb | undefined;
    }
    
    export async function ImportAndExportSchema_Handle() {
      const seedFileName = "./data/Baytown.bim";
      const testFileName = "./data/TestBaytown.bim";
      const example = new ImportAndExportSchema();
      example.CreateIModelFromSeed(seedFileName, testFileName);
      const schemaPath = "./data/RobotWorld.ecschema.xml";
      await example.ImportSchema(schemaPath);
      example.InspectSchema("RobotWorld");
      const SaveSchemaFilePath = "D:/schema/";
      await example.ExportEchema(SaveSchemaFilePath);
      example.dispose();
    }
    

    导出结果:

    • Share
    • History
    • More
    • Cancel
    • Devin Liu Created by Devin Liu
    • When: Thu, Sep 10 2020 4:42 AM
    • Devin Liu Last revision by Devin Liu
    • When: Thu, Sep 10 2020 4:45 AM
    • Revisions: 2
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies