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 :http://www.revitapidocs.com/2018/3f3ed4b4-2d17-de4f-db5f-8363d008a040.htm
Sub-category property: http://www.revitapidocs.com/2018/e2f50049-832c-9b72-70b1-2a0a96e16a60.htm

#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
2 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)