xBimTeam / XbimWindowsUI

The home of XbimXplorer and WPF components for your desktop BIM applications.
Other
245 stars 149 forks source link

Highlight element #208

Closed ShehabFekry closed 11 months ago

ShehabFekry commented 11 months ago

Short summary describing the issue. (3-5 sentences) I have created a desktop application that compares the changes between two IFC files now I want to open the IFC windows viewer from that desktop application and press a button to highlight some global Ids that I already have.

Assemblies and versions affected:

Xbim.Essentials 4.0.29__*

Steps (or code) to reproduce the issue:

A simple set of steps to reproduce the issue. Provide a small sample file is required and/or a small sample of the failing code (or reference a commit / gist)



                using (var modelTwo = IfcStore.Open(FilePathOld))
                {

                    var element= modelTwo.Instances.OfType<IIfcElement>().First();
                   var id = element.GlobalId;

#### Expected behavior:

*What would you expect to happen*

I have a desktop application with some Ids that i've stored .. I want to have two buttons 
one button opening the xbim Xplorer in windows and loads the latest IFC file on it 

the second button highlights the elements with ids from the list that i will pass.
andyward commented 11 months ago

To get the element by GlobalId you want something like :

// yourGlobalId is defined
var element = modelTwo.Instances.OfType<IIfcElement>().FirstOrDefault(e => e.GlobalId == yourGlobalId)

To highlight entities, just add / remove the entities to the Selection collection on the DrawingControl3D instance

https://github.com/xBimTeam/XbimWindowsUI/blob/faa8e9450866f929c7514e2b4b18d285648ccf75/Xbim.Presentation/DrawingControl3D.xaml.cs#L911

e.g.

drawingControl.Selection.Add(element);
ShehabFekry commented 11 months ago

Thank You, I really appreciate your concern, this answers half of my question, the other have is how to open that IFC viewer application from a desktop application by clicking a button and give it a specific file path to load it? It would be very helpful if you could help me with that concern

ShehabFekry commented 11 months ago

I have managed to use the DrawingControl3D and view my model in my WPF application and it works very well. now I'm trying to select a list of IIfcElements but it's not selecting anything I have tried

IfcStore ifcModel = IfcStore.Open(@"FilePath");
            var context = new Xbim3DModelContext(ifcModel);
            context.CreateContext();
            var instances = ifcModel.Instances.OfType<IIfcElement>().Take(5).ToList();            
            DrawingControl.Model = ifcModel;
            DrawingControl.LoadGeometry(ifcModel);
            DrawingControl.SelectionBehaviour = DrawingControl3D.SelectionBehaviours.MultipleSelection;
            DrawingControl.AddRange(instances);

I have also tried DrawingControl.Add(instances[0]);

the only thing that is working and selecting is DrawingControl.SelectedEntity = instances[0]; but I need to select multiple elements not only one;

andyward commented 11 months ago

Check that instances contains some entities. (if not make sure you're importing the Ifc4 namespace for IIfcElement type)

Add the instances to the

DrawingControl.Selection.Add(instances[0]);

or

DrawingControl.Selection.AddRange(instances);

ShehabFekry commented 11 months ago

That solves the problem I was using Xbim.Ifc2x3.Interfaces; when I used ifc4 it worked very well .. thank Andy I appreciate it.