eInvalidLayer when setting LayerTableRecord.IsFrozen to false


Found this problem this morning: if you set IsFrozen to false on the current layer, you'll get an Autodesk.AutoCAD.Runtime.Exception with the ErrorStatus at eInvalidLayer. The setter is certainly checking if the layer is current to avoid freezing it, but it should test the value to ignore when it is false.

So you have to check the layer state before changing the property to false:


AutoCAD indexed colors list


A little bit of code to export the list of Red, Green and Blue values for indexed AutoCAD colors:

public void DumpColors()
    using (var sw = new StreamWriter(@"C:\temp\acadColors.txt"))
        sw.WriteLine(" I ; R ; G ; B ");
        for (short colorIndex = 1; colorIndex <= 255; colorIndex++)
            using (Color color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex))
                sw.WriteLine("{0,3};{1,3};{2,3};{3,3}", colorIndex,
                    color.ColorValue.R, color.ColorValue.G, color.ColorValue.B);


Get the name of the active AutoCAD document with .NET


Here's a little sample code to detect if AutoCAD is running. If it does, it displays the full path of the active drawing.

The code use COM (out of process).


Imports System.Runtime.InteropServices

Module Module1

    Sub Main()
            Dim acad = Marshal.GetActiveObject("AutoCAD.Application")
            Dim activeDocument = acad.ActiveDocument
            MsgBox("Le chemin complet du document actif est : " & activeDocument.FullName)
        Catch ex As COMException
            Const MK_E_UNAVAILABLE As Integer = &H800401E3
            If ex.ErrorCode = MK_E_UNAVAILABLE Then
                MsgBox("AutoCAD n'est pas en cours d'exécution.")
            End If
        End Try
    End Sub

End Module

A virus targeting AutoCAD


The virus Flame is a lot of attention right now. A striking feature here is that it specifically targets AutoCAD DWG files. This suggests that this complex malware was designed by a state eager to seize some secrets documented through drawings.

Subscribe to RSS - .NET