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

Converting colors

15 REPLIES 15
Reply
Message 1 of 16
Thiss
1613 Views, 15 Replies

Converting colors

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;
}
15 REPLIES 15
Message 2 of 16
Anonymous
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;
}
Message 3 of 16
Thiss
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
Message 4 of 16
Anonymous
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
Message 5 of 16
Thiss
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
Message 6 of 16
Anonymous
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
Message 7 of 16
Thiss
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
Message 8 of 16
Thiss
in reply to: Thiss

Tony

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

tks


dave
Message 9 of 16
Thiss
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
Message 10 of 16
Anonymous
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
Message 11 of 16
Anonymous
in reply to: Thiss

Kerry - What's 'AcColors' ?

--
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:5575042@discussion.autodesk.com...
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
Message 12 of 16
Anonymous
in reply to: Thiss

Reading up on the Color class (the .NET one,
not the Autodesk one) should reveal how to
do it.

--
http://www.caddzone.com

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

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
Message 13 of 16
Anonymous
in reply to: Thiss

On second thought, I think this is all he needs:

Autodesk.AutoCAD.Colors.Color entColor = //

System.Drawing.Color color = entColor.ColorValue;


--
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:5575042@discussion.autodesk.com...
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
Message 14 of 16
Anonymous
in reply to: Thiss

Tony,

Just a lame alias 🙂

using AcColors = Autodesk.AutoCAD.Colors;



"Tony Tanzillo" wrote in message
news:5575110@discussion.autodesk.com...
Kerry - What's 'AcColors' ?

--
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:5575042@discussion.autodesk.com...
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
Message 15 of 16
Anonymous
in reply to: Thiss


Yep, Works for me 🙂

 


ltr = (LayerTableRecord)tm.GetObject(ltrId,
OpenMode.ForRead);


System.Drawing.Color winColor =
ltr.Color.ColorValue;


/// kwb

 

 

On second thought, I
think this is all he needs:

  Autodesk.AutoCAD.Colors.Color entColor
= //

  System.Drawing.Color color =
entColor.ColorValue;


--

href="http://www.caddzone.com">
size=2>http://www.caddzone.com



size=2>AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000
through 2008

size=2>http://www.acadxtabs.com


"Kerry
Brown" <

size=2>kwb@home
> wrote in message

size=2>news:5575042@discussion.autodesk.com

size=2>...
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

<Thiss> wrote in message

href="news:5575062@discussion.autodesk.com">
size=2>news:5575062@discussion.autodesk.com

size=2>...
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
Message 16 of 16
Thiss
in reply to: Thiss

Guys

All sorted tks - didn;t spot I could just pass the integer returned by the LookUpRgb into the Syste.Color.FromArgb method


Tks for help

Dave

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