Exception "Specified method is not supported" on extracting text from DWG (C#)

Hi,

We are using Aspose.CAD version 19.5 and the following code to extract text from DWG, DXF and DWT formats:

        using (var cadImage = (CadImage) Image.Load(input))
        {
            var text = new StringBuilder();

            foreach (var entity in cadImage.Entities)
            {
                var txtFromNodes = ExtractTextFromCadNodes(entity);

                if (string.IsNullOrEmpty(txtFromNodes))
                    continue;

                text.Append(txtFromNodes);
                text.Append(" ");
            }

            foreach (CadBlockEntity blockEntity in cadImage.BlockEntities.Values)
            {
                foreach (var entity in blockEntity.Entities)
                {
                    var txtFromNodes = ExtractTextFromCadNodes(entity);

                    if (string.IsNullOrEmpty(txtFromNodes))
                        continue;

                    text.Append(txtFromNodes);
                    text.Append(" ");
                }
            }

            return text.ToString();
        }

We cannot use this code to extract text from DGN and DWF. We get the exception

System.NotSupportedException : Specified method is not supported.

Is the text extraction achievable for those 2 formats?

Thank you!

@gwert,

I have observed the issue shared by you and request you to please provide the source file that we may use on our end to further investigate the issue.

Hi,

Here they are: cad_dgn_dwf.zip (300.1 KB)

Thank you.

@gwert ,

I like to inform that CadImage is used for dwg and dxf formats. So when you read dgn or dwf format, you can’t cast it to CadImage. DGN format readed into DgnImage, and it has “Elements” property with list of DgnDrawingElementBase entities. DWF format readed into DwfImage, and it has “Pages” property, and every page item has “Entities” property with list of DwfWhipDrawable entities. You have to change your code according to this.

Hi,

I see. Is there any code snippet for this so I could start poking with it?

Thank you!

@gwert,

I have shared code snippet with you for both DGN and DWF formats. Please check following code snippets.

using (DgnImage dgnimage = (DgnImage)Image.Load(path+“036.dgn”))
{
foreach (DgnDrawingElementBase element in dgnimage.Elements)
{
if (element is DgnTextElement)
{
var text = (element as DgnTextElement).Text;
}
}
}

using (DwfImage dwfimage = (DwfImage)Image.Load(path+""))
{
foreach (var page in dwfimage.Pages)
{
foreach (var drawableObject in page.Entities)
{
if (drawableObject is DwfWhipText)
{
var text = (drawableObject as DwfWhipText).Text;
}
}
}
}

Hi,
We are using Aspose.CAD version 19.9.0 and the following code to extract text from DGN format:

      if (fileExtension == "dgn")
        {
            var text = new StringBuilder();
            using (var dgnImage = (DgnImage) Image.Load(input))
            {
                foreach (var element in dgnImage.Elements)
                {
                    if (!(element is DgnTextElement))
                        continue

                    text.Append((element as DgnTextElement).Text);
                    text.Append(" ");
                }
            }

            return text.ToString();
        }

We cannot use this code to extract text from DGN. It would be great if you could take a look ay this issue. Thank you!

This is the file I’m working with, in pdf and dgn formats.dgn.zip (953.9 KB)

@gwert,

I have worked with sample code and sample file using Aspose.CAD for .NET 20.1 and have been able to be to extract the text. For your kind reference, I have attached the sample file where by I have copied extracted text.

Extracted.zip (502 Bytes)