Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XBim have “IfcStore.AddModelReference” API,but where is the "Remove ModelReference" API ? #515

Open
lhx24 opened this issue Aug 8, 2023 · 3 comments

Comments

@lhx24
Copy link

lhx24 commented Aug 8, 2023

XBim have “IfcStore.AddModelReference” API,but where is the "Remove ModelReference" API ?

@andyward andyward transferred this issue from xBimTeam/XbimWindowsUI Aug 8, 2023
@andyward
Copy link
Member

andyward commented Aug 8, 2023

Moved from Windows UI project.

Looks like it didn't get thought about....

You could implement as a simple extension method with a couple of lines of code:

    public static class IfcStoreFederationExtensions
    {
        public static bool RemoveModelReference(this IfcStore store, IReferencedModel model)
        {
            var referenced = store.ReferencedModels as ReferencedModelCollection;

            return referenced!.Remove(model);
        }
    }

    // then call like this
    var toRemove = model.ReferencedModels.First(m => m.Name == "yourModelToRemove");
    myStore.RemoveModelReference(toRemove),

Happy to take a PR if you want to add it formally

@lhx24
Copy link
Author

lhx24 commented Aug 9, 2023

Thank you very much for your response. I have tried the code you provided and also studied the source code. The ReferencedModelCollection contains two parts: one is stored in the IFC file, and the other is in the ReferencedModelCollection itself. So, removing the model reference using RemoveModelReference still keeps the graphical representation in the UI, and the link document is still present when opening the IFC file again. Therefore, it is necessary to delete the link information within the IFC file as well. Below is my code, please feel free to provide any suggestions for improvement.

Xbim.Ifc4.ExternalReferenceResource.IfcDocumentInformation document = refence.DocumentInformation as Xbim.Ifc4.ExternalReferenceResource.IfcDocumentInformation;
if (document != null)
{
    Xbim.Ifc4.ActorResource.IfcOrganization owner = document.DocumentOwner as Xbim.Ifc4.ActorResource.IfcOrganization;
    if (owner != null)
    {
        if (owner.Roles != null && owner.Roles.Count == 1)
        {
            modelIFC.Delete(owner.Roles[0]);
        }
        modelIFC.Delete(owner);
    }
    modelIFC.Delete(document);
}

@andyward
Copy link
Member

andyward commented Aug 9, 2023

OK, that makes sense. I won't profess to being that familiar with this code

That will only work for IFC4 schema (not Ifc2x3, 4.3 etc). if you cast to IIfcDocumentationInfo and IIfcOrganization it should work across schemas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants