Hello!I work in Microstation vi8 and trying to call an MDL function (mdlKISolid_minimumDistanceBetweenEntities function) in MVBA, but it return "0". Could you help me to solve this problem? Maybe there is a mistake in types of variables.My code below:
Declare Function mdlKISolid_minimumDistanceBetweenEntities Lib "stdkisolid.dll" (ByRef pPoint1 As Point3d, ByRef pPoint2 As Point3d, ByRef pDistance As Double, ByVal entity1 As Element, ByVal entity2 As Element) As BooleanSub min()Dim entity3 As ElementDim entity4 As ElementDim f As DLongDim b As LongDim b1 As LongDim x As BooleanDim pPoint3 As Point3dDim pPoint4 As Point3dDim pDistance1 As Double
'ID of two solids
b = 447497b1 = 447525
f = DLongFromLong(b)Set entity3 = ActiveDesignFile.GetElementByID(f)f = DLongFromLong(b1)Set entity4 = ActiveDesignFile.GetElementByID(f)
x = mdlKISolid_minimumDistanceBetweenEntities(pPoint3, pPoint4, pDistance1, entity3, entity4)End Sub
Hi Artem,
at first, I recommend to follow the best practices and to always specify the used products and its version exactly (because there have been I guess nearly 20 official MicroStation V8i versions released). Also, always use Insert > Insert code tool when any piece of code is to be shared. To present code, formatted as plain text, is confusing. The last thing to make you post better is to think about used tags. Why to pollute the post by tags like MicroStationAPI (which you question is not about at all, because MicroStationAPI is C++ API, whereas your question is about classic C MDL API) or MicroStation Programming (which is useless and obvious, when you question is posted in MicroStation Programming forum)?
Artem Ramazanov said:Maybe there is a mistake in types of variables.
The problem is that you did not read mdlKISolid_minimumDistanceBetweenEntities carefully, so you use wrong declaration (and argument types consequently): The function does not accept Element as parameter. I think the reason is clear: How C API can understand VBA Element object?
From the documentation, the declaration should be:
Declare Function mdlKISolid_minimumDistanceBetweenEntities Lib "stdkisolid.dll" ( ByRef pPoint1 As Point3d , ByRef pPoint2 As Point3d , ByRef pDistance As Double , ByVal pEntity1 As Long , ByVal pEntity2 As Long ) As Long
where the last 2 parameters are Long, because of pointers to KIENTITY structure.
So the question is transformed into "How to obtain KIENTITY pointer?". I do not remember solid API in V8i well, but I think you have to ask for KIBODY from element descriptor (mdlKISolid_elementToBody2), to use it, and to free it, when not needed.
But, there is another problem: When you have 2 KIENTITIES, created from element descriptors, they are defined in own coordinate systems, so to measure minimum distance likely provide wrong result. See this discussion for more explanation and proper solution. But it's not simple and cannot be probably done using VBA.
Artem Ramazanov said:and trying to call an MDL function
My question is why you want to use this function? To work with solids in MicroStation is complex topic and should always be done directly in C API. Is there any reason to work with KISOLIDS from VBA?
If you want to measure the minimum distance, I recommend to try mdlMinDist_betweenElms() function.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Artem Ramazanov
Thank you for help!