New Opening
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}