.NET

Reply
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 1 of 16 (279 Views)

Converting colors

279 Views, 15 Replies
05-02-2007 01:34 AM
How do I convert an AutoCad color to a system.drawing.color if the AutoCad. color is by Index

switch (autoCadLayer.Color.ColorMethod)
{
case Autodesk.AutoCAD.Colors.ColorMethod.ByColor:
System.Drawing.Color color = autoCadLayer.Color.ColorValue;
break;

case Autodesk.AutoCAD.Colors.ColorMethod.ByAci:
System.Drawing.Color color = System.Drawing.Color.FromArgb(?, ?, ?);
break;
}
*Kerry Brown
Message 2 of 16 (278 Views)

Re: Converting colors

05-03-2007 05:15 AM in reply to: Thiss
Perhaps try something like :


PromptSelectionOptions selectionOptions = new PromptSelectionOptions();
PromptEntityResult entityRes = ed.GetEntity("\nPick something");

//Do nothing if selection is unsuccessful
if (entityRes.Status != PromptStatus.OK)
return;
//
Entity ent = (Entity)tr.GetObject(entityRes.ObjectId, OpenMode.ForWrite);
//
if (ent.Color.IsByAci == false)
return;
//
System.Drawing.Color winColor = System.Drawing.Color.FromArgb(
ent.Color.ColorValue.A,
ent.Color.ColorValue.R,
ent.Color.ColorValue.G,
ent.Color.ColorValue.B
);
ed.WriteMessage("\n "
+ winColor.Name.ToString()
+ " .... "
+ winColor.ToString()
);
//

/// kwb
wrote in message news:5571705@discussion.autodesk.com...
How do I convert an AutoCad color to a system.drawing.color if the AutoCad.
color is by Index

switch (autoCadLayer.Color.ColorMethod)
{
case Autodesk.AutoCAD.Colors.ColorMethod.ByColor:
System.Drawing.Color color = autoCadLayer.Color.ColorValue;
break;

case Autodesk.AutoCAD.Colors.ColorMethod.ByAci:
System.Drawing.Color color = System.Drawing.Color.FromArgb(?, ?, ?);
break;
}
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 3 of 16 (278 Views)

Re: Converting colors

05-03-2007 06:36 AM in reply to: Thiss
Kerry

I tried this before I posted the question.

The problem is that if the color mode is by index then the ARGB slots do not contain Red Green & Blue values. The A slot appears to be 255 and the R slot holds the index number and G & B are zero


Dave
*Kerry Brown
Message 4 of 16 (279 Views)

Re: Converting colors

05-03-2007 08:13 PM in reply to: Thiss
Dave,
I'd have to see your code, but ..
It looks like you're working with a LayerTableRecord
so, by my understanding,
so you should be able to do what you need from the ltr.Color.ColorValue.R
... etc, fed to the
System.Drawing.Color.FromArgb( A, R,G, B) as I've shown.

/// kwb


wrote in message news:5573590@discussion.autodesk.com...
Kerry

I tried this before I posted the question.

The problem is that if the color mode is by index then the ARGB slots do not
contain Red Green & Blue values. The A slot appears to be 255 and the R slot
holds the index number and G & B are zero


Dave
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 5 of 16 (278 Views)

Re: Converting colors

05-04-2007 12:35 AM in reply to: Thiss
Kerry

Tks for reply. Here is the code. Its a common call when reading the layer table and the entities.

If I have a layer with a colour that is ByAci then in the ColorValue object I have the following


ColorValue = "{Name=ff050000, ARGB=(255, 5, 0, 0)}"

Five being the Acad index for Blue


If however I have a layer where the colour is ByValue I get the following, which is good

ColorValue = "{Name=ff2109f6, ARGB=(255, 33, 9, 246)}"



When I read the entities I use the same method


If the color is by layer I don't need to look at the entities color (it is empty anyway)

ColorValue = "{Name=ff000000, ARGB=(255, 0, 0, 0)}"

but if the color is not by layer I get exactky the same behaviour as above





Code snippet below.....






NB I'm on leave next week, so if you reply I am not ignoring you !


Many thanks


Dave
*Tony Tanzillo
Message 6 of 16 (278 Views)

Re: Converting colors

05-04-2007 02:31 AM in reply to: Thiss
Or just use EntityColor.LookUpRgb()

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Kerry Brown" wrote in message news:5574757@discussion.autodesk.com...
Dave,
I'd have to see your code, but ..
It looks like you're working with a LayerTableRecord
so, by my understanding,
so you should be able to do what you need from the ltr.Color.ColorValue.R
... etc, fed to the
System.Drawing.Color.FromArgb( A, R,G, B) as I've shown.

/// kwb


wrote in message news:5573590@discussion.autodesk.com...
Kerry

I tried this before I posted the question.

The problem is that if the color mode is by index then the ARGB slots do not
contain Red Green & Blue values. The A slot appears to be 255 and the R slot
holds the index number and G & B are zero


Dave
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 7 of 16 (278 Views)

Re: Converting colors

05-04-2007 05:11 AM in reply to: Thiss
Tony

Tks for joining in

What do you mean by EntityColor.LookUpRgb() ?

There is no LookUpRgb method or property on the AutoCAD.Colors.Color object.

Can you be more specific please ?

Dave
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 8 of 16 (278 Views)

Re: Converting colors

05-04-2007 05:16 AM in reply to: Thiss
Tony

Sorry - mis understood - I see there is a static method - just tryimng it now

tks


dave
Active Member
Thiss
Posts: 8
Registered: ‎05-02-2007
Message 9 of 16 (278 Views)

Re: Converting colors

05-04-2007 05:22 AM in reply to: Thiss
Tony

Okay - I now have this
int i = Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(acadColor.ColorValue.R);

Which returns an integer. How do I get that into RGB (in .NET)?

Tks

Dave
*Kerry Brown
Message 10 of 16 (278 Views)

Re: Converting colors

05-04-2007 05:56 AM in reply to: Thiss
For your LTR, just for the fun of it, how about :-

System.Drawing.Color argb = System.Drawing.Color.FromArgb(
AcColors.EntityColor.LookUpRgb(
System.Convert.ToByte(
ltr.Color.ColorIndex)));

/// kwb

wrote in message news:5575062@discussion.autodesk.com...
Tony

Okay - I now have this
int i =
Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(acadColor.ColorValue.R);

Which returns an integer. How do I get that into RGB (in .NET)?

Tks

Dave
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.