Hide/Uncheck Visibility for Layer in Linked DWG CAD File

Hi,

I am looking to hide/uncheck layers in a linked CAD file within a view like a Drafting View. There is documentation on how to change line colors, etc but I am having trouble pin pointing a way to simply hide a layer in a view via Dynamo/API. To shortcut initial steps I can use @Thomas_Mahon Bimorph Nodes to obtain all CAD Links and their Layer names. The Bimorph CAD.SetObjectStyle does not include an option for turning off a layer by name. Is there a way through the API or functionality in the Bimorph nodes that allows me to do so?

1 Like

Same hereā€¦ This would potentially save an enormous amount of time when dealing with many CAD links on many view templates.

I didnā€™t see this post, but its easy to implement so Iā€™ve added CAD.SetLayerVisibility to the next release of BimorphNodes. ETA Q1 or early Q2.

6 Likes

Will this control linked CAD layers in View Templates?

Thanks Thomas,

Thatā€™s fantastic, just for my curiosity (and perhaps in the meantime), would you mind helping me do it with Python?

I believe I need the sub-category of the import instance, but I canā€™t find much in the API to get methods for these? Dir didnā€™t give me a visibility or hideā€¦ I had a try with SetCategoryHidden and the import instance class tells me:

To hide or unhide an element, use the Hide() and Unhide() method of [View ]

But nothing has worked :frowning:

Any hints welcome :slight_smile:

Cheers,

Mark

Import instance methods :ImportInstance Methods
Sub-category property: SubCategories Property

#thanks to KSobon, TMahon, Koz Jono YEOH and everyone else

import clr

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
 
import System
from System.Collections.Generic import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc =  DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

view = doc.ActiveView.Id #UnwrapElement(IN[1])
DWG = UnwrapElement(IN[0])
lyrsIds = List[ElementId]()

try:
    lyrs = DWG.Category.SubCategories.GetEnumerator()
    while lyrs.MoveNext():
        lyrsIds.Add(lyrs.Current.Id)
except: pass

TransactionManager.Instance.EnsureInTransaction(doc)
for lyrId in lyrsIds:
    try:
        view.HideElements(lyrId)
        Output = 'Success'
    except:
        pass
        Output = 'Fail'
TransactionManager.Instance.TransactionTaskDone()

OUT  = Output, lyrsIds,

Hi @Mark.Ackerley

No problem, just get the category of the import instance then its sub categories:

#Copyright 2019. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.com
#Written by Thomas Mahon @Thomas__Mahon info@bimorph.com Package: BimorphNodes
#GitHub: https://github.com/ThomasMahon/bimorphNodes/
#Follow: facebook.com/bimorphBIM | linkedin.com/company/bimorph-bim | @bimorphBIM

import clr

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

importInstance = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
layerName = IN[2]
visible = IN[3]

doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

catSub = importInstance.Category.SubCategories
cat = catSub.get_Item(layerName)

cat.set_Visible(view, visible)

TransactionManager.Instance.TransactionTaskDone()

OUT = importInstance
3 Likes

Hi @Thomas_Mahon

Thank you for the speedy response :slight_smile:

Can you help me workout where the get_Item and set_Visible live in the api docs? I canā€™t see a sub category class?

PS I deleted ā€˜Document doc = DocumentManager.Instance.CurrentDBDocumentā€™

PPS Iā€™m still getting an exception?

Hi @edanastas i thought it would, since a VT is just a view from Revits perspective, however it throws an exceptionā€¦so no! Iā€™ll look into this before release.

EDIT: Yes, it works, there was an exception occurring within my test file. Simply pass you view template in as the view and it will work without issue.

1 Like

I copied my code from C# then redacted it and missed thatā€¦ so you need to remove the Document type from the doc object (C# is strong-typed) declaration as you will need this line, i.e.:

doc = DocumentManager.Instance.CurrentDBDocument

Iā€™m testing in D 1.3.4 and R2018:

2 Likes

Sweet, thatā€™s working :slight_smile:

Thanks again!

Mark

Iā€™m a little new at thisā€¦ I have the ā€œView Templateā€ Library element. What would I do with that to drill down to set the layers within it?

image

@edanastas download BimorphNodes v3 and use the new CAD.SetLayerVisibility node (your view template is a type of view, so input it into the view input)

Hi Thomas,

Can you help confirm a few things about the functionality of this node?
-Can it be used to access DWGs from a linked model? I did not have any luck during my attempts.
-Can you elaborate more on the type of views it will take. Will it work with Area Plans?
-Do you know why i am getting the error below?

Original Issue:
The architect is using CAD links in their views for some parts of floorplans and we want to be able to hide a specific layer that they are using to cloud items for an addendum. I was not able to use this node from my model so my compromise it to make the changes in the linked Arch model directly.

Thank you for your help