Incorrect color information of CADEntity

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
thomascheah
Posts: 26
Joined: 17 Oct 2007, 06:46
Location: Malaysia
Contact:

Incorrect color information of CADEntity

Post by thomascheah » 14 Mar 2008, 10:23

Hi,

I noticed that the Color property of CADEntity is incorrect on certain CAD files. The code is like below,

Code: Select all

static void Main(string[] args)
{
    // Load any DWG or DXF file.
    string fName = @"..\..\..\nusajaya.dwg";
    CADImage cadImageSource = CADImage.CreateImageByExtension(fName);
    cadImageSource.LoadFromFile(fName);
    cadImageSource.SetCurrentLayout(0);

    for (int i = 0; i < cadImageSource.Converter.Entities.Count; i++)
    {
        CADEntity entSource = cadImageSource.Converter.Entities[ i ];

        if (entSource.Handle == 1210)
        {
            // Retrieve a CADEntity based on its Handle
            // that is pre-obtained from the Viewer program.
            Console.WriteLine("Type: " + entSource.GetType());
            Console.WriteLine("Color: " + entSource.Color);
            Console.WriteLine("Name: " + entSource.EntName);
            Console.WriteLine("Layer: " + entSource.Layer.Name);
            break;
        }
    }
}
What I am trying to do above is to retrieve a specific CADEntity that initially lookup its color and Handle by using the Viewer. When I run the program above, the CADEntity color that is reported is always [A=47, R=255, G=255, B=255], which is wrong. I had emailed you the sample CAD file that we are working on.

Question #2 is, it seems that each CADEntity has a Handle property, which I assume it is its unique id. I was wondering whether there is anyway to retrieve a specific CADEntity from CADEntityCollection via its Handle?

Thanks!

<b>Objective World Pvt. Ltd.</b>
"<i>Turning Knowledge Into Wisdom.</i>"
http://www.objectiveworld.com

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Post by support » 18 Mar 2008, 11:22

Hi,
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I noticed that the Color property of CADEntity is incorrect on certain CAD files.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
CADConst.clByLayer - A color constant that means an entity's color is determined by layer.
CADConst.clByBlock - A color constant that means an entity's color is determined by block.
CADConst.clNone - A color constant that means an entity's color is undefined.

LWPolyLine, in the file you sent us, has CADConst.clByLayer color:

Code: Select all

<font color="blue">if</font id="blue"> (cadImageSource.CurrentLayout.Entities[j] <font color="blue">is</font id="blue"> CADLWPolyLine)
{
    CADLWPolyLine entLWPoly = (CADLWPolyLine)cadImageSource.CurrentLayout.Entities[j];
    Color entColor;
    <font color="blue">if</font id="blue"> (entLWPoly.Color == CADConst.clByLayer)
        entColor = entLWPoly.Layer.Color;                                        
}
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Question #2 is, it seems that each CADEntity has a Handle property, which I assume it is its unique id. I was wondering whether there is anyway to retrieve a specific CADEntity from CADEntityCollection via its Handle?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Here goes a part of the code from <b>Viewer</b> demo:

Code: Select all

#region Help
          /// <summary>
          /// Adds an entity to the collection.
          /// </summary>
          /// <param name="value">An <see cref="System.Object">Object</see> representing the entity to add to the collection.</param>
#endregion Help
public void Add(Object value)  
{
     string key = string.Empty;
     long ltmp = (value as CADEntity).Handle;
     if(value is CADBlockRecord)
          key = string.Empty + (value as CADPenTableItem).Handle;
     else
          if(value is CADPenTableItem)
          key = (value as CADPenTableItem).Name;
     else 
          if(value is CADXRef)
               key = (value as CADXRef).Name;
     else 
          if(!(value is CADBlock))
          key = value.GetHashCode().ToString();
     else
          key = (value as CADEntity).EntName;
     if(this[key] != null)
          key = key + this.Count;
     this.BaseAdd( key, value );
     (value as CADEntity).keyEnt = key;
}
Thus we recommend to use <i>CADEntity.KeyEnt</i> when it is necessary to get a CADEntity from CADEntityCollection.

Please post questions to the forum or write to support@cadsofttools.com

Post Reply