Element.OverrideInView but for multiple Views?

This works great to override elements the active View but I want to do it on multiple views at once. Is there a node available to do it?

This Python is a clue but I could not figure out the lacing/looping.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])
element = IN[1]
override = IN[2]
result = []
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)
while (count < len(override)):
	for i in element:
		try:
			view.SetElementOverrides(i, override[count])
			result.append("Success")
			count
			count = count + 1
		except:
			view.SetElementOverrides(i, override[count-1])
			result.append("Success")
TransactionManager.Instance.TransactionTaskDone()


OUT = result

Untested. But what if you use the python you posted, and loop the IN[0] over the TransactionManager?
(Btw: perhaps you could map the original node as function?)

doc = DocumentManager.Instance.CurrentDBDocument

views = UnwrapElement(IN[0])
element = IN[1]
override = IN[2]
result = []
count = 0    
for view in views:
         TransactionManager.Instance.EnsureInTransaction(doc)
          while (count < len(override)):
        		for i in element:
        			try:
        			    view.SetElementOverrides(i, override[count])
        			    result.append("Success")
        			    count
        			    count = count + 1
        			except:
        			    view.SetElementOverrides(i, override[count-1])
        			    result.append("Success")
         TransactionManager.Instance.TransactionTaskDone()

I tried it, 3Pinter.
Python:
image
Graph:


Problem in line 34

sorry lacking the time atm to help you. Perhaps others can!

Tried it myself: I see you are using dynamo 2, doing that myself too:

  • line 34 error: GraphicOverrideSetting isn’t a list, so no need to loop that.
  • if you fix that: you get an error: “Expected GraphicOverrideSettings, got GraphicOverrideSettings” … so… that isn’t helpfull.
  • tried creating a GraphicOverrideSettings myself with a color. … same error. Expected Color, got Color. …

:confounded:

Hmm. I found some more clues and will keep trying.

Another clue from Element color override in viewS


Issue opened 2017
https://github.com/DynamoDS/DynamoRevit/issues/1812

Try to use “i.Id” not just “I”.

The Clockwork node View.OverrideElementTransparency works as expected but only if I set its lacing to longest. I think I can hack it.

How to make this Python script by itself lace longest as there is no lacing setting on its node?
image

Hey @truevis,

You need to include the views in the looping process. Can you not implement what I did I the post you linked to?

Otherwise, it would be helpful, if we could see your list structure. I’m not at a computer right now, but I might be able to help you out tomorrow, if you can’t make it work :slightly_smiling_face:

1 Like

Hi, @truevis! I cant help you with this DynamoNodes, but you can try solution with python. Here is short example:


And also code for copy/pasting:

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import OverrideGraphicSettings, Color
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])
line_pattern = UnwrapElement(IN[2])
fill_pattern = UnwrapElement(IN[3])
color_input = IN[4]
color_l= color_input.split(" ")
color = Color(int(color_l[0]),int(color_l[1]),int(color_l[2]))
TransactionManager.Instance.EnsureInTransaction(doc)
for i in elements:
	for view in views:		
		ogs = OverrideGraphicSettings()		
		ogs.SetProjectionLineColor(color)
		ogs.SetProjectionFillColor(color)
		ogs.SetProjectionFillPatternId(fill_pattern.Id)
		ogs.SetCutFillPatternId(fill_pattern.Id)
		ogs.SetCutLineColor(color)
		ogs.SetCutFillColor(color)
		ogs.SetHalftone(False)
		ogs.SetProjectionLinePatternId(line_pattern.Id)
		ogs.SetCutLinePatternId(line_pattern.Id)
		ogs.SetSurfaceTransparency(IN[5])
		view.SetElementOverrides(i.Id, ogs)	
TransactionManager.Instance.TransactionTaskDone()

And here you can get other graphic override settings OverrideGraphicSettings Methods

1 Like

That looks close but we are providing list of lists for the model elements. That list’s top level has the same count as the list of Views. Each sub-list has the elements to be overridden in each View.

I’m just not good yet on the looping in Python to make it the equivalent of longest lacing in a node.

Ok, so can you give an example of final list in this way:

LIST
	LIST:
		View
		View
		View
	LIST:
		Element
		Element
		Element

Is it something like that?

1 Like

No, Dmytro_Serebriian

list:
->view 0
->view 1
->view 2

list:
->list of elements to override in view 0
->list of elements to override in view 1
->list of elements to override in view 2

overrides (from node)
image

I think now its ok, so here we go:


python code:

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import OverrideGraphicSettings, Color
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

input_list = IN[0]
views = UnwrapElement(input_list[0])
el_top_list = UnwrapElement(input_list[1])

line_pattern = UnwrapElement(IN[2])
fill_pattern = UnwrapElement(IN[3])
color_input = IN[4]
color_l= color_input.split(" ")
color = Color(int(color_l[0]),int(color_l[1]),int(color_l[2]))
line_weight = IN[6]
halftone = IN[7]
ogs = OverrideGraphicSettings()		
ogs.SetProjectionLineColor(color)
ogs.SetCutLineColor(color)
ogs.SetCutLineWeight(line_weight)
ogs.SetProjectionLineWeight(line_weight)
ogs.SetHalftone(halftone)
ogs.SetSurfaceTransparency(IN[5])
#ogs.SetProjectionFillColor(color)
#ogs.SetProjectionFillPatternId(fill_pattern.Id)
#ogs.SetCutFillPatternId(fill_pattern.Id)
#ogs.SetCutFillColor(color)
#ogs.SetProjectionLinePatternId(line_pattern.Id)
#ogs.SetCutLinePatternId(line_pattern.Id)

TransactionManager.Instance.EnsureInTransaction(doc)

count = 0
for k in range(len(views)):	
	for i in el_top_list[count]:
		views[count].SetElementOverrides(i.Id, ogs)	
	count+=1	
TransactionManager.Instance.TransactionTaskDone()
OUT = 0

override2.dyn (23.9 KB)

2 Likes

I got it to run. Super!

A caveat is the the ‘Select Model Elements’ nodes have to each have more that one selected element.


A’m glad it works for you. As you sad you need input list for elements:

LIST
	LIST
		Element
		Element
	LIST
		Element
		Element

If you select only one element dynamo node create something like:

LIST
	LIST
		Element
		Element
	Element

So your task is to create correct input list with nodes. But for my example you can add another python node:

out_list=[]
for i in IN[0]:
	if isinstance(i, list):
		out_list.append(i)
	else:
		out_list.append([i])		
OUT = out_list

Wish you to fulfill your task !

1 Like

@Dmytro_Serebriian

This is great! But it doesn’t seem to work for annotation elements (such as Revision Clouds). Is there any way to override those in multiple views? (I created a new topic about this) Thank you!

@Dmytro_Serebriian
What do i have to change in this Python to only override the Fill Patterns.
I don’t want to override the color of the Lines.

NB I know Dynamo, but not Python.

EDIT I think i found out myself :smile:.

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import OverrideGraphicSettings, Color
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])
fill_pattern = UnwrapElement(IN[2])
color_input = IN[3]
color_l= color_input.split(" ")
color = Color(int(color_l[0]),int(color_l[1]),int(color_l[2]))
TransactionManager.Instance.EnsureInTransaction(doc)
for i in elements:
	for view in views:		
		ogs = OverrideGraphicSettings()		
		ogs.SetProjectionFillColor(color)
		ogs.SetProjectionFillPatternId(fill_pattern.Id)
		ogs.SetCutFillPatternId(fill_pattern.Id)
		ogs.SetCutFillColor(color)
		ogs.SetHalftone(False)
		ogs.SetSurfaceTransparency(IN[4])
		view.SetElementOverrides(i.Id, ogs)	
TransactionManager.Instance.TransactionTaskDone()
1 Like


Here is a Python hack to turn a single selected element into a list if needed:

if isinstance(IN[0], list):
    out_list=IN[0]
else:
	out_list=[IN[0]]	
OUT = out_list

Thence the Python for the overrides works if only one element selected.

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import OverrideGraphicSettings, Color
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

input_list = IN[0]
views = UnwrapElement(input_list[0])
el_top_list = UnwrapElement(input_list[1])

line_pattern = UnwrapElement(IN[1])
fill_pattern = UnwrapElement(IN[2])
color_input = IN[3]
color_l= color_input.split(" ")
color = Color(int(color_l[0]),int(color_l[1]),int(color_l[2]))
line_weight = IN[5]
halftone = IN[6]
ogs = OverrideGraphicSettings()		
ogs.SetProjectionLineColor(color)
ogs.SetCutLineColor(color)
ogs.SetCutLineWeight(line_weight)
ogs.SetProjectionLineWeight(line_weight)
ogs.SetHalftone(halftone)
ogs.SetSurfaceTransparency(IN[4])
#ogs.SetProjectionFillColor(color)
#ogs.SetProjectionFillPatternId(fill_pattern.Id)
#ogs.SetCutFillPatternId(fill_pattern.Id)
#ogs.SetCutFillColor(color)
#ogs.SetProjectionLinePatternId(line_pattern.Id)
#ogs.SetCutLinePatternId(line_pattern.Id)

TransactionManager.Instance.EnsureInTransaction(doc)

count = 0
for k in range(len(views)):	
	for i in el_top_list[count]:
		views[count].SetElementOverrides(i.Id, ogs)	
	count+=1	
TransactionManager.Instance.TransactionTaskDone()
OUT = views