Example #1
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (base.CastTo <Q>(ref target))
            {
                return(true);
            }

            var element = APIElement as DB.TaggedObject;

            if (typeof(DB.TaggedObject).IsAssignableFrom(typeof(Q)))
            {
                if (element is null)
                {
                    if (IsValid)
                    {
                        return(false);
                    }
                }
                else if (!typeof(Q).IsAssignableFrom(element.GetType()))
                {
                    return(false);
                }

                target = (Q)(object)element;
                return(true);
            }

            if (element is null)
            {
                return(false);
            }

            if (element.Category?.HasMaterialQuantities ?? false)
            {
                if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh)))
                {
                    using (var options = new DB.Options()
                    {
                        DetailLevel = DB.ViewDetailLevel.Fine
                    })
                        using (var geometry = element.GetGeometry(options))
                        {
                            if (geometry is object)
                            {
                                var mesh = new Mesh();
                                mesh.Append(geometry.GetPreviewMeshes(null).Where(x => x is object));
                                mesh.Normals.ComputeNormals();
                                if (mesh.Faces.Count > 0)
                                {
                                    target = (Q)(object)new GH_Mesh(mesh);
                                    return(true);
                                }
                            }
                        }
                }
            }

            return(false);
        }
Example #2
0
 public static new bool IsValidElement(DB.Element element)
 {
     using (var options = new DB.Options())
         return(!(element.get_Geometry(options) is null));
 }