Dynamo color and Python

I have a problem almost solved: in my version of Revit (French), no solid fill pattern. so Color Element override node doesn’t work.

I’m trying to fix this with some Python code. I achieve to override the pattern and the color of the pattern, but I cannot set the RGB values for the color. always Black.

code is:

doc = IN0
patternID = IN1
elt = IN2
R=IN3
G=IN4
B=IN5
elementlist = list()

color=doc.Application.Create.NewColor()
#color.Red=R
#color.Green=G
#color.Blue=B

a=OverrideGraphicSettings().SetProjectionFillPatternId(patternID)
b=OverrideGraphicSettings(a).SetProjectionFillColor(color)

for item in elt:
elementlist.append(item.Id)

for item in elementlist:
p=doc.ActiveView.SetElementOverrides(item, a)
c=doc.ActiveView.SetElementOverrides(item, b)

OUT =color

When I activate color lines, I get an exception Color is read-only. Thanks for your help.

 

just glancing at code, I’m guessing you must set the rgb values in the constructor… maybe?

doing this I get an error like color wanted color got str or tuple. if I define color = Color(xxx.xxx.xxx), I get an error too, like color is read-only. I tried many combinations with no luck, even with hex numbers to define colors. I also tried to get the node color as an input, but there’s an alpha value in it.

Hi Julien,

finally found the time to look at this problem.

You indeed need to call the constructor, like this:

color = Autodesk.Revit.DB.Color(R,G,B)

Argh! So close I was. I need to understand how to get this kind of input from the API help file. Another beer for you Andreas! Package on the way soon.

Package published. first version that certainly needs enhancement.dynOverride

1 Like

Is the method that you use to override 3d model elements in Revit the same code to override graphics in view of view crop regions? I’m thinking on the documentation side of things and we need to make adjustments to interior elevations to ensure they have borders even if not cropped all the way to a walls edge. There is literally hundreds and currently, the only way to adjust is to manually double-click to activate view > select crop edge > override graphics in view > elements > and set color/weight… on every single one. > Download Dynamo File here…

Any thoughts would be greatly appreciated!

@Julien_Benoit1, do you have a more recent version for this package? Thanks in advance!

This is pretty old, and I imagine no longer relevant. You can now override color of elements using the OOTB nodes.

Thanks @Konrad_K_Sobon, could you explain me please whát do you mean by OOTB nodes?

Thanks in advance

OOTB = Out of the box. I meant that Dynamo now ships with components that provide this functionality. There is no need for Python customization.

Thanks.