Does anyone know how to set the color of an object to a non-enumerated integer when Option Strict is enabled using COM Interop in .NET? When Option Strict is on:
Dim Layer As AcadLayer Dim Color As Integer = 8 Layer.color = Color
Causes a compiler error of:
Option Strict On disallows implicit conversions from 'Integer' to 'Autodesk.AutoCAD.Interop.Common.AcColor'
Anyone have any thoughts on this? I'm trying to use strict type checking as a rule and this is one of the minor roadblocks i've come across.
-Chris
Color requires an AcColor object, not an integer.
Use ColorIndex
Thanks, but in this case the Layer object is the COM interop "Autodesk.AutoCAD.Interop.Common.AcadLayer" object and not the managed "Autodesk.AutoCAD.DatabaseServices.LayerTableRecord". The COM version doesn't appear to have a ColorIndex method....
Initially I was doing something like this:
Layer.color = DirectCast(Color, AcColor)
Which would give me "Value of type 'Short' cannot be converted to 'Autodesk.AutoCAD.Interop.Common.AcColor'" in the debugger which sent me looking in a bunch of wrong places. However, using something like this works:
Layer.color = CType(Color, AcColor)
I'm assuming this is due to some subtle difference between DirectCast and CType that I don't yet fully understand. Time for some googling 🙂
-Chris
Try TueColor, see Help
~'J'~