FreeCAD: add collect_clones function in freecad_to_json WIP
This commit is contained in:
parent
bce317a554
commit
cc538b719f
3 changed files with 86 additions and 30 deletions
|
@ -24,7 +24,9 @@ import Mesh
|
||||||
import MeshPart
|
import MeshPart
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
from freecad.utils.is_object_solid import is_object_solid
|
|
||||||
|
from freecad.utils.solid_tools import (is_object_solid, collect_clones)
|
||||||
|
|
||||||
from utils.custom_parser import CustomArgumentParser
|
from utils.custom_parser import CustomArgumentParser
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -39,6 +41,9 @@ def freecad_to_json(**kwargs):
|
||||||
doc = FreeCAD.open(kwargs['fcstd_path'])
|
doc = FreeCAD.open(kwargs['fcstd_path'])
|
||||||
docname = doc.Name
|
docname = doc.Name
|
||||||
|
|
||||||
|
# collect equal cad objects
|
||||||
|
clones = collect_clones(doc):
|
||||||
|
|
||||||
# collect all materials
|
# collect all materials
|
||||||
fem_mats = []
|
fem_mats = []
|
||||||
for fem_mat in doc.Objects:
|
for fem_mat in doc.Objects:
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
# coding: utf-8
|
|
||||||
# Copyright (C) 2023 Ilia Kurochkin <brothermechanic@yandex.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.
|
|
||||||
'''
|
|
||||||
DESCRIPTION.
|
|
||||||
Simple FreeCAD's object test for manifold mawater-tight surface.
|
|
||||||
'''
|
|
||||||
__version__ = '0.2'
|
|
||||||
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
|
|
||||||
|
|
||||||
return obj.Shape.isClosed()
|
|
80
cg/freecad/utils/solid_tools.py
Normal file
80
cg/freecad/utils/solid_tools.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
# ***** 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
|
Loading…
Add table
Add a link
Reference in a new issue