Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open Source Ifc Property Viewer

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
GeomGym
2205 Views, 9 Replies

Open Source Ifc Property Viewer

I'm involved in an open source project that might be of interest and benefit to other Revit API developers.

 

It's available in an infant form at https://github.com/jmirtsch/RevitIfcPropertyBrowser

 

Primarily it's a replica of the Revit property browser, when you select a single element or multiple elements, it displays the appropriate IFC properties as would be generated when exporting to IFC (Industry Foundation Class openBIM format).  An image is below.

 

There are many planned improvements for this project, including the ability to edit the revit parameters from the IFC properties (which permits the opportunity for some more interesting user interface controls for doing so).

 

I will be posting some related questions and suggestions here in the following posts.

 

Cheers,

 

Jon

 

171208 ifc property browser.png

9 REPLIES 9
Message 2 of 10
GeomGym
in reply to: GeomGym

First question related to the property browser.  It works well in the event of a user selecting an element (or multiple).

 

But I can't find any way to detect when elements are unselected.  The browser retains the previous state.

 

Any suggestions for changes to the code to identify this situation?

 

Thanks,

 

Jon

Message 3 of 10
romain.darocha
in reply to: GeomGym

Currently, I'm doing it by using the Idling event.

UiControlledApplication.Idling += OnIdling;

internal static void OnIdling(object sender, IdlingEventArgs args) { var uiApplication = (UIApplication) sender; if (uiApplication.ActiveUIDocument == null) return; var selection = uiApplication.ActiveUIDocument.Selection; var oldValues = _selectedIds; var newValues = selection.GetElementIds(); //Do what you want next }


from there, you can retreive old selection, new one, compare them, and know what elements are selected/unselected

Message 4 of 10
GeomGym
in reply to: romain.darocha

That's a great suggestion.  I will look at implementing it ASAP.

Message 5 of 10
aignatovich
in reply to: GeomGym

Hi!

 

You are already using IExternalEvent. It can be raised from whatever you want, for example by .Net timer or another thread. I don't like Idle event and I am trying to avoid it due to performance reason.

Message 6 of 10

I mostly agree with you.

Idling event must be used with caution. Each registered event will be called repeatedly, unless you let the event remove itself. So you shouldn't register an event with an heavy workload. However, comparing selected ids is rather quick, and it's possible to do it in an async task.

Moreover, if you need a a specific context that need to be constantly updated following the user selection, the idling event is probably the best way to do it.

Message 7 of 10
romain.darocha
in reply to: GeomGym

 public static class RevitSelection
    {
        private static int[] _selectedIds = new int[0];

        public static EventHandler<RevitSelectionChangedArgs> SelectionChanged;
        internal static Selection Selection { get; private set; }
        public static int[] SelectedIds
        {
            get => _selectedIds;
            set
            {
                var oldValues = _selectedIds;

                if (oldValues.All(value.Contains) && oldValues.Length == value.Length)
                    return;

                _selectedIds = value;
                Selection.SetElementIds(_selectedIds.Select(e => new ElementId(e)).ToArray());
                SelectionChanged?.Invoke(null, new RevitSelectionChangedArgs(oldValues, value));
            }
        }

        internal static void OnIdling(object sender, IdlingEventArgs args)
        {
            var uiApplication = (UIApplication) sender;

            if (uiApplication.ActiveUIDocument == null)
                return;

            Selection = uiApplication.ActiveUIDocument.Selection;

            var oldValues = _selectedIds;
            var newValues = Selection.GetElementIds().Select(e => e.IntegerValue).ToArray();

            if (oldValues.All(newValues.Contains) && oldValues.Length == newValues.Length)
                return;

            _selectedIds = newValues;
            SelectionChanged?.Invoke(null, new RevitSelectionChangedArgs(oldValues, newValues));
        }
    }    

    public class RevitSelectionChangedArgs : EventArgs
    {
        internal RevitSelectionChangedArgs(int[] oldSelection, int[] newSelection)
        {
            OldSelection = oldSelection;
            NewSelection = newSelection;
        }

        public int[] OldSelection { get; }
        public int[] NewSelection { get; }
    }

This is the selection context class that I'm using in my plugin. It always worked well without performance issues for me.

Message 8 of 10
duncan.lithgow
in reply to: GeomGym

@GeomGym

Hi Jon, does anything like this exist now?

Message 9 of 10
GeomGym
in reply to: duncan.lithgow

Sorry, I haven't touched this particular project in some time, and there's a few other developments that are a higher priority to pursue at present.  It is open source, so it should still work and others can work on it.

Message 10 of 10
duncan.lithgow
in reply to: GeomGym

@GeomGym with the current interest in incremental exchange of partial IFC data this is going to become more important.

 

https://community.osarch.org/discussion/comment/12981/#Comment_12981

https://github.com/brunopostle/ifcmerge

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community