mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-31 17:06:29 +00:00
IfcPatch ReplaceDrawingPath recipie improved: now it's possible to use it on Linux and on Windows
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
|
from sys import platform
|
||||||
|
|
||||||
class Patcher:
|
class Patcher:
|
||||||
def __init__(self, src, file, logger):
|
def __init__(self, src, file, logger):
|
||||||
@@ -25,7 +27,9 @@ class Patcher:
|
|||||||
drawig in linux.
|
drawig in linux.
|
||||||
In this case, blenderbim would tell you that can't load "stylesheet" or "markers" or "symbols" or "patterns" folder.
|
In this case, blenderbim would tell you that can't load "stylesheet" or "markers" or "symbols" or "patterns" folder.
|
||||||
If this happens, this recipie comes in rescue!
|
If this happens, this recipie comes in rescue!
|
||||||
Basically, as the path is stored in a strig, the recipie replace the existing sep char with the right one.
|
Basically, as the path is stored in a string, the recipie replace the existing sep char with the right one.
|
||||||
|
It doesn't need to specify the ifc output file or any arguments.
|
||||||
|
If ifc ouput file is specified, it saves the patched file in the new file.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -48,76 +52,15 @@ class Patcher:
|
|||||||
psets = ifcopenshell.util.element.get_psets(annotation)
|
psets = ifcopenshell.util.element.get_psets(annotation)
|
||||||
pset = psets['EPset_Drawing']
|
pset = psets['EPset_Drawing']
|
||||||
pset_ifc = self.file.by_id(pset['id'])
|
pset_ifc = self.file.by_id(pset['id'])
|
||||||
|
wrong_sep = ""
|
||||||
|
if platform == 'linux' or platform == 'linux2' or platform == 'darwin':
|
||||||
|
wrong_sep = "\\"
|
||||||
|
if platform == 'win32':
|
||||||
|
wrong_sep = "/"
|
||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset = pset_ifc, properties = {
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset = pset_ifc, properties = {
|
||||||
'Stylesheet' : pset['Stylesheet'].replace('\\', '/'),
|
'Stylesheet' : pset['Stylesheet'].replace(wrong_sep, os.path.sep),
|
||||||
'Markers' : pset['Markers'].replace('\\', '/'),
|
'Markers' : pset['Markers'].replace(wrong_sep, os.path.sep),
|
||||||
'Symbols' : pset['Symbols'].replace('\\', '/'),
|
'Symbols' : pset['Symbols'].replace(wrong_sep, os.path.sep),
|
||||||
'Patterns' : pset['Patterns'].replace('\\', '/'),
|
'Patterns' : pset['Patterns'].replace(wrong_sep, os.path.sep),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#class Patcher:
|
|
||||||
# def __init__(self, src, file, logger, output_dir=None):
|
|
||||||
# """Split an IFC model into multiple models based on building storey
|
|
||||||
#
|
|
||||||
# The new IFC model names will be named after the storey name in the
|
|
||||||
# format of {i}-{name}.ifc, where {i} is an ascending number starting from
|
|
||||||
# 0 and {name} is the name of the storey.
|
|
||||||
#
|
|
||||||
# :param output_dir: Specifies an output directory where the new IFC models will be saved.
|
|
||||||
# :type output_dir: str
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
#
|
|
||||||
# .. code:: python
|
|
||||||
#
|
|
||||||
# ifcpatch.execute({"input": model, "recipe": "SplitByBuildingStorey", "arguments": ["C:/.../output_files"]})
|
|
||||||
# """
|
|
||||||
# self.src = src
|
|
||||||
# self.file = file
|
|
||||||
# self.logger = logger
|
|
||||||
# self.output_dir = output_dir
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# def patch(self):
|
|
||||||
# import ifcopenshell
|
|
||||||
# from shutil import copyfile
|
|
||||||
#
|
|
||||||
# storeys = self.file.by_type("IfcBuildingStorey")
|
|
||||||
# for i, storey in enumerate(storeys):
|
|
||||||
# dest = "{}-{}.ifc".format(i, storey.Name) if self.output_dir == None else "{}/{}-{}.ifc".format(self.output_dir,i, storey.Name)
|
|
||||||
# copyfile(self.src, dest)
|
|
||||||
# old_ifc = ifcopenshell.open(dest)
|
|
||||||
# new_ifc = ifcopenshell.file(schema=self.file.schema)
|
|
||||||
# if self.file.schema == "IFC2X3":
|
|
||||||
# elements = old_ifc.by_type("IfcProject") + old_ifc.by_type("IfcProduct")
|
|
||||||
# else:
|
|
||||||
# elements = old_ifc.by_type("IfcContext") + old_ifc.by_type("IfcProduct")
|
|
||||||
# inverse_elements = []
|
|
||||||
# for element in elements:
|
|
||||||
# if element.is_a("IfcElement") and not self.is_in_storey(element, storey):
|
|
||||||
# element.Representation = None
|
|
||||||
# continue
|
|
||||||
# if element.is_a("IfcElement"):
|
|
||||||
# styled_rep_items = [
|
|
||||||
# i for i in old_ifc.traverse(element) if i.is_a("IfcRepresentationItem") and i.StyledByItem
|
|
||||||
# ]
|
|
||||||
# [new_ifc.add(i.StyledByItem[0]) for i in styled_rep_items]
|
|
||||||
# new_ifc.add(element)
|
|
||||||
# inverse_elements.extend(old_ifc.get_inverse(element))
|
|
||||||
# for inverse_element in inverse_elements:
|
|
||||||
# new_ifc.add(inverse_element)
|
|
||||||
# for element in new_ifc.by_type("IfcElement"):
|
|
||||||
# if not self.is_in_storey(element, storey):
|
|
||||||
# new_ifc.remove(element)
|
|
||||||
# new_ifc.write(dest)
|
|
||||||
#
|
|
||||||
# def is_in_storey(self, element, storey):
|
|
||||||
# return (
|
|
||||||
# element.ContainedInStructure
|
|
||||||
# and element.ContainedInStructure[0].RelatingStructure.is_a("IfcBuildingStorey")
|
|
||||||
# and element.ContainedInStructure[0].RelatingStructure.GlobalId == storey.GlobalId
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user