Ribbon Customization Via Dynamo

Hello Jeremy / Fellow Dynamo Users,

Awhile back, you wrote an article on Ribbon manipulation for both AutoCAD and Revit modifications. I was wondering, can this be done using Dynamo / Python script instead of C# which seems more native for Addin Development?

I am curious if anyone else has tried to do this and have only currently been successful using the Rhythm Package for Color Manipulation (But not able to do gradient)

Previous Article: https://thebuildingcoder.typepad.com/blog/2011/02/pimp-my-autocad-or-revit-ribbon.html

Thank you again Everyone / Jeremy!
@jeremytammik

Sincerely,
Kevin

Yes, it is possible.

You can undo it withe tilt_ribbon(0) in case anyone panics…

*edit:
The code:

import clr

clr.AddReferenceByPartialName('System.Windows.Forms')
clr.AddReference('PresentationCore')
clr.AddReference('AdWindows')
import System.Windows.Forms as winform
import Autodesk.Windows as adWin
from System.Windows.Media import RotateTransform

def tilt_ribbon(angle):
    ribbon = adWin.ComponentManager.Ribbon
    ribbon.RenderTransform = RotateTransform(angle)
    return ribbon

OUT = tilt_ribbon(0)
7 Likes

Now this is the kind of functionality I come here to see

Man, I love this…looks like someone pulled the thumbtack from the right hand corner! You just need to animate it and play a creaking noise followed by the sound of something breaking (probably revit)! :joy:

Awesome! Thank you guys for the info.

@Kibar, what would the code be then for allowing for gradient color modifications? I have seen the tilt one but not for gradient colors as illustrated in the article?

Thank you again!

Compare the python code to the c# code on jeremy´s page and apply it similarly to the function you´re looking for.

Create clr references to the right assemblies and import the needed modules. You can find in the .NET Frameworks docs the function you´re looking for and see in which .dll it is.

For instance RotateTransform:

You´ll need to reference the PresentationCore assembly and can then import it through System.Windows.Media (because it´s an “sub element” of it)

Hey Kibar,

Still trying to get it right:
Version:0.9 StartHTML:00000097 EndHTML:00001822 StartFragment:00000199 EndFragment:00001784 import clr

clr.AddReferenceByPartialName(‘System.Windows.Forms’)
clr.AddReference(‘PresentationCore’)
clr.AddReference(‘AdWindows’)
import System.Windows.Forms as winform
import Autodesk.Windows as adWin
from System.Windows.Media import Colors

def color_ribbon(color):
ribbon = adwin.ComponentManager.Ribbon
Ribbon.RenderTransform = Colors(color)
return ribbon

OUT = color_ribbon(FFF0F8FF)

Not sure what line is not working :confused:

Kibar’s example specifically shows how to transform (or Rotate, in this case) the UIElement (Ribbon). I would try translating the code from Jeremy’s post into IronPython as best you can. For example, this (C#):

foreach( adWin.RibbonTab tab in ribbon.Tabs )
{
  foreach( adWin.RibbonPanel panel in tab.Panels )
  {
    panel.CustomPanelTitleBarBackground 
      = gradientBrush;

    panel.CustomPanelBackground 
      = picBrush; // use your picture

    //panel.CustomPanelBackground 
    //  = gradientBrush; // use your gradient fill
  }
}

Would be this (IronPython):

for tab in ribbon.Tabs:
    for panel in tab.Panels:
        panel.CustomPanelTitleBarBackground = gradientBrush
        panel.CustomPanelBackground = picBrush # use your picture

This is what you had originally written (I have included some comments as well):

clr.AddReferenceByPartialName('System.Windows.Forms')
clr.AddReference('PresentationCore')
clr.AddReference('AdWindows')
import System.Windows.Forms as winform
import Autodesk.Windows as adWin
from System.Windows.Media import Colors

def color_ribbon(color):
    ribbon = adwin.ComponentManager.Ribbon
    # Ribbon with a capital R is the class itself, not your ribbon object
    # Colors does not have any public constructors
    # This would have to instead be Colors.AliceBlue
    Ribbon.RenderTransform = Colors(color)
    return ribbon

# The data being passed to color_ribbon is not a string
# This would raise a NameError (name 'FFF0F8FF' is not defined)
OUT = color_ribbon(FFF0F8FF)

This is closer to what you’re looking for (although it isn’t functional yet–someone else on the forum with more experience in UI design will probably be able to provide more direction):

clr.AddReferenceByPartialName('System.Windows.Forms')
clr.AddReference('PresentationCore')
clr.AddReference('AdWindows')
import System.Windows.Forms as winform
import Autodesk.Windows as adWin
from System.Windows.Media import ColorConverter

def color_ribbon(color):
    ribbon = adwin.ComponentManager.Ribbon
    color_converted = ColorConverter.ConvertFromString(color)
    # Use color_converted to set the background color
    # Etc etc. This code doesn't yet actually modify the Ribbon's color
    return ribbon

# Make sure to provide a string and include the pound sign
OUT = color_ribbon('#FFF0F8FF')
2 Likes