How does one retrieve the text\values from a dimension element using the DgnPlatform api?
I tried grabbing the TextBlocks, but all it returns is "*"
Thanks,
Maury
Post the code you used to grab the TextBlocks.
Text-like elements such as dimensions can consist of multiple chunks of text, which DgnPlatform refers to as 'text parts'. These elements' handlers implement the ITextQuery interface, from which you can obtain a list of 'text part ids'; and given a text part id, the corresponding TextBlock.
TextQueryOptions options = new TextQueryOptions { ShouldIncludeEmptyParts = false, ShouldRequireFieldSupport = false }; TextPartIdCollection parts = element.GetTextPartIds(options); _measurement = ""; foreach (TextPartId id in parts) { TextBlock textBlock = element.GetTextPart(id); _measurement += textBlock.ToString(); }
I tried different textqueryoptions with no luck.
Paul, any updates on this?
Hi Maury,
I delved into the relevant code and discovered that _GetTextPart() is producing that "*" string as a placeholder for historical reasons.
A DimensionHandler::GetDisplayText() function exists to do what you need, but is unfortunately excluded from the published API.
We could add that to the published SDK, but my preference would be to make _GetTextPart() work as advertised.
I've followed up with the relevant developers...I don't see an obvious temporary workaround for you to use - will follow up with news when available.
Regards,
Paul
we have filed an Enhancement request # 777068 to address this issue.
Edit: Verified workaround using COM object library using method .ActualValue:
double ActualValue { get; } Member of Bentley.Interop.MicroStationDGN.DimensionElement
As reference please find a code example here
Artur,
Thank you for filing the enhancement. The workaround you proposed would work in some cases, however, getting the Element ID is not always possible (Element not yet plotted\transients), thus bouncing between the DgnPlatform and Interop API is not always possible.
Could you also file an enhancement for easier interoperability between the DgnPlatformNET and old interop APIs?
My current workaround for the dimensions has been to pass the ElementHandle to some MDL code.
A problem I have noticed is that after I call my MDL function from c#, the element appears to have been disposed or corrupted.
Element dimensionElement = GetElementUor(); // Generate a new dimension element double measurement = Mdl.GetDimensionValue(dimensionElement.ElementHandle); // dimensionElement no longer valid here...
extern "C" DLLEXPORT double GetDimensionValue(ElementHandle eh) { int numberOfSegments = mdlDim_getNumberOfSegments(eh.GetElementCP()); double values[50]; mdlDim_getActualValues(const_cast<MSElementP>(eh.GetElementCP()), values); if (numberOfSegments > 0) return values[0]; return 0.0; }
I noticed that mdlDim_getActualValues is not accepting a const MSElementP but I cannot imagine that this is modifying anything.
Is there something wrong with what I am doing?
Unknown said:I noticed that mdlDim_getActualValues is not accepting a const MSElementP but I cannot imagine that this is modifying anything
There are a few murky corners of the MicroStationAPI where C-style functions persist, mainly to support legacy apps.. I agree with you that it's unlikely that the function changes anything, in which case const_cast<> is the right approach.
const_cast<>
In a few cases you will find a parallel development of C++ classes that replace those C APIs. In this case, there are classes such as IDimensionQuery that probably do what you want. However, IDimensionQuery is an abstract class, and I don't see a way to create one.
IDimensionQuery
Regards, Jon Summers LA Solutions
You don't create an IDimensionQuery - you dynamic_cast an element handler to one and use it if it's non-null (like any other handler interface).
Dynamic_Cast to IDimensionQuery does not seem possible.
I think in this case, one must use DimensionHandler however, I do not see anything useful in IDimensionQuery. There is no way to pull the values