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

I want to merge two models into one, but keep reporting the error "attempt to clone with unknown class" #6332

Closed
wwr1982 opened this issue Jan 1, 2024 · 6 comments

Comments

@wwr1982
Copy link

wwr1982 commented Jan 1, 2024

My code is as follows:

Logger.initializeToConsole();
Logger.setLevelDefault(LogLevel.Trace);
Logger.setLevel("imodel-transformer", LogLevel.Trace);
let sourceDb: IModelDb;
let sourceDb2: IModelDb;
let targetDb: IModelDb;
const sourceFile ="C:\Users\wwr\Downloads\aa\aa.bim";
const sourceFile2 ="C:\Users\wwr\Downloads\bb\bb.bim";
const targetFile ="C:\Users\wwr\Downloads\c\c.bim";
sourceDb = SnapshotDb.openFile(sourceFile);
sourceDb2 = SnapshotDb.openFile(sourceFile2);
if (IModelJsFs.existsSync(targetFile)) {
  IModelJsFs.removeSync(targetFile);
}
targetDb = StandaloneDb.createEmpty(targetFile, { // use StandaloneDb instead of SnapshotDb to enable processChanges testing
  rootSubject: { name: ${sourceDb.rootSubject.name}-Transformed },
  ecefLocation: sourceDb.ecefLocation,
});
const transformerOptions: TransformerOptions = {
  simplifyElementGeometry:true,
  noProvenance:true,
};
try{
  await Transformer.transformAll(sourceDb, targetDb, transformerOptions);
  await Transformer.transformAll(sourceDb2, targetDb, transformerOptions);
  sourceDb.close();
  targetDb.close();
  return "test";
}
catch(error:any)
{
  console.log(${error.message}\n${error.stack});
}
return "OK";

My files to be merged are:
bimfile.zip

Thank you!

@ben-polinsky
Copy link
Contributor

@MichaelBelousov

@MichaelBelousov
Copy link
Contributor

MichaelBelousov commented Jan 2, 2024

@wwr1982 Transformer.transformAll is from the test-app, which is a testing tool. I recommend using the transformer library directly unless you are trying to hack the test-app for a basic CLI.

So you should be using IModelTransformer.processAll (the library equivalent of transformAll) and IModelTransformer.processSchemas.

But technically transformAll does this, so I will investigate

@MichaelBelousov
Copy link
Contributor

also next time please include a complete reproduction so it's less work on the maintainers to piece together your code into something that we can (safely) run and will accurately depict your issue.

My version

const { Logger, LogLevel } = require("@itwin/core-bentley");
const { SnapshotDb, IModelHost, StandaloneDb, IModelJsFs } = require("@itwin/core-backend");
const { Transformer } = require("@itwin/imodel-transformer");
const path = require("node:path");

async function main() {
IModelHost.startup();

Logger.initializeToConsole();
Logger.setLevelDefault(LogLevel.Trace);
Logger.setLevel("imodel-transformer", LogLevel.Trace);

/** @type{IModelDb} /
let sourceDb;
/
* @type{IModelDb} /
let sourceDb2;
/
* @type{IModelDb} */
let targetDb;

const sourceFile = path.join(__dirname, "./aa.bim")
const sourceFile2 = path.join(__dirname, "./bb.bim")
const targetFile = path.join(__dirname, "./c.bim")

sourceDb = SnapshotDb.openFile(sourceFile);
sourceDb2 = SnapshotDb.openFile(sourceFile2);

if (IModelJsFs.existsSync(targetFile)) {
IModelJsFs.removeSync(targetFile);
}

// use StandaloneDb instead of SnapshotDb to enable processChanges testing
targetDb = StandaloneDb.createEmpty(targetFile, {
rootSubject: { name: ${sourceDb.rootSubject.name}-Transformed },
ecefLocation: sourceDb.ecefLocation,
});

/** @type{TransformerOptions} */
const transformerOptions = {
simplifyElementGeometry: true,
noProvenance: true,
};

try {
await Transformer.transformAll(sourceDb, targetDb, transformerOptions);
await Transformer.transformAll(sourceDb2, targetDb, transformerOptions);
sourceDb.close();
targetDb.close();
return "test";
} catch(error) {
console.log(${error.message}\n${error.stack});
}

return "OK";
}

void main()

@MichaelBelousov
Copy link
Contributor

MichaelBelousov commented Jan 2, 2024

this occurs because your input files have the same version of a dynamic schema (RevitDynamic), but bb.bim contains classes in that dynamic schema which aa.bim does not. I will investigate this further.

@wwr1982
Copy link
Author

wwr1982 commented Jan 3, 2024

Thank you.

@MichaelBelousov
Copy link
Contributor

In order to merge iModels with dynamic schemas using the transformer, you must manually merge the dynamic schemas, import the new merged one (it can be an update of one of the two), and remap all elements from the other schema into it.

We are working on additional automation of this process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants