...
using CADImport;
using CADImport.DWG;
using CADImport.DXF;
using CADImport.RasterImage;
...
private void Access_texts_Click(object sender, EventArgs e)
{
//CADImage.CreateImageByExtension detects format by the extension specified in the argument.
//The correct class for any supported format will be used automatically. We recommend to
//create a new drawing object with CADImage.CreateImageByExtension if import from the existed
//file/stream is required.
CADImage vDrawing = CADImage.CreateImageByExtension(@"..\..\..\Files\Entities.dxf");
vDrawing.LoadFromFile(@"..\..\..\Files\Entities.dxf");
// Adjusting visualization sizes to the control area:
RectangleF vRect;
double vRatio = (double)(vDrawing.AbsHeight * Image1.ClientSize.Width) / (vDrawing.AbsWidth * Image1.ClientSize.Height);
if (vRatio > 1)
vRect = new RectangleF(0, 0, (float)(Image1.ClientSize.Width / vRatio), (float)Image1.ClientSize.Height);
else
vRect = new RectangleF(0, 0, (float)Image1.ClientSize.Width, (float)(Image1.ClientSize.Height * vRatio));
//-----------------------------------------------
vDrawing.Draw(Image1.CreateGraphics(), vRect);
string S = "";
for (int i = 0; i < vDrawing.CurrentLayout.Count; i++)
{
if (vDrawing.CurrentLayout.Entities[i].EntType == EntityType.Text)
{
CADText vText = (CADText)vDrawing.CurrentLayout.Entities[i];
MessageBox.Show("Text: " + vText.Text);
}
if (vDrawing.CurrentLayout.Entities[i].EntType == EntityType.MText)
{
CADMText vMText = (CADMText)vDrawing.CurrentLayout.Entities[i];
for (int j = 0; j < vMText.Block.Count; j++)
S = S + ((CADText)vMText.Block.Entities[j]).Text + "\n";
MessageBox.Show("MText:\n" + S);
S = "";
}
}
}