Skip to content
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

Failed to merge imodels using transformer related methods #159

Open
MYDJH opened this issue Feb 28, 2024 · 1 comment
Open

Failed to merge imodels using transformer related methods #159

MYDJH opened this issue Feb 28, 2024 · 1 comment
Labels
question Further information is requested

Comments

@MYDJH
Copy link

MYDJH commented Feb 28, 2024

"I encountered some issues while using the transformer to merge two iModels. When executing the method, I encountered error messages. I tried several approaches to merge, but all of them failed."

Attempting solutions 1:

async count(iModelDb: IModelDb, classFullName: string): Promise<number> {
    return iModelDb.withPreparedStatement(
      `SELECT COUNT(*) FROM ${classFullName}`,
      (statement: ECSqlStatement): number => {
        return DbResult.BE_SQLITE_ROW === statement.step()
          ? statement.getValue(0).getInteger()
          : 0;
      }
    );
  }
  async mergeFrist(req: any, res: any): Promise<string> {
    IModelHost.startup();
    const SourceFileName1 = "C:\\Users\\wwr\\Downloads\\a\\a.bim";
    const sourceFileName2 = "C:\\Users\\wwr\\Downloads\\b\\b.bim";
    const targetFile = "C:\\Users\\wwr\\Downloads\\c\\c.bim";

    const SrouceModel1 = SnapshotDb.openFile(SourceFileName1);
    const SrouceModel2 = SnapshotDb.openFile(sourceFileName2);

    const num1 = await this.count(SrouceModel1, "BisCore.Element"); 
    const num2 = await this.count(SrouceModel2, "BisCore.Element"); 
    console.log("num1 = " + num1.toString()); //Output 1194
    console.log("num2 = " + num2.toString()); //Output 11943
    if (IModelJsFs.existsSync(targetFile)) {
      IModelJsFs.removeSync(targetFile);
    }
    const targetDbProps: CreateIModelProps = {
      rootSubject: { name: "Clone-Target" },
      ecefLocation: SrouceModel1.ecefLocation,
    };
    // Create a blank Imodel
    const targetDb = SnapshotDb.createEmpty(targetFile, targetDbProps);
    const transformer = new IModelTransformer(SrouceModel1,targetDb);
    await transformer.processSchemas();//Error Message:Error importing schema
    await transformer.processAll();//Error Message:attempt to clone with unknown class
    targetDb.saveChanges();

    const num4 = await this.count(targetDb, "BisCore.Element");

    SrouceModel1.close();
    targetDb.close();
    SrouceModel2.close();

    IModelHost.shutdown();
    return "Frist";
  }

Error Message:Error importing schema;
Error Message:attempt to clone with unknown class;

Attempting solutions 2:

  async mergeSecond(req: any, res: any): Promise<string> {
    IModelHost.startup();
    const SourceFileName1 = "C:\\Users\\wwr\\Downloads\\a\\a.bim";
    const sourceFileName2 = "C:\\Users\\wwr\\Downloads\\b\\b.bim";
    const SrouceModel1 = SnapshotDb.openFile(SourceFileName1);
    const SrouceModel2 = SnapshotDb.openFile(sourceFileName2);
    const num1 = await this.count(SrouceModel1, "BisCore.Element"); //1194
    const num2 = await this.count(SrouceModel2, "BisCore.Element"); //11943
    const targetFileName = "C:\\Users\\wwr\\Downloads\\c\\c.bim";
    if (IModelJsFs.existsSync(targetFileName)) {
      IModelJsFs.removeSync(targetFileName);
    }
    const targetDbProps: CreateIModelProps = {
      rootSubject: { name: "Clone-Target" },
      ecefLocation: SrouceModel1.ecefLocation,
    };
    
    // Create a readable and writable file using a seed
    let TargetIModel1 = SnapshotDb.createFrom(SrouceModel1, targetFileName);
    const parentSubject = TargetIModel1.elements.getRootSubject().id;
    const subjectId1 = Subject.insert(TargetIModel1, parentSubject, "subject1");
    const subjectId2 = Subject.insert(TargetIModel1, parentSubject, "subject2");

    if (TargetIModel1.isReadonly) {
      console.log("readable");
    } else {
      console.log("readable and writable");
    }
    const transformer = new IModelTransformer(SrouceModel2,TargetIModel1,{
      targetScopeElementId: subjectId1,
    });
    await transformer.processSchemas();
    await transformer.processAll();//Error Error: attempt to clone with unknown class
    TargetIModel1.saveChanges();
    const num4 = await this.count(TargetIModel1, "BisCore.Element");
    SrouceModel1.close();
    SrouceModel2.close();
    TargetIModel1.close();
    return "Second";
  }
}

The actual error location is reported when executing the transformer. processAll() method

  public async processAll(): Promise<void> {
    Logger.logTrace(loggerCategory, "processAll()");
    this.logSettings();
    this.validateScopeProvenance();
    await this.initialize();
    await this.exporter.exportCodeSpecs();
    await this.exporter.exportFonts();
    await this.exporter.exportChildElements(IModel.rootSubjectId); Subject
    await this.exporter.exportModelContents(IModel.repositoryModelId, Element.classFullName, true);
    await this.exporter.exportSubModels(IModel.repositoryModelId); //Actual Error Position
    await this.exporter["exportAllAspects"](); 
    await this.exporter.exportRelationships(ElementRefersToElements.classFullName);
    await this.processDeferredElements();
    if (this.shouldDetectDeletes()) {
      await this.detectElementDeletes();
      await this.detectRelationshipDeletes();
    }

    if (this._options.optimizeGeometry)
      this.importer.optimizeGeometry(this._options.optimizeGeometry);

    this.importer.computeProjectExtents();
    this.finalizeTransformation();
  }

Error Message:Error Error: attempt to clone with unknown class

"I hope you can help me analyze whether the issue lies in my code or the environment, or if you have a better implementation plan. Thank you."
The file I want to merge is.
mergeFile.zip

@nick4598
Copy link
Collaborator

Hello, are you still experiencing this issue?

@nick4598 nick4598 added the question Further information is requested label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants