.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting Object Color to Non-Enumerated Value using COM Interop in VB.NET

5 REPLIES 5
Reply
Message 1 of 6
chrisshoemaker4224
913 Views, 5 Replies

Setting Object Color to Non-Enumerated Value using COM Interop in VB.NET

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 REPLIES 5
Message 2 of 6

Color requires an AcColor object, not an integer.

 

Use ColorIndex



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 6
Jeffrey_H
in reply to: caddzone

 

 

Layer.Color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex)

Put integer where colorindex is

 

This uses the autocad 255 colors I believe 256 is byBlock and 0 is bylayer if I am wrong lokk it up in the docs

You can also find your answers @ TheSwamp
Message 4 of 6

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

Message 5 of 6

DirectCast requires that one of the types has to either implement or inherit from the other

 

 

 

You can also find your answers @ TheSwamp
Message 6 of 6
Hallex
in reply to: chrisshoemaker4224

Try TueColor, see Help

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost