static IList <GeometryObject> ImportObject(File3dm model, GeometryBase geometry, ObjectAttributes attributes, Document doc, Dictionary <string, Autodesk.Revit.DB.Material> materials, double scaleFactor) { var layer = model.AllLayers.FindIndex(attributes.LayerIndex); if (layer?.IsVisible ?? false) { using (var ctx = GeometryEncoder.Context.Push()) { switch (attributes.MaterialSource) { case ObjectMaterialSource.MaterialFromObject: { var modelMaterial = attributes.MaterialIndex < 0 ? Rhino.DocObjects.Material.DefaultMaterial : model.AllMaterials.FindIndex(attributes.MaterialIndex); ctx.MaterialId = ToHost(modelMaterial, doc, materials); break; } case ObjectMaterialSource.MaterialFromLayer: { var modelLayer = model.AllLayers.FindIndex(attributes.LayerIndex); var modelMaterial = modelLayer.RenderMaterialIndex < 0 ? Rhino.DocObjects.Material.DefaultMaterial : model.AllMaterials.FindIndex(modelLayer.RenderMaterialIndex); ctx.MaterialId = ToHost(modelMaterial, doc, materials); break; } } if (geometry is InstanceReferenceGeometry instance) { if (model.AllInstanceDefinitions.FindId(instance.ParentIdefId) is InstanceDefinitionGeometry definition) { var definitionId = definition.Id.ToString(); var library = DirectShapeLibrary.GetDirectShapeLibrary(doc); if (!library.Contains(definitionId)) { var objectIds = definition.GetObjectIds(); var GNodes = objectIds. Select(x => model.Objects.FindId(x)). Cast <File3dmObject>(). SelectMany(x => ImportObject(model, x.Geometry, x.Attributes, doc, materials, scaleFactor)); library.AddDefinition(definitionId, GNodes.ToArray()); } return(DirectShape.CreateGeometryInstance(doc, definitionId, instance.Xform.ToTransform(scaleFactor))); } } else { return(geometry.ToShape(scaleFactor)); } } } return(new GeometryObject[0]); }
public static IEnumerable <DB.GeometryObject> ToHostMultiple(this GeometryBase geometry, double scaleFactor) => geometry.ToShape(scaleFactor);