public static Autodesk.Revit.DB.DirectShape ToNative(this SpeckleElementsClasses.DirectShape myDs) { var(docObj, stateObj) = GetExistingElementByApplicationId(myDs.ApplicationId, myDs.Type); //can't edit existing DS if (docObj != null) { Doc.Delete(docObj.Id); } IList <GeometryObject> mesh = (IList <GeometryObject>)SpeckleCore.Converter.Deserialise(obj: (SpeckleMesh)myDs.directShapeMesh, excludeAssebmlies: new string[] { "SpeckleCoreGeometryDynamo", "SpeckleElementsRevit", "SpeckleStructuralRevit" }); var cat = BuiltInCategory.OST_GenericModel; var bic = BuiltInCategories.GetFromCategory(myDs.category); BuiltInCategory.TryParse(bic, out cat); var catId = Doc.Settings.Categories.get_Item(cat).Id; var ds = Autodesk.Revit.DB.DirectShape.CreateElement(Doc, catId); ds.ApplicationId = myDs.ApplicationId; ds.ApplicationDataId = Guid.NewGuid().ToString(); ds.SetShape(mesh); ds.Name = myDs.directShapeName; SetElementParams(ds, myDs.parameters); return(ds); }
public ApplicationPlaceholderObject DirectShapeToNative(DirectShape speckleDs) { var docObj = GetExistingElementByApplicationId(speckleDs.applicationId); //just create new one if (docObj != null) { Doc.Delete(docObj.Id); } var converted = new List <GeometryObject>(); speckleDs.baseGeometries.ToList().ForEach(b => { switch (b) { case Brep brep: try { var solid = BrepToNative(brep); converted.Add(solid); } catch (Exception e) { var mesh = MeshToNative(brep.displayValue); converted.AddRange(mesh); } break; case Mesh mesh: var rMesh = MeshToNative(mesh); converted.AddRange(rMesh); break; default: ConversionErrors.Add(new Error("Incompatible geometry type", $"Type ${b.GetType()} is not supported in DirectShape conversions.")); break; } }); BuiltInCategory cat; var bic = RevitUtils.GetBuiltInCategory(speckleDs.category); BuiltInCategory.TryParse(bic, out cat); var catId = Doc.Settings.Categories.get_Item(cat).Id; var revitDs = DB.DirectShape.CreateElement(Doc, catId); revitDs.ApplicationId = speckleDs.applicationId; revitDs.ApplicationDataId = Guid.NewGuid().ToString(); revitDs.SetShape(converted); revitDs.Name = speckleDs.name; SetInstanceParameters(revitDs, speckleDs); return(new ApplicationPlaceholderObject { applicationId = speckleDs.applicationId, ApplicationGeneratedId = revitDs.UniqueId, NativeObject = revitDs }); }