Cut Geometry Method in C# Revit API

Cut Geometry Method in C# Revit API

ahmadkhalaf7892
Advocate Advocate
1,176 Views
6 Replies
Message 1 of 7

Cut Geometry Method in C# Revit API

ahmadkhalaf7892
Advocate
Advocate

ahmadkhalaf7892_0-1728305429832.png

 

Hi Revit Users,

I need help finding the correct method to obtain cut geometry using the API. The cut geometry I'm referring to is shown in the attached picture. I’ve tried the following methods:

  • SolidSolidCutUtils.AddCutBetweenSolids
  • InstanceVoidCutUtils.AddInstanceVoidCut

Unfortunately, they didn’t work as expected. When I manually cut in Revit, the result is different from what I get using these methods. Specifically, I’m working with a shared family that contains a void.

Could anyone please provide guidance on the correct method to use for cutting in this scenario?

Thanks!






0 Likes
Accepted solutions (1)
1,177 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

First of all, please search this forum for existing threads on "cut geometry" and suchlike. I see quite many of them. Maybe some of them can help. Then you can summarise what we have learned so far, so that we know where we stand as a community, and can continue researching from there:

  

  

Thank you!

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 7

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi,

 

InstanceVoidCutUtils.AddInstanceVoidCut  Should be the one, I think.

I use this to autocut walls with a void family, although it's not a Shared Family with a void.

 

Maybe the wrong family is selected in the API to cut. In the UI I believe you select the top-family to cut with.

Either the UI command makes a cut-relation with the nested family and the cut-element or ....

 

Make the Cut with the UI and check with the API util tools what the cut relation (which element with what) and work you're way back in the API.

 

Use below function to find the relation:

GetElementsBeingCut  and GetCuttingVoidInstances  

0 Likes
Message 4 of 7

jeremy_tammik
Alumni
Alumni

Please note that cut geometry also requires a corresponding setting in the family definition:

  

  

Search the two articles for "cut geom"...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 7

ahmadkhalaf7892
Advocate
Advocate

Hi Thanks , 
Here is my code : 

public void CutSheetPilesWithFloor(Document doc, List<FamilyInstance> sheetPiles, Floor floor)
{
Transaction transaction = new Transaction(doc, "Cut Sheet Piles with Floor");
transaction.Start();


foreach (FamilyInstance sheetPile in sheetPiles)
{

// Add a solid-solid cut between the floor and the sheet pile
SolidSolidCutUtils.AddCutBetweenSolids(doc, floor, sheetPile);
}

transaction.Commit();
transaction.Start();
foreach (FamilyInstance sheetPile in sheetPiles)
{
if (InstanceVoidCutUtils.CanBeCutWithVoid(floor))
{
InstanceVoidCutUtils.AddInstanceVoidCut(doc, floor, sheetPile);
}


}


transaction.Commit();
}

I am just trying to cut the sheet pile with the floor,  and I have attached my family , when I cut them manually in revit it works , and it cuts the way I want , however when I try cutting it via the code I am recieving erorrs, or not what I want 

ahmadkhalaf7892_0-1728374230752.png


I attached the cut geometry I want in the picture , also the shared family ,  IHave no idea why with the code ots not working , I am going back and forth with no results. 
I appricaite any help provided

0 Likes
Message 6 of 7

ahmadkhalaf7892
Advocate
Advocate
0 Likes
Message 7 of 7

ahmadkhalaf7892
Advocate
Advocate

Hi 
Thanks for the advice, Apparetnly I had to use a for loop instead of a foreach loop and it works, 
Moreover sometimes the nested family(the void inside the family) wasn't cutting properly which is why I had to adjust it and add a 1 mm height but overall your comment have helped a lot 

0 Likes