Yesterday I wrote about creating a custom theme thmx in SharePoint 2010. But now I would like to add this them to my site definition. I could not figure out how to do it in the onet.xml so I did some digging around in the object model.  Below is an example on how you can get the theme url and the name of the them of a SPWeb.

SPWeb web = new SPSite("http://yourSPSite/").RootWeb;
string themeurl = ThmxTheme.GetThemeUrlForWeb(web); //gets your theme
ThmxTheme theme = ThmxTheme.Open(web.Site, themeurl );
theme.Name; //Gets the name of your theme

 

The ThmxTheme is found in the Microsoft.SharePoint.Utilities namespace. Below is the methods to remove a theme and set a theme. I am not sure what ShareGenerated does yet. But when I know I will post it.

//Will Remove the theme from the SPWeb.
ThmxTheme.RemoveThemeFromWeb(SPWeb web, Boolean RemoveStyles) 
 
//Set a theme on a SPWeb
ThmxTheme.SetThemeUrlForWeb(SPWeb web, string ThemeUrl) 
 
//Set a theme on a SPWeb OverLoaded Function. 
ThmxTheme.SetThemeUrlForWeb(SPWeb web, string ThemeUrl, bool shareGenerated))