We link CAD files from our standard detail packages into Revit as drafting views. I need to change the color of a specific layer (hatch) to gray. I was able to find all the layers from the CAD files and filtered down to the hatch1 layer I want to change. I have no idea how where to go from here.
You could use this simple Python script. It changes the Layer found in the Object Styles dialog, not any view override. Note that the view needs to be refreshed (simply hide/unhide the DWG) to see the change. Forcing the refresh via Python is currently a limitation. I’ll get something more robust created and added to my package (bimorphNodes - hope its useful!):
#Copyright 2016. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.co.uk #Written by Thomas Mahon @Thomas__Mahon email@example.com package: bimorphNodes #GitHub: https://github.com/ThomasMahon/bimorphNodes/ import clr # Import RevitAPI clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * # Import DocumentManager and TransactionManager clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument dwgImport = UnwrapElement(IN) name = IN col = IN # "Start" the transaction TransactionManager.Instance.EnsureInTransaction(doc) catSub = dwgImport.Category.SubCategories catSub.Item[name].LineColor = Color(col, col, col) TransactionManager.Instance.TransactionTaskDone()
Also the CADLayerNames node returns strings (text) not the Revit element which is partly why you’ve been unable to find a way to change them. I’ll look to add a new output to these nodes that also includes the Revit object for the next release
Tomas, thank you so much for your help. I added the python script and I got this warning. I made sure that it was exactly as you posted without any tabs, but I was still getting this warning.
As for the CADLayerNames node, I didn’t realize it returns a string. That completely make sense why the way I was using it didn’t work.
You need to add the additional inputs to the python node by clicking the + button. That script looks for three inputs using the
IN variable. Each input is indexed and that’s what’s throwing the exception. If you match that example graph I posted then test it should work as expected
Crazy coincidence I was just on Dynamo Primer doing the tutorial on the exact thing you just explained. So now I don’t have errors but the layer still did not change color. Even after I refreshing like you explained above (hide/unhide the DWG).
its the huge black patch in the background that should change.
Its most likely an issue with your DWG rather than the script. Firstly, check the obvious things: ensure you are selecting the correct layer. Once confirmed then its a DWG issue. You can try this and it should work: open in Microstation, select all objects in the DWG, then set the color of all object to ByCell. Link back into Revit and now it will work (tested successfully). I dont know what the equivalent setting is in AutoCAD before you ask:
That did it! I really thank you for all your help. In AutoCAD its called ByLayer.
Is there a way to have the CADLayerNames node except more than one instance? For example, I would like to find all the CAD imported files and have it find the layers causing the issue and change them. Similar to what I tried to do in my first example.
Yes, just use
Also, I’ve found a hack to get Python to force the line colour update without you having to hide/unhide the reference:
It’s pretty strightforward really; I’ve simply automated the hide/unhide step.
#Copyright 2016. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.co.uk #Written by Thomas Mahon @Thomas__Mahon firstname.lastname@example.org package: bimorphNodes #GitHub: https://github.com/ThomasMahon/bimorphNodes/ import clr # Import RevitAPI clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * clr.AddReference("RevitAPIUI") import Autodesk from Autodesk.Revit.UI import * # Import DocumentManager and TransactionManager clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager from System.Collections.Generic import * doc = DocumentManager.Instance.CurrentDBDocument dwgImport = UnwrapElement(IN) name = IN col = IN # "Start" the transaction TransactionManager.Instance.EnsureInTransaction(doc) catSub = dwgImport.Category.SubCategories catSub.Item[name].LineColor = Color(col, col, col) vId = List[ElementId]( ) vId.Add(dwgImport.Id) v = Autodesk.Revit.UI.UIDocument(doc).ActiveView v.HideElements(vId) v.UnhideElements(vId) TransactionManager.Instance.TransactionTaskDone()
That was an awesome hack. It works beautifully without having to do it manually.
Is it possible to have the Python script use the actual layer name instead of the numbered list? In your example, your showing tow files, one with 3 layers and the other with 4. Passing #4 into the script will not work in this case since the first one does not have it.
Like this, but keep in mind that Python script is very basic and only accepts scalars (i.e. single items). You’ll need to create multiple instances of the Python node for now. I am going to add this node to my package soon with the ability to take lists for the next release, so keep your package regularly updated:
Ones again, thank you for all the help. This was an awesome experience. I’m looking forward to the update to your package.
SetCADObjectStyles is avaialble in BimorphNodes v2.0!
Just want to say thank you for such a clear solution to the above problem – it has been extremely helpful in getting me this far. Apologies for resurrecting this feed but I feel that my issue does lie within the realm of this original ask.
I am working with multiple sub-contractor’s CAD backgrounds per level and I am trying to do the following:
- Select all Linked CAD throughout the entire Revit Project
- Filter the CAD by file name, thus grouping the Linked CAD by trade
- Change all the CAD layers within those Linked CAD files to the same Color, i.e. Electrical = Blue, HAC = Red and so on…
I have been able to get through steps 1 and 2 but cannot figure out how to get the elements/CAD layers within the Linked CAD to change the object style once I filter by trade. I would really appreciate any thoughts on the matter.
@kirsten.crock I think you could replace your current graph using the GetItemAtIndex node and List.Map with the bimorph node CAD.ReportImportInstances, then use your String.Contains and FilterByBoolMask similarly to shown below (I quickly just imported some dwgs that I could run this on).
Thanks so much @awilliams! That did the trick!! And with such a fast reply - I truly appreciate your help!
I’ve got the setup as shown (as far as I can tell), but the node doesn’t seem to actually change anything in my Object Styles.
I have a couple of instances of the same linked DWG in different views and they appear to be filtered correctly, but nothing seems to change.
Any feedback would be appreciated!
Hi @Thom_Krejci you need to set your cad layer colours to ‘By Level’ (or similar, i don’t know the exact phraseology in AutoCad as I barely use it) in Autocad. If you override the colour of your DWG elements (in AutoCad) it cant be changed in Revit.
Thank you for the quick reply: I haven’t tried to change the color, it was the weight that I was trying to change.
In the Object Styles dialog, I can change the weight and the lines in that link change throughout the model.
I guess I’m looking for Dynamo to be change that “4” highlighted above to let’s say “8”. Am I looking at the wrong dyn for this?