0

I am a beginner in Revit Api and trying to keep up with the upcoming project which relates to manipulating extensible storage. I have received an example code from a senior dev that try to get the extensible storage from an element as follow:

// _schema is known
Entity ent = element.GetEntity(_schema);
if (ent?.Schema != null)
{
// code to retrieve extensible storage here
// produce correct result
}

and I try to replace the snip set with my amateur code:

Entity ent = element.GetEntity(_schema);
if (ent != null && ent.IsValidObject)
{
// code to retrieve extensible storage here
// my code produces incorrect results   
}

What are the differences between these 2 snip set? if I retrieve the entity using a certain schema, then the entity.Schema must return the same schema, is that correct? why do I have to check the Schema of the entity again to get the correct result? Thank you all for your time. Your answer will help me a great deal in my upcoming project.

Thế Long
  • 516
  • 7
  • 19

1 Answers1

1

You code looks more sensible and reliable. Checking the schema of an entity that was retrieved specifying a schema does indeed not make sense. I do not understand the meaning of the comments, however.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • I 'm sorry for the confusion because I am not a native English speaker. I thought the same thing as you do at first, but my senior 's code produce a more reliable and accurate result. In this case, it suppose to be only 1 result (which my senior 's code does) while my code produces way more results , and all of them are incorrect. My guess is that the input schema (_schema) and the Entity schema (Entity.Schema) is not necessarily the same one. – Thế Long Dec 12 '17 at 14:42
  • I 've read about the schema is saved in revit (it persists through the entire session) and may not be valid in the current drawing/document. If that was the case, then my code should not be retrieve an un-null and valid entity. I just hope someone can clear my thought. p/s: I 've also edited the comments in my post for better understanding. Hope that helps. – Thế Long Dec 12 '17 at 14:46