//format autocad 2018
private void ReadDxfFile(string DxfFile)
{
DxfFile = System.IO.File.ReadAllText(DxfFile);
string Layer = "";
//because I'm italian
DxfFile = DxfFile.Replace(".", ",");
string[] D = DxfFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
int iEntities = 0;// for (int i = 0; i < D.Length; i++) { if (D[i] == "ENTITIES") { iEntities = i; break; } }
for (int i = iEntities; i < D.Length; i++)
{
if (D[i] == "POINT" || D[i] == "AcDbPoint")
{
int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == " 8") { Layer = D[iLayer + 1]; }; }
for (int iWaarden = i; iWaarden < i + 8; iWaarden++)
{
if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
{
//Here you can store the following data in a list for later use
//LayerName = Layer
string X = D[iWaarden + 1];
string Y = D[iWaarden + 3];
string Z = D[iWaarden + 5];
}
}
}
if (D[i] == "LINE" || D[i] == "AcDbLine")
{
int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == " 8") { Layer = D[iLayer + 1]; }; }
for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
{
if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
{
//Here you can store the following data in a list for later use
//LayerName = Layer
lines.Add(new List<double>());
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 1])); //Xbegin
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 3])); //Ybegin
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 5])); //Zbegin
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 7])); //Xend
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 9])); //Yend
lines[lines.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 11])); //Zend
}
}
}
if (D[i] == "CIRCLE" || D[i] == "AcDbCircle")
{
int iEntity = i; if (D[i].StartsWith("AcDb")) { for (iEntity = i; D[iEntity] != "AcDbEntity"; iEntity--) ; }
Layer = ""; for (int iLayer = iEntity; iLayer < i + 10 && Layer == ""; iLayer++) { if (D[iLayer] == " 8") { Layer = D[iLayer + 1]; }; }
for (int iWaarden = i; iWaarden < i + 10; iWaarden++)
{
if (D[iWaarden] == " 10" && D[iWaarden + 2] == " 20")
{
//Here you can store the following data in a list for later use
//LayerName = Layer
arcs.Add(new List<double>());
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 1])); //Xmid
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 3])); //Ymid
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 5])); //Zmid
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 7])); //Radious
//Check if this is an arc
if (D[iWaarden + 8] == "100")
{
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 11])); //StartAngle
arcs[arcs.Count() - 1].Add(Convert.ToDouble(D[iWaarden + 13])); //EndAngle
}
else
{
arcs[arcs.Count() - 1].Add(0); //StartAngle
arcs[arcs.Count() - 1].Add(360); //EndAngle
}
}
}
}
}
}