SelectionSet.ExplicitModelItems throwing an exception that "InvalidOperationException"

SelectionSet.ExplicitModelItems throwing an exception that "InvalidOperationException"

mukund.thakare
Enthusiast Enthusiast
1,910 Views
6 Replies
Message 1 of 7

SelectionSet.ExplicitModelItems throwing an exception that "InvalidOperationException"

mukund.thakare
Enthusiast
Enthusiast

Hello Forum,
I have created SelectionSets of the ModelItems on the basis of Revit family type and provided display name as same Revit family type. for example if Revit family type is "Walls" then I am making one selection set of all the walls in model and naming this selection set as Walls.
For an exercise I wanted Revit ID's of all the walls, So I used the property of SelectionSet called "ExplicitModelItems"
code-

1.ModelItemCollection mic = set.ExplicitModelItems;

2.foreach(ModelItem item in mic){

3.    getRevitID(item);

4. }
But at line 1 it throws an exception "InvalidOperationException".
I searched API doc's and it says this property throws an exception when  when  property name '!HasExplicitModelItems'  is false.

 

Forum is there any specific reason for this exception to occur ?
On the other hand my selection set is not empty and fortunately in API doc's I found one method "SelectionSet.GetSelectedItems(ActiveDoc)" which returns ModelItemCollection of ModelItem in SelectionSet.
So I was able to carry out my exercise completely.

But Why this property is null ?
Becuase I have Observed same thing for ModelItem.Model property, When I try to access the model from modelItem. it returns null.
 

0 Likes
Accepted solutions (1)
1,911 Views
6 Replies
Replies (6)
Message 2 of 7

alexisDVJML
Collaborator
Collaborator

Is the SelectionSet you created a Search type or an Explicit Type?
If of the Search type, the behaviour you describe is expected 😉

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 3 of 7

mukund.thakare
Enthusiast
Enthusiast

Thanks for reply @alexisDVJML .
Yes they are of Search type.
But how does it make difference ? Since I am asking for ModelItem of single same model.
How search type and explicit type is different ?

Thanks in advance !!

0 Likes
Message 4 of 7

alexisDVJML
Collaborator
Collaborator
Accepted solution

Search Type store the search, not the items, and the items resulting from this search can be obtained by calling the GetSelectedItems(ActiveDoc) as you did.

 

These are not "cached" in ExplicitModelItems which apply only for Explicit Selection Set type, as I think is explicit by the name of the method 😉

 

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 5 of 7

mukund.thakare
Enthusiast
Enthusiast

Hello @alexisDVJML .
I think so Understood the behaviors and difference between Search types and Explicit Models Items.
Thanks.
Is this same behavior responsible for the following scenario ?
1) I have Clash results and from results I am accessing each ModelItem which is clashing and by using Items Parent Property categories I am able to get the RevitID of element.
But on other hand if I normally take ModelItem (From selection set or from any other model item which is not involve in clash detection ) I can Extract The RevitID from Properties of Item but not from It's parent Properties.

Why this difference ? Why I Can't just Get RevitID from element itself when I am doing clash detection ? 
 
  Thanks in advance !!.

0 Likes
Message 6 of 7

alexisDVJML
Collaborator
Collaborator

I have not played with Clash features programmatically yet, so I just can give a wide guess 😉
Maybe class selection is actually the list of the geometries that clashes so you need to go to the geometry parent to get the properties while in the other cases you directly get the object that contains the properties. Or the opposite 😉

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 7 of 7

mukund.thakare
Enthusiast
Enthusiast

@alexisDVJML  Thanks for your wide guess 😃. It's Understandable and digestible.

0 Likes