Dark Icons, NewFamilyInstance and AI News

Revit 2024 brought us theme switching functionality requiring new icons, and a new NewFamilyInstance overload; meanwhile, the AI revolution acceleration continues growing:

Dark Theme Icons

Matthew Taylor, associate and CAD developer at WSP shared two dark theme icon hacks, useful time- and labour-saving tips and tricks to support the dark theme in Revit 2024. The new API functionality to support theme switching is listed in the Revit API news section on UI API additions. Says Matt:

Hack 1 – Dark Icons by ImageMagick

I've long used .bmp files as my raw ribbon icon images.

I take those .bmp files and create .png files using a program called ImageMagick – I'm not affiliated).

Once installed, you may use it in batch scripts etc.:

This is what I used in Revit 2023:

rem For each .bmp file in this folder,
rem   convert the white pixels to transparent,
rem   and save the result to .png.
for %%f in (*.bmp) do ( convert -transparent white %%f %%~nf.png)

Then, with Revit 2024, the dark theme came along!

This is what I ended up with, in addition to the above:

rem For each .bmp file in this folder,
rem   invert the grayscale pixels only (white->black,
rem   lightgray->darkgray, darkgray->lightgray,
rem   black->white etc.)
rem   convert the black pixels to transparent,
rem   add 30 to each R,G,B value (necessary as our dark
rem   mode is not black - this is an arbitrary value to
rem   lighten the overall image),
rem   and save the result to _dark.png.
for %%f in (*.bmp) do ( convert +negate -transparent black -colorize 30,30,30  %%f %%~nf_dark.png)

This system works well with grayscale icons and icons that already used a similar colour scheme to native Revit.

I imagine it's possible to use the -scale switch to create 16x16 icons from 32x32 icons, but I've not tested that.

I imagine it's also possible to add badges (from the zip in Jeremy's post) to images using something like this: Add an image on top of existing one with ImageMagick command line.

Hack 2 – Embed Name in BitMapSource

Another issue I had was that I was using icons as embedded resources.

I couldn't work out how to get the name of the icon from the ribbon item Image or LargeImage property in order to get the dark or light equivalent. (I was changing the icons in the ThemeChanged event.) I worked out I could embed the name within the BitMapSource when initially adding the image:

Private Shared Function GetEmbeddedImage(ByVal assembly As Assembly, ByVal imageFullName As String) As BitmapSource
  If Not String.IsNullOrEmpty(imageFullName) Then
      Dim s As IO.Stream = assembly.GetManifestResourceStream(imageFullName)
      If s IsNot Nothing Then
          Dim bitmap As BitmapSource = BitmapFrame.Create(s)
          Dim metadata As BitmapMetadata = New BitmapMetadata("png")
          metadata.SetQuery("/iTXt/Keyword", imageFullName.ToCharArray())
          Dim bitmapWithMetadata As BitmapSource = BitmapFrame.Create(bitmap, Nothing, metadata, Nothing)
          Return bitmapWithMetadata
      End If
  End If
  Return Nothing
End Function

I could then retrieve that name:

Dim ribbonItem as RibbonItem...
Dim bitmapSource As BitmapSource = CType(ribbonItem.Image, BitmapSource)
Dim metadata As BitmapMetadata = CType(bitmapSource.Metadata, BitmapMetadata)
If metadata IsNot Nothing Then
   Dim existingValue As Object = metadata.GetQuery("/iTXt/Keyword")
   Dim imageName As String = TryCast(existingValue, String)
   'Use image name to get an embedded resource and set it to the ribbon item image.
End If

I hope this saves some of you a bit of time and effort.

Many thanks to Matt for these valuable work- and time-savers!

New NewFamilyInstance Overload

Kennan Chen provided a very clear explanation and solution for getting the wrong NewFamilyInstance override using .NET Reflection or the C# dynamic keyword. In short:

In Revit 2024, the method you are using is defined in the Autodesk.Revit.Creation.ItemFactoryBase class and the Autodesk.Revit.Creation.Document class just inherits it. This means that ItemFactoryBase.NewFamilyInstance is invoked underneath by the C# compiler generated code.

NewFamilyInstance moved

In previous versions of Revit, the "same" method is defined directly in Autodesk.Revit.Creation.Document class.

The Revit API news highlights this change in the section 1.4.1. Placement of Level based instances in family documents.

The use of the method looks the same, but they result in different compiled code when linked with different releases of RevitAPI.dll, which means the DLL compiled against Revit 2024 cannot be used in Revit 2023 if you use this method.

This is an API compatibility issue. The standard solution is to build different Revit add-in DLLs targeting the different versions of Revit.

For full details of this discussion, please refer to the original discussion thread on getting the wrong NewFamilyInstance override.

Many thanks to Kennan for his research and explanation!

Open-Source AI Surging Ahead

A purportedly leaked document titled Google "We Have No Moat, And Neither Does OpenAI" highlights the impressive acceleration of AI research success in the past month:

I’m talking, of course, about open source. Plainly put, they are lapping us. Things we consider “major open problems” are solved and in people’s hands today. Just to name a few:

Timeline of Major Milestones Crossed

Non-Technical Explanation of AI and Deep Learning

For a newbie to get a quick feel for some of the basic topics involved in the current LLM revolution, here is a completely non-technical explanation of AI and deep learning.

Using AI to Read Your Thoughts

Connecting AI with our human brain holds both very scary and very promising potential. Now, scientists can use GPT AI to passively read people's thoughts:

AI model combined with fMRI reading non-invasively decodes continuous language from subjects

AI Emergent Abilities May Not Be Emergent After All

In March, scientists were surprised comparing ChatGPT using GPT 3.5 with some greater capabilities exhibited by GPT 4, hypothesising sparks of artificial general intelligence in the LLM.

A more recent paper questions this, instead asking are emergent abilities of large language models a mirage?

Figure 2: Emergent abilities of large language models are creations of the researcher’s analyses, not fundamental changes in model outputs with scale

Risk of AI Manipulation

Among many others, Yuval Noah Harari warned last year that humans will be "hacked" if artificial intelligence is not globally regulated and argues that AI has hacked the operating system of human civilisation.

It is indisputable that we will all need to significantly sharpen our skills to critically evaluate all the input we receive. Soon, it will be almost impossible to distinguish deep fake from reality.

That reminds me of Harari's last chapter in 21 Lessons for the 21st Century, on meditation. He shares his own very personal answer on how to reconnect with reality: retreat into myself and feel it through my own senses, cutting off myself for a while from all external input. I love that book, as I mentioned discussing generative AI and multi-modal learning back in February this year. Highly recommended.