text overlapped with other entities in dxf files

26 Views Asked by At

I am trying to find a dxf files that contains text overlapping with other entities like circle, polyline, point.. using netDxf but my code did not work. I have circle radius, center(X,Y) and text position (X,Y):

 string directoryPath = @"C:\Users\Desktop";
 string fileName = "Drawing2.dxf";
 string filePath = Path.Combine(directoryPath, fileName);

 try
 {
     if (File.Exists(filePath))
     {
         // File exists, proceed with loading and checking for overlap
         DxfDocument loaded = DxfDocument.Load(filePath);
         
         List<EntityObject> entityList = loaded.Entities.All.ToList();
         Vector2 TcurrentPosition = Vector2.Zero;
         Vector2 ComputeB= Vector2.Zero;
         foreach (EntityObject entity in entityList)
         {
             if (entity is Text textEntity)
             {
                 // Retrieve the current text position
                 TcurrentPosition = new Vector2(textEntity.Position.X, textEntity.Position.Y);

                 // Display or process the retrieved values as needed
                 Console.WriteLine($"Text Position: X: {textEntity.Position.X}, Y:{textEntity.Position.Y}");
             }
             // Add more conditions for other entity types if needed
             if (entity is Circle circleEntity)
             {
                 // Retrieve the current circle center position
                 Vector2 centerPosition = new Vector2(circleEntity.Center.X, circleEntity.Center.Y);

                 // Display or process the retrieved values as needed
                 double radius = circleEntity.Radius;
                 Console.WriteLine($"Circle Position: X: {centerPosition.X}, Y: {centerPosition.Y}, Radius: {radius}");

                 // Example: Check if a specific point overlaps with the circle
                 Vector2 point1ToCheck = TcurrentPosition;
                 Vector2 point2ToCheck = centerPosition;         
                
                 double distance = Math.Sqrt(Math.Pow(point1ToCheck.X - point2ToCheck.X, 2) + Math.Pow(point1ToCheck.Y - point2ToCheck.Y, 2));
                 if(distance>radius)
                 
                 {
                     Console.WriteLine("Overlap detected!");
                 }
                 else
                 {
                     Console.WriteLine("There is no Overlap detected!");
                 }
             }
         }
     }
     else
     {
         Console.WriteLine($"Error: File not found at {filePath}");
     }
 }
 catch (Exception ex)
 {
     Console.WriteLine($"Error: {ex.Message}");
 }

How can I do this with netDxf? Example DWG snapshot follows:

Screenshot of a DXF file with text overlapping a circle

0

There are 0 best solutions below