Hi guys.
In my logic, I should generate and attach a lot of little POD files to the MicroStation DGN document. For example, it can be about 100 files (each file has 10000 points and 400 Kb of disk space). One file can be generated and attached in 52-57 milliseconds, it's very fast. But 100 files take about 5 seconds in total. And when I generate and attach these files in a simple loop - MicroStation UI just freeze for these 5 seconds and I see the total result of attaching all files in the end.
But I need some "streaming" analog. Each file should be generated and attached some parallel. It shouldn't freeze the UI. And the user should see how points appear in the graphic area dynamically, in portions.
How can I do it? Is the MicroStation and Point Cloud Writer support multi-thread and parallel work?
Here is my code of how I create and attach 1 single POD:
ISessionMgrR sessionMgr = ISessionMgr::GetManager(); DgnModelRefR model = *sessionMgr.GetActiveDgnModelRefP(); Bentley::PointCloud::PointCloudPodWriter pointCloudWriter; StatusInt status = pointCloudWriter.Initialize(); Bentley::WString PodFilePath(filePath); // filePath - full path to POD file from method parameter status = pointCloudWriter.StartStream(PodFilePath.c_str()); status = pointCloudWriter.AddGroup(Bentley::PointCloud::PointCloudPodWriter::Group_Combine, L"Group"); status = pointCloudWriter.AddCloud(Bentley::PointCloud::PointCloudPodWriter::Cloud_RGB, L"Cloud", NULL, 0, 0); // some loop where we add points with next method: for (...) { UChar ch = 0; pointCloudWriter.AddPoint(point3d, &rbg, 1000, NULL, ch); } status = pointCloudWriter.EndStream(); status = pointCloudWriter.BuildPod(); if (status == 0) // SUCESS { Bentley::DgnDocumentMonikerPtr moniker = Bentley::DgnPlatform::DgnDocumentMoniker::CreateFromFileName(PodFilePath.c_str()); Bentley::DgnPlatform::PointCloudPropertiesPtr properties = Bentley::DgnPlatform::PointCloudProperties::Create(*moniker, model); DgnPlatform::EditElementHandle element; Bentley::DRange3d infiniteRange = Bentley::DRange3d::FromMinMax(-1.7976931348623157E+308, 1.7976931348623157E+308); status = Bentley::DgnPlatform::PointCloudHandler::CreatePointCloudElement(element, model, *properties, infiniteRange); if (status == 0) { status = element.AddToModel(); } }
Hi Dart,
Dart Vader said:How can I do it? Is the MicroStation and Point Cloud Writer support multi-thread and parallel work?
MicroStation API is not thread safe and one instance cannot be called from different threads.
What I remember from some (only a few) discussions and own research: When your operations are limited to DgnPlatformLib (and not e.g. MStnPlatformLib), what you can do is to start a thread(s) and initialize own "host" in every thread. I think separate hosts cannot access the same DGN file (maybe to open the same empty DGN in read-only is fine). It should be possible to create individual POD files there.
What always must be done in the main (GUI) thread is to attach newly created POD files, so you must implement some kind of thread-safe messaging, so the main thread is informed, when new POD is created.
I recommend to see this discussion, where the same process, but in NET, is mentioned.
With regards,
Jan
P.S. In fact, it's possible to find rich set of multi task / multi thread code in MicroStation API, but there are no examples and guidelines available, and it is there to make code simpler, not allowing multithreaded access to API.
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
Oh, I see. Thanks for the quick answer. I will check that discussion.
And from this point, I have another question. Do some MicroStation API methods support the work outside the Microstation? I mean, could I find a target DLL that implements a Point Cloud writer and call it in my DLL to only generate the POD regardless of whether the MicroStation is running?
Dart Vader said:Do some MicroStation API methods support the work outside the Microstation?
By default, MicroStation must be always running, when API is used (you call API from MicroStation process and memory space). Licensing and similar topics (settings of feature aspects...) are checked when MicroStation is started, prior API can be used.
But it does not mean MicroStation GUI must be visible. MicroStation can be started using (so called) MS_INITAPP application, when MicroStation does not "enter" graphic mode. It is used when e.g. batch processing from command line is used. Still, MicroStation is running.
Technically MicroStation is built on top of PowerPlatfom, where DgnPlatform is one from core components. It is how other applications like OpenRoads Designer are created (common misunderstanding is that other products are built on top of MicroStation, but they are not). This technology (core) is not available outside Bentley (maybe for some very special partners under special agreement ;-)
Thanks a lot.
Dart Vader said: when I generate and attach these files in a simple loop - MicroStation UI just freeze
Type calling function mdlSystem_pumpMessages() in your loop.
mdlSystem_pumpMessages()
Regards, Jon Summers LA Solutions