How to get imported Categories

How to get imported Categories

Anonymous
Not applicable
2,555 Views
1 Reply
Message 1 of 2

How to get imported Categories

Anonymous
Not applicable

Hi,

 

In Revit Graphics/Visibility Overrides dialog, I can see the Imported Categories tab.

2016-07-28_1818.png

In API Category has a property CategoryType which is Enum with the following values:

  • Invalid
  • Model
  • Annotation
  • Internal
  • AnalyticalModel

Looks like CategoryType corresponds the tabs in Dialog, but not. Imported Categories also have CategoryType = CategoryType.Model, but not appear in the Model Categories tab.

 

Is there a way to find out whether a category is Imported or not?

 

I actually found two ways. The first on is implicit. I just looked into RevitLookup and checked the properties of Imported category:

2016-07-28_1823.png

I noticed the following:

  • Category.Id is not BuiltInCategory, i.e. value > 0
  • Properties AllowsBoundParameters, CanAddSubcategory, HasMaterialQuantities and IsCuttable are always false for imported categories.

As a result, I cretaed the extension method:

    public static class CategoryExtenstions
    {
        public static bool IsImportedCategory(this Category category)
        {
            if (Enum.IsDefined(typeof(BuiltInCategory), category.Id.IntegerValue))
                return false;

            if (category.Id.IntegerValue < -1)
                return false;

            return category.AllowsBoundParameters == false &&
                category.CanAddSubcategory == false &&
                category.HasMaterialQuantities == false &&
                category.IsCuttable == false;
        }
    }

It works. I tested it only for couple models. But want to now is it reliable method or not?

 

The second one is more complicated, but gave for me the same result.

Searching by keyword "Imported" in Revit API help, I've found the only enum member:

2016-07-28_1829.png

Sounds like this is exactly that I need.

 

This enum member is related with DWG Export Options. In UI we can find it in DWG Export Settings dialog:

2016-07-28_1831.png

 

I will not provide the code snippet for this approach. It is really much complicated and gives the same result.

 

Are there other ways to find out Imported Categories? Definitely internally Revit knows about that, but how to get this info in API? Or I have already found this way? 🙂

 

Thanks,

Victor.

2,556 Views
1 Reply
Reply (1)
Message 2 of 2

JimJia
Alumni
Alumni

Dear Victor,

 

Thanks for deep investigation and sharing!

 

Yet another approach you may consider to try is ExternalFileReference related: the imported instances are ExternalFileReference, you can use ExternalFileReferenceType to distinguish them. ExternalFileUtils.GetAllExternalFileReferences() can get all the ExternalFileReference's Id.

Following is simple sample snippet, do you think this is useful? 

private void GetExternalFileCategory()
{
string info = null;
ICollection<ElementId> ids = ExternalFileUtils.GetAllExternalFileReferences(doc);
foreach(ElementId id in ids)
{
Element elem = doc.GetElement(id);
if(elem.Category!= null)
info += elem.Category.Name + "\n";
}
MessageBox.Show(info);
}


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes