Home > other >  Get the view name of a CAD imports in Revit
Get the view name of a CAD imports in Revit

Time:09-23

I am making a list of CAD imports in a Revit project to include import ID, import name, view Id, and view name. I have 3 out of 4. I cannot get the view name from the view Id.

the filtered element collector gets import instances and returns import Id, import name, and view Id

public ObservableCollection<ImportWrapper> GetCadImport()
    {
        var colImportInstances = new FilteredElementCollector(Doc)
            .OfClass(typeof(ImportInstance))
            .Select(x => new ImportWrapper(x, null));

        return new ObservableCollection<ImportWrapper>(colImportInstances);
    }

        return new ObservableCollection<ImportWrapper>(colImportInstances);

the import wrapper passed into the observable collection is

public ImportWrapper(Element importInstance, View view)
    {
        ImportName = importInstance.Category.Name;
        ElementId = importInstance.Id;
        Doc = importInstance.Document;
        ViewId = importInstance?.OwnerViewId;
        var viewelement = Doc.GetElement(importInstance.OwnerViewId);
        var view = viewelement as View;
        ViewName = view?.Name;

    }

how can I get the view name from the ownerViewId here? I tried empty string and null but the view name is not reassigned

Thanks for any help!

CodePudding user response:

Use the OwnerViewId to open the corresponding View object and retrieve its Name property. Does that give you what you need?

  • Related