CADLink Layer Display

CADLink Layer Display

KRayJay
Participant Participant
349 Views
4 Replies
Message 1 of 5

CADLink Layer Display

KRayJay
Participant
Participant

Is there anything in the API that allows control of visibility of a layer in a CADLink?

0 Likes
350 Views
4 Replies
Replies (4)
Message 2 of 5

jorgedelacova7458
Advocate
Advocate

What exactly are you trying to accomplish? You can already control and override linked CAD file layers in Visibility/Graphics.

0 Likes
Message 3 of 5

KRayJay
Participant
Participant

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. 

0 Likes
Message 4 of 5

KRayJay
Participant
Participant

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;
        }
    }

 

0 Likes
Message 5 of 5

RPTHOMAS108
Mentor
Mentor

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.

0 Likes