80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
#
|
|
# Copyright (C) 2021-2024 Robossembler LLC
|
|
#
|
|
# Created by Ilia Kurochkin (brothermechanic)
|
|
# contact: brothermechanic@yandex.com
|
|
#
|
|
# This file is part of Robossembler Framework
|
|
# project repo: https://gitlab.com/robossembler/framework
|
|
#
|
|
# Robossembler Framework 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.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
# ***** END GPL LICENSE BLOCK *****
|
|
#
|
|
# coding: utf-8
|
|
'''
|
|
DESCRIPTION.
|
|
Solid tools for FreeCAD's .FCStd scene.
|
|
'''
|
|
__version__ = '0.2'
|
|
|
|
import logging
|
|
import FreeCAD
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
def is_object_solid(obj) -> bool:
|
|
'''
|
|
Simple FreeCAD's object test for manifold mawater-tight surface.
|
|
|
|
:param obj: part, FreeCAD Part::Feature object
|
|
:returns: boolean of obj solid state
|
|
'''
|
|
if not isinstance(obj, FreeCAD.DocumentObject):
|
|
return False
|
|
|
|
if not hasattr(obj, 'Shape'):
|
|
return False
|
|
|
|
return obj.Shape.isClosed()
|
|
|
|
|
|
def collect_clones(doc=FreeCAD.getDocument(FreeCAD.ActiveDocument.Label)) -> list:
|
|
'''
|
|
This script find equal cad parts in a FreeCAD .FCStd scene.
|
|
|
|
:param doc: document, freecad opened scene (or current scene)
|
|
:returns: list with clones sublists [['c0'], ['c1', 'c2', 'c4'],]
|
|
'''
|
|
doc_clones = []
|
|
for item in doc.Objects:
|
|
if not is_object_solid(item):
|
|
continue
|
|
item_clones = []
|
|
item_clones.append(item.Label)
|
|
for other in doc.Objects:
|
|
if other == item:
|
|
continue
|
|
if other.Shape.isPartner(item.Shape):
|
|
logger.info('%s and %s objects has equal Shapes',
|
|
item.Label, other.Label)
|
|
item_clones.append(other.Label)
|
|
item_clones.sort()
|
|
if item_clones not in doc_clones:
|
|
doc_clones.append(item_clones)
|
|
return doc_clones
|