solid test and disable importing nonsolid objects

This commit is contained in:
brothermechanic 2023-03-10 19:37:15 +03:00
parent 1ea7e50ecd
commit 37bdfcd5e9
No known key found for this signature in database
GPG key ID: BFB3FB14288FAC5E
3 changed files with 41 additions and 1 deletions

6
.gitignore vendored
View file

@ -103,4 +103,8 @@ ENV/
# blender backup files
*.blend1
install_plugin_cad.sh
.vscode
.vscode
# emacs backup files
~*
*#

View file

@ -23,6 +23,7 @@ import bpy
from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
from import_fcstd.handler import FreeCAD_xml_handler
from import_fcstd.materials import set_fem_mat
from import_fcstd.is_object_solid import is_object_solid
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
@ -123,6 +124,10 @@ def importer(filename,
# TODO add parent visibility check
continue
if not is_object_solid(obj):
logger.debug('%s is not solid', obj.Label)
continue
verts = []
edges = []
faces = []

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Original code by (C) 2019 yorikvanhavre <yorik@uncreated.net>
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import FreeCAD
def is_object_solid(obj):
"""If obj is solid return True"""
if not isinstance(obj, FreeCAD.DocumentObject):
return False
if not hasattr(obj, 'Shape'):
return False
if not hasattr(obj.Shape, 'Solids'):
return False
if len(obj.Shape.Solids) == 0:
return False
return True