Iterating through entities and extraction of color values
Posted: 19 Sep 2016, 19:57
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?