Hello all.
We are trying to import the contents of a Dxf file into a Dgn file.Our DXF file as 10000 UOR per master unit, but the DGN file as 1000 UOR per master.
Here is the source code:
void copyContentIntoAnotherFile(DgnModelRefP fromFile, DgnModelRefP destFile) const { if (fromFile == MODEL_REF_NULL || destFile == MODEL_REF_NULL) return; auto fromFileModelP = fromFile->GetDgnModelP(); for (PersistentElementRefP const& elemRef : fromFileModelP->GetElementsCollection()) { auto elemHandle = Bentley::DgnPlatform::ElementHandle(elemRef, elemRef->GetDgnModelP()); if (elemRef->IsGraphics()) { EditElementHandle eeh{ fromFile }; DgnPlatform::ElementCopyContext copyContext(destFile); copyContext.SetSourceModelRef(fromFile); copyContext.SetLevelHandling(Bentley::DgnPlatform::CopyContextLevelOption::CopyAlways); copyContext.SetTransformToDestination(true); // does not change anything copyContext.SetWriteElements(true); // copyContext.SetDestinationModelRef(destFile); // does not change anything either if (SUCCESS != copyContext.DoCopy(eeh)) printf("errno : %d", mdlErrno); } } } […] if (mdlWorkDgn_openFile (&dgnModelRef, NULL, NULL, beDgnPathName, NULL, false) == SUCCESS) { DgnAttachmentP const dxfModel = importFileAsReference(dxfPathName); copyContentIntoAnotherFile(dxfModel, dgnModelRef); mdlWorkDgn_saveChanges(dgnModelRef); Alm::Basic::WorkDgn_closeFile(dgnModelRef); } […]
The Dxf file has units ten times too large, which is why we have applied SetTransformToDestination(true); so that the import is done at the correct scale. However, this does not change anything, the imported content still appears too large. The same is true if we import the DXF file by reference into the active file rather than importing its graphical elements one at a time.
How could we successfully import this Dxf file with the correct coordinates please?
Thank you in advance for your answer,
Hervé
Herve Cuzon said:We are trying to import the contents of a Dxf file into a Dgn file
What are you attempting that MicroStation can't already do?
Herve Cuzon said:How could we successfully import this DXF file?
MicroStation can open a DWG or DXF file.
Regards, Jon Summers LA Solutions
Jon,
We want to automatize an action which can be done manually. We have a service, in France, where you can download the dxf file for a given town. The purpose of the feature is to have an interface where you key-in the name of the town and our application download automatically the dxf file of the specified town on the server. And then, we import this DXF in the DGN file eventually with a resymbolisation (which can be customizable) of the elements depending on the level name of the elements readen in the DXF.
Is this clearer for our needs?
Herve Cuzon said:Is this clearer for our needs?
Yes: good explanation.
Herve Cuzon said:we import this DXF in the DGN file eventually with a resymbolisation
Again, what do you want that is not possible with MicroStation File|Open? If you search the MicroStation Forum for something like open dwg level remap you may see some answers.
Herve Cuzon said:The Dxf file has units ten times too large
One step at a time. If you open the DXF file with MicroStation File|Open, can you obtain the correct units in the DGN file? If not, can you change the import options for a good result?
Yes if you put the DXF file in reference and then merge the DXF in the active DGN file, all the coordinates are ok
Hi Hervé,
I used CopyContext long time ago, but I do not see anything obviously wrong in your code.
I think it's not important for the discussion, but I guess CopyContext can be created once only (because it describes all necessary transformations from source to destination), before iterating elements, and not individually for every element? But it's probably more performance question, not functionality issue.
What I am not sure I understand right is "what file is what" ;-) What is source and what destination, in a meaning active and reference. Or the files (both or one only) are opened at background?
I see WorkDgn is used there. Why you do not use C++ DgnFile object instead of it?
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point