[MSCE 10.15 C#] Intersection of Cone and Rectangle

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?

Parents
  • Hi Mike,

    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.

    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.

    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

  • 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.

  • 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 !

    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");
    }



Reply
  • 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 !

    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");
    }



Children
  • 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

  • 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 ,

    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...

    1. Take a look at ..\examples\Elements\ManagedToolsExample; particularly files:
      1. Readme.txt, BooleanExampleTool.cs, and SolidUtilClass.cs
    2. In those examples, reference in the DgnDisplayNet.dll assembly
    3. Then search and focus on Convert1 methods - as mentioned; not an easy to imply correlation between C++ and .NET APIs.
    4. Where these additional Bentley Communities searches (in order of least/precise to more/generic results) that when using Google Translates browser Extension (Edge and Chrome) may help find/address need for some more code snips and understanding:
      1. Convert1.ElementToBody AND *intersect*
      2. Convert1.ElementToBody
      3. Convert1
    5. Also note that you can conveniently perform some similar (though not all the above) searches using SDKSearch (or QS for local source) right from the MicroStation Developer Shell, by typing:
      1. sdksearch Convert1 -ver
      2. sdksearch Convert1.ElementToBody -ver

        NOTE
        : Unfortunately the example below currently does not work, though I will try to provide a future update to (sdksearch) to better support expanded searches with spaces via quotes and (cmd.exe) regex patterns.
        • sdksearch Convert1.ElementToBody AND *intersect*

    Hope this helps and let us know any additional specific that may be needed on "this topic". Slight smile

    HTH,
    Bob



  • Hi Mike,

    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:

    • In Visual Studio, Object browser is available. Its disadvantage (in the discussed context) is that it works with assemblies, referenced to a project, but often to search all MicroStation assemblies is necessary.
    • From free / open source solutions, I like dnSpy (but there are plenty of others)
    • Normally I use commercial .NET Reflector from RedGate. It has some special functions (like debugging and stepping into 3rd party assemblies etc.), that are needed rarely, but are extremely useful.

    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.

    With regards,

      Jan

  • 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.

     
    Regards, Jon Summers
    LA Solutions

  • Hi ,

    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.

    • 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.