mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-30 12:09:51 +00:00
Instead of using a template ifc file, ifccityjson now uses ifcopenshell.api to create a new file for conversion
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import warnings
|
import ifcopenshell.api
|
||||||
from geometry import GeometryIO
|
from geometry import GeometryIO
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
JSON_TO_IFC = {
|
JSON_TO_IFC = {
|
||||||
"Building": ["IfcBuilding"],
|
"Building": ["IfcBuilding"],
|
||||||
@@ -45,6 +46,7 @@ class Cityjson2ifc:
|
|||||||
def convert(self, city_model):
|
def convert(self, city_model):
|
||||||
self.city_model = city_model
|
self.city_model = city_model
|
||||||
self.create_new_file()
|
self.create_new_file()
|
||||||
|
self.write_file()
|
||||||
self.create_metadata()
|
self.create_metadata()
|
||||||
self.geometry.build_vertices(self.IFC_model,
|
self.geometry.build_vertices(self.IFC_model,
|
||||||
coords=city_model.j["vertices"],
|
coords=city_model.j["vertices"],
|
||||||
@@ -73,14 +75,38 @@ class Cityjson2ifc:
|
|||||||
crs = self.IFC_model.create_entity("IfcProjectedCrs", Name=f"epsg:{epsg}")
|
crs = self.IFC_model.create_entity("IfcProjectedCrs", Name=f"epsg:{epsg}")
|
||||||
self.IFC_model.create_entity("IfcMapConversion", self.IFC_representation_context, **self.properties["local_translation"])
|
self.IFC_model.create_entity("IfcMapConversion", self.IFC_representation_context, **self.properties["local_translation"])
|
||||||
|
|
||||||
self.properties["owner_history"] = self.IFC_model.by_type("IfcOwnerHistory")[0]
|
|
||||||
|
|
||||||
def create_new_file(self):
|
def create_new_file(self):
|
||||||
self.IFC_model = ifcopenshell.open('example/template.ifc')
|
self.IFC_model = ifcopenshell.api.run("project.create_file")
|
||||||
self.IFC_site = self.IFC_model.by_type('IfcSite')[0]
|
self.IFC_project = ifcopenshell.api.run("root.create_entity", self.IFC_model, **{"ifc_class": "IfcProject"})
|
||||||
self.IFC_representation_sub_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONSUBCONTEXT")[0]
|
self.properties["owner_history"] = self.create_owner_history()
|
||||||
self.IFC_representation_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONCONTEXT")[0]
|
self.IFC_representation_context = ifcopenshell.api.run("context.add_context", self.IFC_model,
|
||||||
# self.IFC_model = ifcopenshell.file(schema='IFC4')
|
**{"context": "Model"})
|
||||||
|
self.IFC_representation_sub_context = ifcopenshell.api.run("context.add_context", self.IFC_model,
|
||||||
|
**{"context": "Model",
|
||||||
|
"subcontext": "Body", # LODs as subcontext
|
||||||
|
"target_view": "MODEL_VIEW"})
|
||||||
|
|
||||||
|
self.IFC_site = ifcopenshell.api.run("root.create_entity", self.IFC_model,
|
||||||
|
**{"ifc_class": "IfcSite",
|
||||||
|
"name": "My Site"})
|
||||||
|
|
||||||
|
# self.IFC_representation_sub_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONSUBCONTEXT")[0]
|
||||||
|
# self.IFC_representation_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONCONTEXT")[0]
|
||||||
|
|
||||||
|
def create_owner_history(self):
|
||||||
|
actor = self.IFC_model.createIfcActorRole("ENGINEER", None, None)
|
||||||
|
person = self.IFC_model.createIfcPerson("Oostwegel", None, "L.J.N.", None, None, None, (actor,))
|
||||||
|
organization = self.IFC_model.createIfcOrganization(
|
||||||
|
None,
|
||||||
|
"IfcOpenShell",
|
||||||
|
"IfcOpenShell, an open source (LGPL) software library that helps users and software developers to work with the IFC file format.",
|
||||||
|
)
|
||||||
|
p_o = self.IFC_model.createIfcPersonAndOrganization(person, organization)
|
||||||
|
application = self.IFC_model.createIfcApplication(organization, "v0.0.x", "ifccityjson", "ifccityjson")
|
||||||
|
timestamp = int(datetime.now().timestamp())
|
||||||
|
ownerHistory = self.IFC_model.createIfcOwnerHistory(p_o, application, "READWRITE", None, None, None, None, timestamp)
|
||||||
|
|
||||||
|
return ownerHistory
|
||||||
|
|
||||||
def write_file(self):
|
def write_file(self):
|
||||||
self.IFC_model.write(self.properties["file_destination"])
|
self.IFC_model.write(self.properties["file_destination"])
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,39 +0,0 @@
|
|||||||
ISO-10303-21;
|
|
||||||
HEADER;
|
|
||||||
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
|
|
||||||
FILE_NAME('template.ifc','2021-03-17T14:54:00+11:00',(),(),'IfcOpenShell 0.6.0b0','BlenderBIM 0.0.999999','Nobody');
|
|
||||||
FILE_SCHEMA(('IFC4'));
|
|
||||||
ENDSEC;
|
|
||||||
DATA;
|
|
||||||
#1=IFCPERSON('HSeldon','Seldon','Hari',$,$,$,$,$);
|
|
||||||
#2=IFCORGANIZATION('APTR','Aperture Science',$,$,$);
|
|
||||||
#3=IFCPERSONANDORGANIZATION(#1,#2,$);
|
|
||||||
#4=IFCACTORROLE(.USERDEFINED.,'CONTRIBUTOR',$);
|
|
||||||
#5=IFCTELECOMADDRESS(.USERDEFINED.,'The main webpage of the software collection.','WEBPAGE',$,$,$,$,'https://ifcopenshell.org',$);
|
|
||||||
#6=IFCTELECOMADDRESS(.USERDEFINED.,'The CJ2IFC webpage of the software collection.','WEBPAGE',$,$,$,$,'https://github.com/LaurensJN/IFC2JS',$);
|
|
||||||
#7=IFCTELECOMADDRESS(.USERDEFINED.,'The source code repository of the software collection.','REPOSITORY',$,$,$,$,'https://github.com/IfcOpenShell/IfcOpenShell.git',$);
|
|
||||||
#8=IFCORGANIZATION($,'IfcOpenShell','IfcOpenShell is an open source (LGPL) software library that helps users and software developers to work with the IFC file format.',(#4),(#5,#6,#7));
|
|
||||||
#9=IFCAPPLICATION(#8,'0.0.999999','CityJSON to IFC converter','CJ2IFC');
|
|
||||||
#10=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
|
||||||
#11=IFCPROJECT('2yjpApQSX3ZAZudc2AGHb3',#10,'My Project',$,$,$,$,(#20,#27),#15);
|
|
||||||
#12=IFCSIUNIT(*,.LENGTHUNIT.,$,.METRE.);
|
|
||||||
#13=IFCSIUNIT(*,.AREAUNIT.,$,.SQUARE_METRE.);
|
|
||||||
#14=IFCSIUNIT(*,.VOLUMEUNIT.,$,.CUBIC_METRE.);
|
|
||||||
#15=IFCUNITASSIGNMENT((#12,#13,#14));
|
|
||||||
#16=IFCCARTESIANPOINT((0.,0.,0.));
|
|
||||||
#17=IFCDIRECTION((0.,0.,1.));
|
|
||||||
#18=IFCDIRECTION((1.,0.,0.));
|
|
||||||
#19=IFCAXIS2PLACEMENT3D(#16,#17,#18);
|
|
||||||
#20=IFCGEOMETRICREPRESENTATIONCONTEXT($,'Model',3,1.E-05,#19,$);
|
|
||||||
#21=IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Body','Model',*,*,*,*,#20,$,.MODEL_VIEW.,$);
|
|
||||||
#22=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
|
||||||
#23=IFCSITE('1maxFQa9z7q8w50tN19Dw9',#22,'My Site',$,$,#30,$,$,$,$,$,$,$,$);
|
|
||||||
#24=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
|
||||||
#25=IFCRELAGGREGATES('1GuJ2jz2TA49gFFSYhrqGa',#24,$,$,#11,(#23));
|
|
||||||
#26=IFCCARTESIANPOINT((0.,0.,0.));
|
|
||||||
#27=IFCDIRECTION((0.,0.,1.));
|
|
||||||
#28=IFCDIRECTION((1.,0.,0.));
|
|
||||||
#29=IFCAXIS2PLACEMENT3D(#26,#27,#28);
|
|
||||||
#30=IFCLOCALPLACEMENT($,#29);
|
|
||||||
ENDSEC;
|
|
||||||
END-ISO-10303-21;
|
|
||||||
Reference in New Issue
Block a user