Text in DWG File

Hello,

I have a DWG file that has plenty of text. Are you able to pull the text out using Aspose.CAD? In my example, nothing is being pulled from it. This is for .net.

architectural_-_annotation_scaling_and_multileaders.zip (128.8 KB)

Here is my function that I running the file through

  public static string ExtractTextFromDwg(Stream input)
    {
        var text = new StringBuilder();
        using(CAD.FileFormats.Cad.CadImage cadImage = (CAD.FileFormats.Cad.CadImage)CAD.Image.Load(input))
        {
            foreach(CAD.FileFormats.Cad.CadObjects.CadBaseEntity entity in cadImage.Entities)
            {
                
                try
                {
                    dynamic entitytext = System.Convert.ChangeType(entity,entity.GetType());
                    if (!String.IsNullOrEmpty(entitytext.DefaultValue.ToString()))
                    {
                        text.AppendLine(entitytext.DefaultValue.ToString());
                    }
                }
                catch (Exception e)
                {
                }                    
            }
        }
        return text.ToString();
    }

@gwert,

I have observed your comments. You need to find entity to achieve your requirements. In your case you need to search for Multileader, MTEXT, TEXT entities and theirs corresponding values with text. Below code will help you to achieve your requirements.

foreach (CadBaseEntity baseEntity in entities)
{
// selection or filtration of entities
if (baseEntity.TypeName == CadEntityTypeName.TEXT)
{
filteredEntities.Add(baseEntity);
}
}