mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Fix #4340. Indicate user needs to setup IFC2X3 user/app when using API directly.
This commit is contained in:
@@ -48,7 +48,7 @@ class Usecase:
|
|||||||
software library and will not know what application the API is being
|
software library and will not know what application the API is being
|
||||||
called from, and nor does it have the responsibility to manage the
|
called from, and nor does it have the responsibility to manage the
|
||||||
"active user" making edits, which may be as simple as hardcoding it to
|
"active user" making edits, which may be as simple as hardcoding it to
|
||||||
"Bob" or even be as complex as integrationg with a CDE's authentication
|
"Bob" or even be as complex as integration with a CDE's authentication
|
||||||
system. As a result, the developer responsible to integrate with
|
system. As a result, the developer responsible to integrate with
|
||||||
IfcOpenShell is expected to overload the
|
IfcOpenShell is expected to overload the
|
||||||
ifcopenshell.api.owner.settings.get_user and
|
ifcopenshell.api.owner.settings.get_user and
|
||||||
@@ -106,26 +106,14 @@ class Usecase:
|
|||||||
application = ifcopenshell.api.owner.settings.get_application(self.file)
|
application = ifcopenshell.api.owner.settings.get_application(self.file)
|
||||||
if self.file.schema != "IFC2X3" and not application:
|
if self.file.schema != "IFC2X3" and not application:
|
||||||
return
|
return
|
||||||
try:
|
return self.file.create_entity(
|
||||||
return self.file.create_entity(
|
"IfcOwnerHistory",
|
||||||
"IfcOwnerHistory",
|
OwningUser=user,
|
||||||
**{
|
OwningApplication=application,
|
||||||
"OwningUser": user,
|
State="READWRITE",
|
||||||
"OwningApplication": application,
|
ChangeAction="ADDED",
|
||||||
"State": "READWRITE",
|
LastModifiedDate=int(time.time()),
|
||||||
"ChangeAction": "ADDED",
|
LastModifyingUser=user,
|
||||||
"LastModifiedDate": int(time.time()),
|
LastModifyingApplication=application,
|
||||||
"LastModifyingUser": user,
|
CreationDate=int(time.time()),
|
||||||
"LastModifyingApplication": application,
|
)
|
||||||
"CreationDate": int(time.time()),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
# clarification message because error may come out of blue for users
|
|
||||||
# first time they try to create_entity in IFC2X3
|
|
||||||
if self.file.schema == "IFC2X3" and (application is None or user is None):
|
|
||||||
raise Exception(
|
|
||||||
"In IFC2X3 setting up owner history mandatory but it cannot be setup because either user or application is not set. "
|
|
||||||
"See an example in the owner.create_owner_history documentation."
|
|
||||||
)
|
|
||||||
raise e
|
|
||||||
|
|||||||
@@ -30,7 +30,13 @@ def get_application(ifc):
|
|||||||
:return: The IfcApplication with metadata of the authoring software.
|
:return: The IfcApplication with metadata of the authoring software.
|
||||||
:rtype: ifcopenshell.entity_instance.entity_instance
|
:rtype: ifcopenshell.entity_instance.entity_instance
|
||||||
"""
|
"""
|
||||||
return (ifc.by_type("IfcApplication") or [None])[0]
|
app = ifc.by_type("IfcApplication")
|
||||||
|
if not app and ifc.schema == "IFC2X3":
|
||||||
|
raise Exception(
|
||||||
|
"Please create an application to continue. See the owner.create_owner_history docs for more info."
|
||||||
|
"https://blenderbim.org/docs-python/autoapi/ifcopenshell/api/owner/create_owner_history/index.html"
|
||||||
|
)
|
||||||
|
return (app or [None])[0]
|
||||||
|
|
||||||
|
|
||||||
def get_user(ifc):
|
def get_user(ifc):
|
||||||
@@ -44,7 +50,13 @@ def get_user(ifc):
|
|||||||
:return: The IfcPersonAndOrganization with metadata of the authoring user.
|
:return: The IfcPersonAndOrganization with metadata of the authoring user.
|
||||||
:rtype: ifcopenshell.entity_instance.entity_instance
|
:rtype: ifcopenshell.entity_instance.entity_instance
|
||||||
"""
|
"""
|
||||||
return (ifc.by_type("IfcPersonAndOrganization") or [None])[0]
|
pao = ifc.by_type("IfcPersonAndOrganization")
|
||||||
|
if not pao and ifc.schema == "IFC2X3":
|
||||||
|
raise Exception(
|
||||||
|
"Please create a user to continue. See the owner.create_owner_history docs for more info."
|
||||||
|
"https://blenderbim.org/docs-python/autoapi/ifcopenshell/api/owner/create_owner_history/index.html"
|
||||||
|
)
|
||||||
|
return (pao or [None])[0]
|
||||||
|
|
||||||
|
|
||||||
get_application_factory = get_application
|
get_application_factory = get_application
|
||||||
|
|||||||
Reference in New Issue
Block a user