Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New Opening

3 REPLIES 3
Reply
Message 1 of 4
GeomGym
536 Views, 3 Replies

New Opening

Hi,

 

Can someone please help with the following code and why the new opening throws an exception?

If I manually create it works.  I have called a document regeneration between creating the roof and the opening.

 

Here's the exception

 

Autodesk.Revit.Exceptions.InvalidOperationException was unhandled by user code
HResult=-2146233088
Message=""
Source=RevitAPI
StackTrace:
at Autodesk.Revit.Creation.Document.NewOpening(Element hostElement, CurveArray profile, Boolean bPerpendicularFace)
at GGYM.ImportIFCGeomGym.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in c:\My Work\Geometry Gym\programming\BIM\revit\GGPL Revit Test\GGPL Revit IFC\Class1.cs:line 53
at apiManagedExecuteCommand(AString* assemblyName, AString* className, AString* vendorDescription, MFCApp* pMFCApp, DBView* pDBView, AString* message, Set<ElementId\,std::less<ElementId>\,tnallc<ElementId> >* ids, Map<AString\,AString\,std::less<AString>\,tnallc<AString> >* data, AString* exceptionName, AString* exceptionMessage)
InnerException:

 

Thanks in advance,

 

Jon

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class ImportIFCGeomGym : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

Document document = commandData.Application.ActiveUIDocument.Document;
Transaction trn = new Transaction(document, "ggTest");
trn.Start();
FilteredElementCollector collector = new FilteredElementCollector(document).OfClass(typeof(RoofType));
RoofType rt = collector.FirstElement() as RoofType;

Level l = null;
FilteredElementCollector fec = new FilteredElementCollector(document).OfClass(typeof(Level));
foreach(Level lvl in fec)
{
l = lvl;
break;
}

CurveArray ca = new CurveArray();
ca.Append(Line.CreateBound(new XYZ(-1.254816156, -0.790364666, 0.000000000), new XYZ(10.181315441, -3.331727227, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(10.181315441, -3.331727227, 0.000000000), new XYZ(9.841979237, -0.002432085, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(9.841979237, -0.002432085, 0.000000000), new XYZ(4.920719387, 3.278407815, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(4.920719387, 3.278407815, 0.000000000), new XYZ(-0.000540464, -0.002432085, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(-0.000540464, -0.002432085, 0.000000000), new XYZ(-1.254816156, -0.790364666, 0.000000000)));


ModelCurveArray mca = new ModelCurveArray();
FootPrintRoof fpr = document.Create.NewFootPrintRoof(ca, l, rt, out mca);
ca.Clear();
ca.Append(Line.CreateBound(new XYZ(-1.254816156, -0.790364666, 0.000000000), new XYZ(10.181315441, -3.331727227, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(10.181315441, -3.331727227, 0.000000000), new XYZ(9.841979237, -0.002432085, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(9.841979237, -0.002432085, 0.000000000), new XYZ(-0.000540464, -0.002432085, 0.000000000)));
ca.Append(Line.CreateBound(new XYZ(-0.000540464, -0.002432085, 0.000000000), new XYZ(-1.254816156, -0.790364666, 0.000000000)));
document.Regenerate();
document.Create.NewOpening(fpr, ca, false);
trn.Commit();
return Result.Succeeded;
}

3 REPLIES 3
Message 2 of 4
Scott_Wilson
in reply to: GeomGym

I checked this out for you and it does seem like it should work. I seperated the the roof creation and opening creation sections into different commands and tried your opening creation code on several roofs created using various methods and found that Create.NewOpening() wouldn't accept any of them as input, each time stating that the element is not a roof, floor or ceiling.

 

Floor elements, on the other hand worked fine with your code, which means that your code works in principle, but something else is in play here.

 

I can't see anything in your code that would be causing this error. It looks to either be a bug in the API or atleast a misrepresentation of which elements are actually valid input for this function. (I used revit 2015 for my testing)

 

In the interest of providing an alternative solution while you wait for a better answer, I suggest that if the polygon you are trying to remove as an opening is fully enclosed within the outer footprint of the roof, you could simply append its profile curves to the roof's curve array before creating the roof. Not sure if that is suitable for your needs though.

 

I think someone from Autodesk needs to look at this one.

Message 3 of 4
GeomGym
in reply to: Scott_Wilson

Hi Scott,

 

Really appreciate your time looking into this (I should have said, I was testing in 2014).

 

The reason for the opening being the shape it is is so I can create a slope arrow on a horizontal edge (a preferred approach to your suggestion to chamfer a corner in the other thread for sloped roofs).

 

Will wait and see what Autodesk reply with for this.

Message 4 of 4
arnostlobel
in reply to: GeomGym

Sorry for the delay, but I have been trying to figure out what the problem might be. It looks like the code around NewOpening method has been refactored in R2015. All the parts that used it throw an Invalid Operation Exception with an empty message have been addressed as well as the execution code around it. I have not run your example though my local build yet, but is possible that the problem has been fixed.

I looked at the original code (the one before our fixes in 2015) and found the following situations at which an Invalid Operation used to be thrown with no descriptive message string:

  • the “host element” argument is NULL
  • the  host element is neither a Floor nor Ceiling nor Roof
  • Revit fails to create a Sketch object for a sketch plane that is based on the reference plane of the host element (at its main face)
  • the sketch failed to update itself after the opening got created.

For the last of the cases, there may be a few reasons for a sketch not being able to update itself. It may work in the UI because the UI may have some extra checks that validate values and do not allow them to be wrong, so the Sketch is not unhappy, so to speak. However, the API workflow may be missing the extra checks and thus allowing something that a Sketch sees as illegal.

I understand this is not much of an information, but maybe it can give you a hint. We have another programmer still looking into that and we should be able to post his findings later.

I, personally, was a bit surprised to see that the opening being created basically covers the entire floor except one corner of the polygon. That is practically cutting almost the entire floor off and leaving just a triangle. I discussed that with our internal “floor specialist” and he told me that it is in fact a legal operation and “should” work. However, I would have probably done that differently, I think. I would probably create a floor with just the one triangle so I would not have to even worry about creating an opening. I do understand, however, that the data may be coming from another source (like another file), thus it may not be obvious how an opening relates to the floor.  (Note: I can see this has already been pointed out and discussed earlier in this tread; so, never mind 🙂

 

Thank you

Arnošt Löbel

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community