I have a rectangle (ShapeElement) and a cylinder (ConeElement) that I'm trying to find out if they intersect. (Don't actually need the intersection point(s), just if they intersect).
Using Interop methods the ConeElement is not Intersectable element (Cone.IsIntersectableElement = false) so I can't use Element.GetIntersectionPoints.
Is there a method in DgnPlatformNET that may be able to cover this situation?
Hi Mike,
Mike Robertson said:I have a rectangle (ShapeElement) and a cylinder (ConeElement)
That's not optimal situation in my opinion, because "solid analytics" assume there are 2 (or more) solids (ISolidKernetEnetity) inputs, not solid and 2D "not solid" geometry.
Mike Robertson said:Don't actually need the intersection point(s), just if they intersect
The first test always should be evaluation of the element ranges, because it allows an efficient "early escape", when there is no reason to do any further analysis.
Mike Robertson said:Is there a method in DgnPlatformNET that may be able to cover this situation?
I do not think such function exists in API, but of course API is huge and maybe I miss something ;-)
I recommend to check DgnPlatformNET.Modify class (in DgnDisplayNET assembly), which looks like NET wrapper around SolidUtil::Modify class. BooleanIntersect allows to do the intersection, which is more than you need, but when there is no result, the solid does not intersect. But, a prerequisite here is to convert 2D "no thickness" shape to SolidKernelEntity upfront.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thanks Jan, I was thinking mixing the 2D & 3D might be a problem. I'll look into it and update if I find a solution.
Jan Ĺ legr said:I do not think such function exists in API, but of course API is huge and maybe I miss something ;-)
Actually you have found such function already. BooleanIntersect is !
Jan Ĺ legr said:a prerequisite here is to convert 2D "no thickness" shape to SolidKernelEntity upfront.
Doesn't need to do "thinckness" operation. The Solid API is powerful, it can think a shape as a sheet body and a linear element as a wire body. All are bodies.
I wrote below C++ code snippet to verify this. Just need Mike to rewrite it by using C#.
void isShapeSolidInterest() { EditElementHandle eeh1(6900L, ACTIVEMODEL), eeh2(6901L, ACTIVEMODEL); ISolidKernelEntityPtr target, tool; SolidUtil::Convert::ElementToBody(target, eeh1); SolidUtil::Convert::ElementToBody(tool, eeh2); if (SUCCESS == SolidUtil::Modify::BooleanIntersect(target, &tool, 1)) mdlDialog_dmsgsPrint(L"Intersect"); else mdlDialog_dmsgsPrint(L"NOT Intersect"); }
Yongan.Fu said:The Solid API is powerful, it can think a shape as a sheet body and a linear element as a wire body. All are bodies
Thanks for that help, and thanks for a simple and elegant code sample!
Regards, Jon Summers LA Solutions
Thanks a lot for the confirmation of my idea :-)
I agree with Jon the code is nicely simple, and there should not be a problem to convert it to NET.
Regards,
Jan,
The logic of the code is easy to follow, finding any objects/methods in the .NET api is not so apparent. Any pointers on where to look? Typically I can find similar .NET counterparts to the C++ objects/methods but that is proving not so easy on this topic.
Hi Mike Robertson,
Mike Robertson said:Typically I can find similar .NET counterparts to the C++ objects/methods but that is proving not so easy on this topic.
Please correct me if wrong, but I presume you may be looking for "some next steps" on "this topic" (hopefully...) being; How do I access the SolidsAPI from .NET?
As with some sections of the APIs at some point it may be required to "extend an APIs functionality" and augment with another more inclusive language; like calling native C++ APIs from managed .NET. C++/CLI and PInvoke are two common ways to extend and access C++ functionality from .NET.
However in this case until more functionality/use cases are require those extensions, I think you may to...
Hope this helps and let us know any additional specific that may be needed on "this topic".
HTH,Bob
Mike Robertson said:Any pointers on where to look?
What I recommend is "more direct" (maybe primitively brutal? ;-) way:
When you are not sure how to "convert" C++ knowledge or information to NET API, like whether any method is used, in what assembly it is available etc., use any available "NET assembly explorer" (debugger, editor...).
There are many of them available:
Regardless the tool you use, all of them offer full text search, so it is simple to find in what assembly specific class or method is available.
Robert Hook said:sdksearch Convert1.ElementToBody AND *intersect*
That produces no useful result...
################################################################################ # [SEARCH] Mode: , Command: "C:\PROGRA~1\Bentley\MICROS~1\SDK\examples\SDKSearch.bat Convert1.ElementToBody AND *intersect*" ################################################################################ 0 was unexpected at this time.
Hi Jon Summers,
For the last example I did NOTE (originally) it does not currently work and will modify the NOTE below in hopes to make it more clear (less confusing).- and - hope to make that last case work in the U16.2 or U16.3 timeframe.
Robert Hook said:sdksearch Convert1.ElementToBody -ver NOTE: Does not work, will try to provide a future update to support expanded searching w/spaces and regex options. sdksearch Convert1.ElementToBody AND *intersect*
Bob
Thanks for pointing out the SolidUtilClassExample.cs code. I'd searched high and low through the docs & examples for ElementToBody but was only finding the C++ references. I was using Agent Ransack to search within all the files inside the sdk and examples but for some reason didn't pick that code example up. I'll post my basic code incase someone else runs into this need.
DIdn't have Bentley.DgnDisplayNET.dll referenced so of course the object browser in Visual Studio didn't show any hits either.
Note: A reference to Bentley.DgnDisplayNET.dll is required.
I may need to do some more validation checks but the code below is working for now.
public static void ElementsIntersect(Element elementOne, Element elementTwo) { Bool intersects = false; SolidKernelEntity solidKernelEntityOne; Convert1.ElementToBody(out solidKernelEntityOne, elementOne, true, true, true); SolidKernelEntity solidKernelEntityTwo; Convert1.ElementToBody(out solidKernelEntityTwo, elementTwo, true, true, true); SolidKernelEntity[] solidKernelEntities = new SolidKernelEntity[1]; solidKernelEntities[0] = solidKernelEntityTwo; if (BentleyStatus.Success == Bentley.DgnPlatformNET.Modify.BooleanIntersect(ref solidKernelEntityOne, ref solidKernelEntities, 1)) { intersects = true; } return intersects; }
Answer Verified By: Robert Hook
Actually, Jan had told us SolidUtil class is in Bentley.DgnDisplayNET.dll at his first reply.