What exactly are you trying to accomplish? You can already control and override linked CAD file layers in Visibility/Graphics.
I need to automate display of specific layers - we are modelling based on drawings from architect, mech and structural engineer and need to quickly layer each discipline on and off. Going via vg is time consuming as there are hundreds of layers to scroll through.
I have managed to find the layer table in the cad link - now I am stuck on how to control the visibility of the cadlink layer in the active view... As a newbie to revit API and C# this has taken a surprising amount of time even to get this far... so my apologies if this is a stupid question. The API documentation doesn't really give a high level overview of how things like cadLinks are stored in the database - if such an overview exists I would love to read it...
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
var collector = new FilteredElementCollector(doc);
var cadLinks = collector
.OfClass(typeof(CADLinkType))
.OfType<CADLinkType>()
.Where(x => x.IsExternalFileReference())
.ToList();
foreach (var cadLink in cadLinks)
{
Debug.Print(cadLink.Name);
// the cadLink layer table in in Category->Subcategory
CategoryNameMap linklayertable = cadLink.Category.SubCategories;
foreach (Category layer in linklayertable )
{
string layerName = layer.Name;
Debug.Print(layerName);
}
}
using (Transaction tx = new Transaction(doc))
{
tx.Start("Transaction Name");
tx.Commit();
}
return Result.Succeeded;
}
}
View.SetCategoryHidden
Category.Visible
I believe the above follows the same approach as is used with visibility graphics in the UI so should work.
There was an issue with visibility by category in general and the suggestion for that was to hide temporarily but you can't do that for import instances in the UI so would not expect that to work with the equivalent API call but only testing will confirm.