//NOTE: FaceWalls cannot be updated, as well we can't seem to get their base face easily so they are ToNatvie only public List <ApplicationPlaceholderObject> FaceWallToNative(RevitFaceWall speckleWall) { if (speckleWall.face == null) { throw new Exception("Only surface based FaceWalls are currently supported."); } var wallType = GetElementType <WallType>(speckleWall); //TODO: Convert speckle surface to face Face f = null; var revitWall = DB.FaceWall.Create(Doc, wallType.Id, GetWallLocationLine(speckleWall.locationLine), f.Reference); if (revitWall == null) { ConversionErrors.Add(new Error { message = $"Failed to create wall ${speckleWall.applicationId}." }); return(null); } SetInstanceParameters(revitWall, speckleWall); var placeholders = new List <ApplicationPlaceholderObject>() { new ApplicationPlaceholderObject { applicationId = speckleWall.applicationId, ApplicationGeneratedId = revitWall.UniqueId, NativeObject = revitWall } }; var hostedElements = SetHostedElements(speckleWall, revitWall); placeholders.AddRange(hostedElements); return(placeholders); }
//TODO: delete temp family after creation //TODO: allow updates to family..? //NOTE: FaceWalls cannot be updated, as well we can't seem to get their base face easily so they are ToNatvie only public List <ApplicationPlaceholderObject> FaceWallToNative(RevitFaceWall speckleWall) { if (speckleWall.surface == null) { throw new Speckle.Core.Logging.SpeckleException("Only surface based FaceWalls are currently supported."); } // Cannot update revit wall to new mass face FaceWall revitWall = GetExistingElementByApplicationId(speckleWall.applicationId) as DB.FaceWall; if (revitWall != null) { Doc.Delete(revitWall.Id); } var famPath = Path.Combine(Doc.Application.FamilyTemplatePath, @"Conceptual Mass\Metric Mass.rft"); if (!File.Exists(famPath)) { ConversionErrors.Add(new Error { message = $"Could not find file Metric Mass.rft" }); return(null); } var tempMassFamilyPath = CreateMassFamily(famPath, speckleWall.surface, speckleWall.applicationId); Family fam; Doc.LoadFamily(tempMassFamilyPath, new FamilyLoadOption(), out fam); var symbol = Doc.GetElement(fam.GetFamilySymbolIds().First()) as FamilySymbol; symbol.Activate(); try { File.Delete(tempMassFamilyPath); } catch { } var mass = Doc.Create.NewFamilyInstance(XYZ.Zero, symbol, DB.Structure.StructuralType.NonStructural); // NOTE: must set a schedule level! // otherwise the wall creation will fail with "Could not create a face wall." var level = new FilteredElementCollector(Doc) .WhereElementIsNotElementType() .OfCategory(BuiltInCategory.OST_Levels) // this throws a null error if user tries to recieve stream in a file with no levels .ToElements().FirstOrDefault(); if (level == null) // create a new level at 0 if no levels could be retrieved from doc { level = Level.Create(Doc, 0); } TrySetParam(mass, BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM, level); //must regenerate before getting the elem geometry Doc.Regenerate(); Reference faceRef = GetFaceRef(mass); var wallType = GetElementType <WallType>(speckleWall); if (!FaceWall.IsWallTypeValidForFaceWall(Doc, wallType.Id)) { ConversionErrors.Add(new Error { message = $"Wall type not valid for face wall ${speckleWall.applicationId}." }); return(null); } revitWall = null; try { revitWall = DB.FaceWall.Create(Doc, wallType.Id, GetWallLocationLine(speckleWall.locationLine), faceRef); } catch (Exception e) { } if (revitWall == null) { ConversionErrors.Add(new Error { message = $"Failed to create face wall ${speckleWall.applicationId}." }); return(null); } Doc.Delete(mass.Id); SetInstanceParameters(revitWall, speckleWall); var placeholders = new List <ApplicationPlaceholderObject>() { new ApplicationPlaceholderObject { applicationId = speckleWall.applicationId, ApplicationGeneratedId = revitWall.UniqueId, NativeObject = revitWall } }; var hostedElements = SetHostedElements(speckleWall, revitWall); placeholders.AddRange(hostedElements); return(placeholders); }