Boolean Operation Fail

Boolean Operation Fail

marcelo_quevedo
Contributor Contributor
23,797 Views
62 Replies
Message 1 of 63

Boolean Operation Fail

marcelo_quevedo
Contributor
Contributor

Hello,

The core of our application works with solid operations between solids, and we constantly faced Boolean operation issues by using the ExecuteBooleanOperation() API method. It throws the next exception that doesn’t allow to do the Boolean operation.

 

“Failed to perform the Boolean operation for the two solids. This may be due to geometric inaccuracies in the solids, such as slightly misaligned faces or edges. If so, eliminating the inaccuracies by making sure the solids are accurately aligned may solve the problem. This also may be due to one or both solids having complexities such as more than two faces geometrically meeting along a single edge, or two coincident edges, etc. Eliminating such conditions, or performing a sequence of Boolean operations in an order that avoids such conditions, may solve the problem.”

 

I created a simple C# sample with a command that allows to do a Boolean operation between two solids. Also, I have attached two Revit files. Each file contains two intersected directShape objects. Using the C# sample and those files you could reproduce the issue by trying to do a Boolean operation between the two objects.

 

We will be very grateful if you could help us with some directions to solve the issue, and it would be great if you take into consideration this API issue for the future Revit APIs.

 

Thanks a lot, in advance!

Marcelo

 

23,798 Views
62 Replies
Replies (62)
Message 2 of 63

JimJia
Alumni
Alumni

Dear Marcelo Quevedo,

 

I am sorry to say that I can reproduce your problem as well(I didn't find code problem).

 

I'm communicating with engineering team and I submitted the issue list item REVIT-122714 [Boolean Operation Fail - case 13578517] on your behalf for the issue you find, as this issue requires exploration and possibly a modification to our software. Please make a note of this number for future reference.

You are welcome to request an update on the status of this issue or to provide us with additional information at any time quoting this wish list item number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritized against all of the other change requests that are outstanding. As a result any information that you can provide to influence this assessment will help. Please provide the following where possible:
• Impact on your application and/or your development.
• The number of users affected.
• The potential revenue impact to you.
• The potential revenue impact to Autodesk.
• Realistic timescale over which a fix would help you.
• In the case of a request for a new feature or a feature enhancement, please also provide detailed Use Cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact Change Requests. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 3 of 63

Anonymous
Not applicable

 

I use Revit 2019 and often get this problem when performing Union operation on two solids. Any alternatives to do union on two solids?

Thanks

Message 4 of 63

Anonymous
Not applicable

 

This Boolean Operation problem is really frustrating.

Theoretically the operation (union, intersection, difference) can be performed on any two solids, and the problem should NEVER take place. This only means the algorithm currently used by Autodesk is not working well.

It would be nice if Autodesk can give some useful suggestions on how to avoid the problem before it is fixed eventually.

Can user get any clue from the error message “This may be due to geometric inaccuracies in the solids, such as slightly misaligned faces or edges”. What are “geometric inaccuracies” or “slightly misaligned faces or edges”? Or the purpose of the error message is just to make user think the problem is caused by the model?

 

Message 5 of 63

SouravGanguli
Contributor
Contributor

Facing the exact same issue. Anybody have any solution yet?

Message 6 of 63

antonio_hipolito
Enthusiast
Enthusiast

I'm having the same difficulties. I found that many times it is due to slight object misalignment.

If after Boolean operation the resulting solid has one small face, the method fails.

The images bellow are example. Wanting to subtract red object from white one.

In REVIT every things seams aligned, but after exporting the geometry to AUTOCAD I found this small misalignment (0.0004 units). After alignment correction, it worked.

 

WHAT I SEEK: a method to automatically correct those small misalignment or to adjust REVIT tolerance.

Any ideas? 

 

 red object to subtract from white objectred object to subtract from white object         zoom at the cornerzoom at the corner

 

 

Message 7 of 63

jeremytammik
Autodesk
Autodesk

Thank you for the nice pictures.

 

Can you please provide a minimal complete reproducible case that illustrates the problem with one single click or two that I can pass on to the development team for further analysis?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 63

antonio_hipolito
Enthusiast
Enthusiast

Jeremy,

I'm not quite sure what you need, but I prepared a sample Revit model with the question.

The generic model in red, is slight of alignment with the column and the beam.

An exception occurs when I try to subtract form the generic model the solid geometry of the beam and column with:

 

BooleanOperationsUtils.ExecuteBooleanOperationModifyingOriginalSolid(base, geomSolid, BooleanOperationsType.Difference)

 

I don't know how to attach the .rvt file... but I can send you if you need it.

Anotação 2020-04-28 163701.png

0 Likes
Message 9 of 63

jeremytammik
Autodesk
Autodesk

You can attach the RVT model right here to your message in this discussion thread, cf. 'Attachments'.

 

Optimally, you could implement a macro that performs the Boolean operation on two hard-coded solids in the model.

 

Thank you!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 10 of 63

antonio_hipolito
Enthusiast
Enthusiast

Jeremy,

Please find attached .rvt file.

Regards

0 Likes
Message 11 of 63

Anonymous
Not applicable

Dear Jeremy,

I prepared an example to show the Boolean Operation exception. You may run the following code on the attached document to see the exception. The code includes a working case (4373) and a failed case (4348).

This example is for BooleanOperationsType.Difference. The Union operation sometimes also fails with the same error message. I do not know about Intersect operation since I never use it.

Thanks

 

internal static void BooleanOperationFail(Document document)
{
Element ele_big = document.GetElement(new ElementId(4348));
Element ele_small = document.GetElement(new ElementId(4366)); // this one throws exception
// Element ele_small = document.GetElement(new ElementId(4373)); // this one does not throw exception

Solid solid_big = Get_Solid(document, ele_big);
Solid solid_small = Get_Solid(document, ele_small);
Solid res_solid = BooleanOperationsUtils.ExecuteBooleanOperation(solid_big, solid_small, BooleanOperationsType.Difference);

// Check the result by creating a DirectShape
List<GeometryObject> directShapeSolids = new List<GeometryObject>();
directShapeSolids.Add(res_solid);

using (Transaction trans = new Transaction(document))
{
trans.Start("tex3");
DirectShape thisEle;
thisEle = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
thisEle.SetShape(directShapeSolids);
ElementTransformUtils.MoveElement(document, thisEle.Id, new XYZ(10,10,10));
trans.Commit();
}

TaskDialog.Show("Revit", " Boolean Operation Done");
}

internal static Solid Get_Solid(Document document, Element element)
{
Autodesk.Revit.DB.Options opt = document.Get_GeomOption();
Autodesk.Revit.DB.GeometryElement geomElem = element.get_Geometry(opt);
List<Solid> all_solids = new List<Solid>();
foreach (GeometryObject geomObj in geomElem)
{
Solid geomSolid = geomObj as Solid;
if (null != geomSolid)
{
all_solids.Add(geomSolid);
}
}
if(all_solids.Count != 1)
{
throw new Exception("must be one solid");
}
return all_solids[0];
}

0 Likes
Message 12 of 63

Anonymous
Not applicable
Hi Jeremy, Could you please have a look at the Boolean operation failure example I posted last week in this thread? I hope it can help the development team to identify the problem and fix it. Thanks.
Message 13 of 63

jeremytammik
Autodesk
Autodesk

Dear Steve, Antonio, and others,

 

Thank you very much for your sample material and problem reports.

 

I attached them to the development ticket REVIT-122714 [Boolean Operation Fail - case 13578517] and raised its priority to 'critical'.

 

I hope to hear back from the development team on it soon.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best Regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 14 of 63

antonio_hipolito
Enthusiast
Enthusiast

Jeremy,

 

Solid Boolean Operation is a crucial task on any 3D modeling software. 

It's a basic requirement, it's not optional. REVIT must perform extremely well on this matter. 

It's a critical issue to be solved as soon as possible, I agree with you.

Keep pushing this issue to a solution.

 

PS: My company has above 40 000 employees. 

António

Message 15 of 63

jeremytammik
Autodesk
Autodesk

Dear António,

 

Thank you very much for your update and business case.

 

I attached it to the development ticket REVIT-122714 [Boolean Operation Fail - case 13578517].

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 16 of 63

jshial
Advocate
Advocate

@JimJia @jeremytammik @marcelo_quevedo @antonio_hipolito @Anonymous 

 

I'm also facing this issue right now.  I hope the following experience could be helpful to any of you, developers or Autodesk.

 

This is my situation, a grey box containing several green cuboids. See the rendering gets a bit weird at interfacing area due to overlapping. BooleanUtil fails on the second cuboid when computing intersection between grey box and these cuboids (I wish I could give you these elements, but they're all linked. I'll try to put them in a sample file to help others recreating the problem if anyone is interested.)

 

jshial_1-1592882483937.png

 

Exception thrown, inaccuracy, misalignment. 

 

So this is what I tested:

1. Translate cuboid's solid just a little bit. Or scale it to 1.1 or 0.9. Same exception thrown, I guess a little bit of transformation didn't resolve what exception message says.

 

2. Run same logic in Dynamo (with nodes), it works fine.

 

3. Run same logic in Dynamo (with only one Python node, pure IronPython, calling BooleanUtil from RevitAPI), it works fine surprisingly.

 

Idk why even calling BooleanUtil straight from Revit API in Dynamo doesn't throw that exception anymore either. Is there some optimization that Dynamo does intentionally to cope with this problem?  I did some diggin on both Revit and Dynamo's geometry kernel, a term ASM(Autodesk ShapeManager) comes up,  this thread has some very informative discussion: https://github.com/DynamoDS/DynamoRevit/issues/1960

 

kronz's post might explain what I'm experiencing now.

 
 

 

To sum it up:

1. To revit users and developers, I would suggest to give Dynamo a try.

2. Not knowing how internal collaboration is in Autodesk, wish Revit dev team could discuss this with Dynamo dev team, hopefully releasing a fix asap.

3. This puts me in dilemma now because I'm developing a WPF app with these intersections. I have hundreds of this kind of grey boxes to compute intersections with its nearby elements. Operating on all the boxes is too heavy for Dynamo, forcing me to chop the task into smaller sets and run Dynamo multiple times. Although I consider an IExternalCommand in C# is faster than Dynamo script for my task, I just cannot use it.

 

1. Impact on your application and/or your development: 

It basically means I cannot develop my app, may argue that I can always implement my own algorithm for boolean operation. Pretty challenging and time-consuming, resource is a factor.

 

2. The number of users affected:

Almost 10,000 employees, expected product could make our work tremendously easier.

 

3. The potential revenue impact to you:

Hard to measure. Dynamo to the rescue while the efficiency dropped considerable than expected before.

 

4. The potential revenue impact to Autodesk:

Impossible for me to measure, I feel like Dynamo has a more reliable algorithm to this but don't know if transfer that to Revit is simple or not.

 

5. Realistic timescale over which a fix would help you.

As soon as possible. Timestamp in this thread, 2017 => 2019 => 2020. Development-wise, I'm stopped basically.

 

6. In the case of a request for a new feature or a feature enhancement, please also provide detailed Use Cases for the workflows that this change would address.

I just need the intersection solids, just like what BooleanOperationsUtils can give me usually.

Message 17 of 63

jshial
Advocate
Advocate

 

jshial_0-1592896473599.png

 

Message 18 of 63

jeremytammik
Autodesk
Autodesk

Thank you very much for your careful analysis and interesting results, which I attached it to the development ticket REVIT-122714 [Boolean Operation Fail - case 13578517].

  

I am glad to hear that it works better in Dynamo, and hope very much that will help enable the Revit development team to improve the situation inside the pure Revit API.

   



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 19 of 63

tommy.stromhaug
Contributor
Contributor

Hi,

 

One possible solution that helped for me is : if boolean operation fails, then make a tiny adjustment to the solid(s).

I know that handling program flow in the catch block is not good practice, but this problem was driving me crazy.

The code below shows one of my solutions. I also have backup routines in case this fail, like rotating other axis combined with small translations.

 

           List<double> rad = new List<double>{0.00001,0.00005,0.0001,0.0005};
            
            foreach (double value in rad)
            {
                
                try
                {
                    Transform t1 = Transform.CreateRotation(new XYZ(0, 0, 1), value);
                   
                    Transform t2 = t1.Multiply(trans);
                    s2 = SolidUtils.CreateTransformed(s2, t2);
                    Solid areaSolid = BooleanOperationsUtils.ExecuteBooleanOperation(s1, s2, BooleanOperationsType.Intersect);
                    res = s2;
                    return areaSolid;

                }
                catch (Exception e) {}
            }

            

            
            throw new Exception();
        }

 

Tommy Strømhaug

Symetri Norway

0 Likes
Message 20 of 63

jeremytammik
Autodesk
Autodesk

Wow!

 

That is a pretty horrific workaround.

 

I am very impressed that it helps.

 

Thank you very much, Tommy, for sharing this.

 

I added a note of it to the development ticket REVIT-122714 [Boolean Operation Fail - case 13578517] to show the development team how bad the situation is and to what extremes ot forces add-in developers to handle it.

 

The naming of your variables hints that you are in fact calculating an area, not a 3D solid.

 

Is that true?

 

If you just need a 2D area intersection, I would suggest taking a look at the very tiny yet powerful 2D Boolean operation libraries available, e.g., Clipper:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.2

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes