C# Autocad Developer:如何使用C在RGB模式下获取对象颜色#
大家好,我想在RGB模式下获取属性中的对象颜色。我已经尝试了类似以下代码:C# Autocad Developer:如何使用C在RGB模式下获取对象颜色#,c#,autocad,autocad-plugin,C#,Autocad,Autocad Plugin,大家好,我想在RGB模式下获取属性中的对象颜色。我已经尝试了类似以下代码:string cecolor=acDocComObj.GetVariable(“cecolor”)但这不会返回TrueColor中的。有人知道如何操作吗?对于AutoCAD中的任何实体(例如直线、圆、块等),可以使用.Color属性(对于.NET进程内API): 正如您提到的进程外COM/ActiveX,您可以尝试类似的方法: AcadEntity ent = // get the entity here; int[] r
string cecolor=acDocComObj.GetVariable(“cecolor”)代码>但这不会返回TrueColor中的。有人知道如何操作吗?对于AutoCAD中的任何实体(例如直线、圆、块等),可以使用.Color属性(对于.NET进程内API):
正如您提到的进程外COM/ActiveX,您可以尝试类似的方法:
AcadEntity ent = // get the entity here;
int[] rgb = new int[] { ent.TrueColor.Red, ent.TrueColor.Green, ent.TrueColor.Blue };
对于AutoCAD中的任何图元(例如直线、圆、块等),可以使用.Color属性(对于.NET进程内API):
正如您提到的进程外COM/ActiveX,您可以尝试类似的方法:
AcadEntity ent = // get the entity here;
int[] rgb = new int[] { ent.TrueColor.Red, ent.TrueColor.Green, ent.TrueColor.Blue };
我在Autodesk讨论组上给出的答复
AcadAcCmColor color = new AcadAcCmColor();
int index = 0;
if (colorName.ToUpper() == "BYBLOCK")
{
color.ColorIndex = AcColor.acByBlock;
}
else if (colorName.ToUpper() == "BYLAYER")
{
color.ColorIndex = AcColor.acByLayer;
}
else if (int.TryParse(colorName, out index))
{
color.ColorIndex = (AcColor)index;
}
else if (colorName.ToUpper().StartsWith("RGB:"))
{
string[] rgb = colorName.Substring(4).Split(',');
color.SetRGB(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2]));
}
else
{
string[] bookColor = colorName.Split('$');
color.SetColorBookColor(bookColor[0], bookColor[1]);
}
我在Autodesk讨论组上给出的答复
AcadAcCmColor color = new AcadAcCmColor();
int index = 0;
if (colorName.ToUpper() == "BYBLOCK")
{
color.ColorIndex = AcColor.acByBlock;
}
else if (colorName.ToUpper() == "BYLAYER")
{
color.ColorIndex = AcColor.acByLayer;
}
else if (int.TryParse(colorName, out index))
{
color.ColorIndex = (AcColor)index;
}
else if (colorName.ToUpper().StartsWith("RGB:"))
{
string[] rgb = colorName.Substring(4).Split(',');
color.SetRGB(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2]));
}
else
{
string[] bookColor = colorName.Split('$');
color.SetColorBookColor(bookColor[0], bookColor[1]);
}
现在它给了你什么?字符串格式,比如RGB:128,12113或213(索引号),或Pantone。根据用户在Autocad中选择的内容。@G.C.Looi您应该在问题中包括该信息,而不仅仅是在注释中。它现在为您提供了什么?字符串格式,如RGB:128、12113或213(索引号)或Pantone。根据用户在Autocad中选择的内容。@G.C.Looi您应该在问题中包含该信息,而不仅仅是在注释中。谢谢,但是我担心这不是解决我问题的答案,因为此代码用于过程中,但不用于互操作。我编辑了我的答案,基本上与COM/ActiveXtanks的方法相同,但是,我担心这不是解决我问题的答案,因为这段代码是用于进程内的,而不是用于互操作。我已经编辑了我的答案,基本上与COM/ActiveXHi的方法相同,先生,再次感谢。您好,先生,再次感谢。