Hi everybody,
We had developed for MicroStation V8i an application who works with MicroStation with no graphic interface. This application is designed to read a large quantity of dgn file to produce a unique dgn file containing a selection of some elements from the source files.So we need to open in external mode the source file and create new elements in the destination file.We have migrated this application on Connect Platform. Our problem with Microstation Connect is that we have an exception while creating a new element.
Below an example which crashes on the line mdlShape_create(...):
extern "C" DLLEXPORT void MdlMain( int argc, /* => Number of arguments passed in pargv */ WCharCP argv[]) /* => Array of pointers to arguments */ { BeFileName repAppli; for (int i = 0; i < argc; ++i) { if (i == 0) repAppli.assign(argv[i]); } mdlSystem_enterGraphicsExtended(1); BeFileName dgnWorkFile; BeFileName seedFile; seedFile.BuildName(NULL, BeFileName::GetDirectoryName(repAppli).GetWCharCP(), L"vide", L"dgn"); if (BeFileName::DoesPathExist(seedFile) == true) { dgnWorkFile.BuildName(NULL, BeFileName::GetDirectoryName(repAppli).GetWCharCP(), L"test", L"dgn"); BeFileName::BeCopyFile(seedFile, dgnWorkFile); } DgnModelRefP modelRefDepart = MODEL_REF_NULL; if (mdlWorkDgn_openFile(&modelRefDepart, NULL, NULL, dgnWorkFile, NULL, FALSE) == SUCCESS) { DPoint3d tabPoint[MAX_VERTICES]; tabPoint[0].x = tabPoint[0].y = tabPoint[0].z = 0.0; tabPoint[1].x = 0.0; tabPoint[1].y = 1000.0; tabPoint[1].z = 0.0; tabPoint[2].x = 1000.0; tabPoint[2].y = 1000.0; tabPoint[2].z = 0.0; tabPoint[3].x = 1000.0; tabPoint[3].y = 0.0; tabPoint[3].z = 0.0; tabPoint[4] = tabPoint[0]; MSElement Elm; mdlShape_create(&Elm, NULL, tabPoint, 5, 0); mdlElement_add(&Elm); mdlWorkDgn_closeFile(modelRefDepart); } }
Can you help me?Is there any other solution for our need?
Regards,
Hervé
Hi Hervé,
I assume all necessary things like app is configured to be MS_INITAPP application, there is a file that is opened etc. are set and done?
I do not understand why you enter graphics mode, but after that, you use work file to access DGN file.
MicroStation CE API offers better way than mdlWork_dgn, see DgnFile struct reference.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thanks Jan,
I've done what you suggest me but the exception is still at the same moment.In fact, the problem is always when you try to create an element when there is no active file.You can easily create elements in external files but only if there is an active file.It was not working like this in V8i...
hervecuzon said:In fact, the problem is always when you try to create an element when there is no active file.
I am not surprised, because typically any INITAPP starts with opening some DGN. But I do not recall any discussion whether it is mandatory requirement. I can imagine without opening the file, MicroStation is not initialized completely (e.g. because of tight dependency on selected workspace/workset, that did not exist in V8i).
Maybe Jon Summers has some experience, as he wrote good article about INITAPP in CE.
hervecuzon said:You can easily create elements in external files but only if there is an active file.
And does it cause any problem? There can be "empty operation file" available (especially when MicroStation works at background, with no GUI initialized), or alternatively, such file can be created ad hoc from any seed file in temp folder.
Please refer below thread(sorry it is in Chinese, but code can easily read).
[MSCE C++ U6]如何打开一个dgn文件并向其添加元素?
Yongan.Fu said:Please refer below thread
The message seems to be to create a DgnFile and load its default model rather than to use the mdlWorkDgn API.
DgnFile
mdlWorkDgn
Is the mdlWorkDgn API deprecated? The header file mswrkdgn.fdf has no comment.
mswrkdgn.fdf
Regards, Jon Summers LA Solutions
Jon, In all the application we have, mdlWorkDgn API continue to work fine!Anyway, as i said below, the problem is the "mdlShape_create(...);"It crashes even if I have open a dgn file in external mode or not
hervecuzon said: I said below, the problem is the mdlShape_create(...)
mdlShape_create(...)
Element creating is depending on the resources available in the DGN model.
It's possible that using a DgnFile as a work file makes necessary resources available where mdlWorkDgn omits some vital step. I have come across several instances, when programming for CONNECT, where a legacy MDL function fails but its 21st century class replacement works fine.
In other words, even though your code is tried-and-tested in V8i, it depends on something that mdlWorkDgn in CONNECT does not implement 100%. Of course, I'm speculating, but Yongan.Fu's example provides working code.