.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
How to change the Color, line type and Line weight for the Line using .Net.
Solved! Go to Solution.
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
What have you tried. ?
... and what documentation have you looked at ?
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I tried the following
newentLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autod
where, newentLine is a entity
This works, but the issue is i want to change the color with a string input. I don't know how to do it
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
What strings do you want to use ?
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I want to send the color as string
ex: red, white, ByLayer........
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sounds like a simple
if (..)
//--
else if ( .. )
//--
else if ( .. )
//--
else if ( .. )
//--
else ( .. )
construct would work for you.
... or you could use a dictionary if you're comfortable with that.
Depending on the source of the string you may be advised to change the case to a consistant format ....
Regards
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Or a (switch...), since color values are mutually exclusive. The various case statements would associate the strings with the enumerated values, or ACI values.
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.

Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
One option:
Code solution is posted at http://www.theswamp.org/index.php?topic=41172.msg4
// (C) CodeHimBelonga kdub
using System;
using System.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using StringToColorTest;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof (StringToColor))]
namespace StringToColorTest
{
public class StringToColor
{
[CommandMethod("DoIt")]
public void StringToColorTest_01()
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
string colorString = AskUserForColorString(ed);
int colorIndex = ColorIndexFromString(colorString);
MessageBox.Show( "Color String : " +
colorString +
"\nTranslates to Integer : " +
colorIndex.ToString(),
"StringToColorTest_01");
}
//
//
public string AskUserForColorString(Editor ed)
{
PromptStringOptions strOpts = new PromptStringOptions("\nEnter Color: ");
strOpts.AllowSpaces = false;
PromptResult res = ed.GetString(strOpts);
if (res.Status != PromptStatus.OK)
{
return "ByLayer";
}
return res.StringResult;
}
//
//
public int ColorIndexFromString(string colorString)
{
int result = -1;
if (int.TryParse(colorString, out result))
{
result = ((result >= 0) && (result <= 256) ? result : 256);
}
else
{
try
{
MyColors colorIndex =
(MyColors) Enum.Parse(typeof (MyColors), colorString, true);
if (Enum.IsDefined(typeof(MyColors), colorIndex))
{
result = (int) colorIndex;
}
}
catch (ArgumentException)
{
AcadApp.DocumentManager.MdiActiveDocument.Editor.W riteMessage(
"Blooper !!");
return 256;
}
}
return result;
}
//
//
private enum MyColors
{
ByBlock = 0,
Red = 1,
Yellow = 2,
Green = 3,
Cyan = 4,
Blue = 5,
Magenta = 6,
White = 7,
Grey = 8,
ByLayer = 256
};
}
}
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for solution, this code helps me................
Re: Changing the Color, Line type and Line weight using .Net
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
You're welcome.
It was an interesting technical problem.
Regards
class keyThumper<T> : Lazy<T>; another Swamper
I do not endorse the social media app links below![]()

