Iterating through entities and extraction of color values
Moderators: SDS, support, admin
-
- Posts: 5
- Joined: 19 Sep 2016, 19:51
Iterating through entities and extraction of color values
I'm using CAD.NET in C#. I'm importing DWG and DXF files as follows:
In ProcessDWGEntity, to get color for an entity, I do this
I couldn't figure out how to determine if an entity is using a default color so I hacked the part about checking if it's transparent black. Is there a better way?
Should I be using Iterate instead of how I'm doing it?
Code: Select all
cadImage = CADImport.CADImage.CreateImageByExtension(fileName);
if (cadImage != null)
{
cadImage.LoadFromFile(fileName);
for (int index = 0; index < cadImage.Layouts.Count; index++)
{
CADImport.CADLayout layout = cadImage.Layouts[index];
if (cadImage.Layouts[index].Name.Equals("Model", StringComparison.InvariantCultureIgnoreCase))
{
foreach (CADImport.CADEntity ent in layout.Entities)
{
ProcessDWGEntity(cadImage, ent);
}
}
}
}
Code: Select all
CADImport.CADInsert ins = ent as CADImport.CADInsert;
if(ent is CADImport.CADLeader)
ins = (ent as CADImport.CADLeader).Insert;
Color entColor = CADImport.CADConst.EntColor(ent, ins);
if (entColor.ToArgb() == 0)
entColor = cadImage.DefaultColor;
Should I be using Iterate instead of how I'm doing it?
Re: Iterating through entities and extraction of color value
Hello,
For iterating through the entities you may use a single foreach loop, it will simplify the code:
To determine if an entity is using the default color, call this method in the ProcessDWGEntity routine:
Mikhail
For iterating through the entities you may use a single foreach loop, it will simplify the code:
Code: Select all
foreach (CADImport.CADEntity ent in cadImage.Converter.Entities)
{
ProcessDWGEntity(cadImage, ent);
}
Code: Select all
private bool HasDefaultColor(CADEntity entity, CADImage cadImage)
{
if (entity.Color.ToArgb() == cadImage.DefaultColor.ToArgb())
{
return true;
}
else
{
return false;
}
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 5
- Joined: 19 Sep 2016, 19:51
Re: Iterating through entities and extraction of color value
My original problem was that the color returned from the API is transparent black (ARGB(0,0,0,0)), but CAD.NET Editor was listing the color as White. So, I assumed that the entity was not using a local color, but the default color (which also happened to be white).
So, what would be the cause of the discrepancy between the API returned color and what your Editor program shows?
So, what would be the cause of the discrepancy between the API returned color and what your Editor program shows?
Re: Iterating through entities and extraction of color value
Hello,
You should check what color type (ByValue, ByLayer, ByBlock or Default) is used by the entity, by using the Color_type property value displayed in the PropertyGrid. Most likely, the color type value is Default in the given case, that means the color value displayed in the PropertyGrid may be (255, 255, 255) or (0,0,0) depending on the background color.
If you set the color type to ByValue, the color value displayed in the PropertyGrid will be the same as the one returned from the API.
Mikhail
You should check what color type (ByValue, ByLayer, ByBlock or Default) is used by the entity, by using the Color_type property value displayed in the PropertyGrid. Most likely, the color type value is Default in the given case, that means the color value displayed in the PropertyGrid may be (255, 255, 255) or (0,0,0) depending on the background color.
If you set the color type to ByValue, the color value displayed in the PropertyGrid will be the same as the one returned from the API.
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support