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

Deleting / Removing stuff from the xbim model #15

Closed
Jero9999 opened this issue Jan 17, 2016 · 8 comments
Closed

Deleting / Removing stuff from the xbim model #15

Jero9999 opened this issue Jan 17, 2016 · 8 comments
Assignees

Comments

@Jero9999
Copy link

Is there any plan to migrate the examples and documentation from version 2 to version 3?
My current issue is that I have to remove some elements out of an IFC model and I can't find a good way to do that.

Is there a forum or something that xBim users use. Google has not been my friend so far.

@CBenghi
Copy link
Member

CBenghi commented Jan 18, 2016

The logic for cascading the deletion of elements is quite complicated to manage.
I think your best approach for reducing files is to build a new ones copying the elements of interest.
Does this seam to be an acceptable approach to your case? If so ping us again here.
There's no strong place where the community meets other than here. We'll have to work on this.
Best,
Claudio

@CBenghi CBenghi self-assigned this Jan 18, 2016
@Jero9999
Copy link
Author

Thanks for the reply. I thought that might be the answer. I know about it being complicated to manage. That's pretty much why I was hoping you guys had already done it.
I agree with the copying relevant bits into a new model. I actually tried it using the XBimModel.InsertCopy() but I kept getting Assert errors. It looks like it is designed to do what I want though. Any suggestions?

_Model.CreateFrom(ifcFilename, xbimDbFilename, null, true, true);
var outputModel = new XbimModel();

using (var transaction = outputModel.BeginTransaction("add to representation"))
{
    outputModel.InsertCopy(_Model.IfcProject, transaction);
    outputModel.Validate(transaction.Modified(), Console.Out);
    transaction.Commit();
}

@CBenghi
Copy link
Member

CBenghi commented Feb 5, 2016

Apologies for the long wait, i'll be testing this in the next couple of days and come back to you.

@SteveLockley
Copy link
Member

Work has commenced to migrate samples. See the develop branch for the latest state, now we support Ifc4 the remainder will be migrated over, any help greatly appreciated

@martin1cerny
Copy link
Member

Shall we close this issue?

@Jero9999
Copy link
Author

Yup. No longer an issue

From: Martin Černý [mailto:[email protected]]
Sent: Wednesday, 16 March 2016 3:55 a.m.
To: xBimTeam/XbimEssentials [email protected]
Cc: jero [email protected]
Subject: Re: [XbimEssentials] Deleting / Removing stuff from the xbim model (#15)

Shall we close this issue?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#15 (comment)

@jojobs
Copy link

jojobs commented Oct 17, 2016

Hi Steve, Martin. Claudio,

I have similar problem, I want to filter walls and create the Spatial view.

I have used the following code, but it is not populating the tree (Only project number appears on the tree). Could you please help?

private void OpenIfcFile(object s, DoWorkEventArgs args)
{
var worker = s as BackgroundWorker;
var ifcFilename = args.Argument as string;

        var model = new XbimModel();
        var modelCopy = new XbimModel();
        try
        {
            _temporaryXbimFileName = Path.GetTempFileName();
            SetOpenedModelFileName(ifcFilename);             

            if (worker != null)
            {
                model.CreateFrom(ifcFilename, _temporaryXbimFileName, worker.ReportProgress, true);
                string tempFileName = "";
                modelCopy = XbimModel.CreateModel(tempFileName);

                modelCopy.AutoAddOwnerHistory = false;
                using (var txn = modelCopy.BeginTransaction())
                {
                    var copied = new XbimInstanceHandleMap(model, modelCopy);
                    //modelCopy.InsertCopy(model.IfcProject, txn);
                    foreach (var item in model.Instances)
                    {
                        var ifctype = item.IfcType();
                        if (ifctype.IfcTypeEnum == IfcEntityNameEnum.IFCPROJECT || 
                            ifctype.IfcTypeEnum == IfcEntityNameEnum.IFCBUILDING ||
                            ifctype.IfcTypeEnum == IfcEntityNameEnum.IFCBUILDINGSTOREY ||
                            ifctype.IfcTypeEnum == IfcEntityNameEnum.IFCSITE ||
                            ifctype.IfcTypeEnum == IfcEntityNameEnum.IFCWALLSTANDARDCASE )
                        {
                            modelCopy.InsertCopy(item, copied, txn, false);
                        }                        
                    }

                    txn.Commit();
                }

                var context = new Xbim3DModelContext(modelCopy);//upgrade to new geometry represenation, uses the default 3D model
                context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary,  progDelegate: worker.ReportProgress,  adjustWCS: false);

                if (worker.CancellationPending) //if a cancellation has been requested then don't open the resulting file
                {
                    try
                    {
                        model.Close();
                        if (File.Exists(_temporaryXbimFileName))
                            File.Delete(_temporaryXbimFileName); //tidy up;
                        _temporaryXbimFileName = null;
                        SetOpenedModelFileName(null);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message, ex);
                    }
                    return;
                }
            }
            args.Result = modelCopy;

        }
        catch (Exception ex)
        {
            var sb = new StringBuilder();
            sb.AppendLine("Error reading " + ifcFilename);
            var indent = "\t";
            while (ex != null)
            {
                sb.AppendLine(indent + ex.Message);
                ex = ex.InnerException;
                indent += "\t";
            }

            args.Result = new Exception(sb.ToString());
        }
    }

@andyward
Copy link
Member

Answered on #57

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

6 participants