It take a long time to convert a dwg file to png with high resolution

The rendering performance is not obvious. What does rasterization speed have to do with? The resolution、 the size of the dwg or the Graphics card?

@cuipz_coalinfo_net_cn

Can you please provide the source file, generated output and desired output quality that you like to achieve so that we can investigate it further on our end. Earlier, the issue added in thread was related to performance of the API in terms of rendering time.
Please also share the used sample code.

We want to convert the Huangling.dwg file to pngs with a high resolution, 0.25 meter per pixel or 0.125 meter per pixel。
The dwg file and the C# code is in zip.
链接:https://pan.baidu.com/s/1Ok0uyuWmxOxnhsUa_geqNw
提取码:x5tv
or
http://frc.tpddns.cn:1108/sharing/Cy8WJKjbp

@cuipz_coalinfo_net_cn

Can you please share on some other source as it is asking me to register first.

image.jpg (153.4 KB)

Please, try the second link http://frc.tpddns.cn:1108/sharing/Cy8WJKjbp.

@cuipz_coalinfo_net_cn

I regret to share that I am still unable to access the link shared by you.

image.png (68.7 KB)

I am sorry,the link is ok。
http://117.107.134.126:21704/DOM/2021-02-10.zip

@cuipz_coalinfo_net_cn
I regret to share that I am unable to access the shared link. I have tried multiple browsers. The shared link opens blank page for me. Can you please upload on Google drive or Dropbox and then provide the link to us.

image.png (82.3 KB)

http://117.107.134.126:21702/DOM/2021-02-10.zip
I was on the Spring Festical holiday, I am sorry replyed you later.
The link above is valid.

@cuipz_coalinfo_net_cn

I hope you must have enjoyed the holidays. Unfortunately, I have tried to access the file from your link a number of times but its always failing and extremely slow. Although, I am using an extremely good internet connection.
image.png (88.3 KB)

Thank you for your patience and continued support.
Google Drive Sharing link:

@cuipz_coalinfo_net_cn

I have created a ticket with ID CADNET-1340 in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thank you! I will continuous tracking.

@cuipz_coalinfo_net_cn

You are welcome. We will share updates with you as soon as they will be available.

@cuipz_coalinfo_net_cn

We have investigated the requirements on our end and there are some observations and suggestions for you in this regard. The trouble of initially slow processing are hatches. Here are our advices:

  • You may set low quality just for hatches (not for the text): Hatch = RasterizationQualityValue.Low and this improved the speed significantly: the time required to export just first part of the drawing to png according to his code without quality options is about 1000 sec. It is 90 sec. with Low quality only for hatches.

  • You may consider improve DWG for future drawings if he can to fit our product better. GRAVEL hatch pattern type which is used here is one of the most complex as it contains 42 separate hatch lines which we need to combine accurately to preserve the initial pattern. And this problem becomes more sharp when hatch boundary is far away from the origin point which is set up for hatches. This drawing contains few such hatches with origin point far away.

  • The last option is to move hatch origin point programmatically if it is far away. Here is idea and code example how to do it:

      foreach (ICadBaseEntity entity in cadImage.Entities)
      {
    
          // find hatches
          if (entity.TypeName == CadEntityTypeName.HATCH)
          {
              ICadHatch hatch = (ICadHatch)entity;
    
              ICadBaseEntity hatchEntity = (ICadBaseEntity)(hatch.BoundaryPaths[0].BoundaryPath[0].Objects[0]);
              Cad3DPoint firstPoint = null;
    
              // find first hacth boundary entity and get first point in it to understand where is boundary.
              // Only LINE and VERTEX are implemented for example. All other possible types are listed.
              switch (hatchEntity.TypeName)
              {
                  case CadEntityTypeName.ARC:
                      {
                          break;
                      }
    
                  case CadEntityTypeName.LINE:
                      {
                          ICadLine line = (ICadLine)hatchEntity;
                          firstPoint = line.FirstPoint;
                          break;
                      }
    
                  case CadEntityTypeName.VERTEX:
                      {
                          ICadVertexBase vertex = (ICadVertexBase)hatchEntity;
                          firstPoint = vertex.LocationPoint;
                          break;
                      }
    
                  case CadEntityTypeName.SPLINE:
                      {
                          break;
                      }
    
                  case CadEntityTypeName.LWPOLYLINE:
                      {
                          break;
                      }
    
                  case CadEntityTypeName.ELLIPSE:
                      {
                          break;
                      }
              }
    
              bool requiresShift = false;
              double distanceX = 0, distanceY = 0;
    
              // get the distance from the origin point to the first hatch pattern line
              // if it is far away - differences are calculated
              if (hatch.PatternDefinitions.Count > 0)
              {
                  if (Math.Abs(hatch.PatternDefinitions[0].LineBasePoint.X - firstPoint.X) > 20000 || Math.Abs(hatch.PatternDefinitions[0].LineBasePoint.Y - firstPoint.Y) > 20000)
                  {
                      requiresShift = true;
                      distanceX = hatch.PatternDefinitions[0].LineBasePoint.X - firstPoint.X;
                      distanceY = hatch.PatternDefinitions[0].LineBasePoint.Y - firstPoint.Y;
    
                  }
              }
    
              // all hacth pattern lines should be moved at the same distance to preserve hatch pattern view
              if (requiresShift)
              {
                  foreach (ICadHatchPatternData d in hatch.PatternDefinitions)
                  {
                      d.LineBasePoint.X -= distanceX;
                      d.LineBasePoint.Y -= distanceY;
                  }
              }
          }
      }
    

Two important notes for this example are: it will probably not working in 3D but this drawing is flat. And such moving of the pattern origin lines in hatch will not preserve exactly the same view like it is shown in Autocad - the pattern inside hatch boundary will be shifted. I am not sure whether this is important for you though.
The time for this approach without decreasing the quality at all is about 120 sec.

Thank you for your advices! I will test it。

I delete all hatch from the dwg file.and set low quality just for hatches (not for the text): Hatch = RasterizationQualityValue.Low。 then do raster, It take a long time 。
Is there any difference ? Can you provide your whole sample code and the dwg file?

Can you please share how long does it take? Here is the update for point 3 with the new public API:

foreach (CadBaseEntity entity in cadImage.Entities)
                        {
                            if (entity.TypeName == CadEntityTypeName.HATCH)
                            {
                                CadHatch hatch = (CadHatch)entity;

                                if (hatch.PatternDefinitions.Count > 0)
                                {
                                    Point2D firstPoint = new Point2D(hatch.PatternDefinitions[0].LineBasePoint.X, hatch.PatternDefinitions[0].LineBasePoint.Y);

                                    if (hatch.BoundaryPaths[0].BoundaryPath[0].GetType() == typeof(CadPolylineBoundaryPath))
                                    {
                                        CadPolylineBoundaryPath polyline = (CadPolylineBoundaryPath)(hatch.BoundaryPaths[0].BoundaryPath[0]);
                                        firstPoint = polyline.Vertices[0];
                                    }
                                    else
                                    {
                                        CadEdgeBoundaryPath edgePath = (CadEdgeBoundaryPath)(hatch.BoundaryPaths[0].BoundaryPath[0]);

                                        if (edgePath.Objects[0].GetType() == typeof(CadBoundaryPathLine))
                                        {
                                            CadBoundaryPathLine line = (CadBoundaryPathLine)edgePath.Objects[0];
                                            firstPoint = line.FirstPoint;
                                        }

                                        if (edgePath.Objects[0].GetType() == typeof(CadBoundaryPathCircularArc))
                                        {
                                            // TODO
                                        }

                                        if (edgePath.Objects[0].GetType() == typeof(CadBoundaryPathCircularEllipse))
                                        {
                                            // TODO
                                        }

                                        if (edgePath.Objects[0].GetType() == typeof(CadBoundaryPathSpline))
                                        {
                                            // TODO
                                        }
                                    }


                                    bool requiresShift = false;
                                    double distanceX = 0, distanceY = 0;

                                    if (Math.Abs(hatch.PatternDefinitions[0].LineBasePoint.X - firstPoint.X) > 20000
                                        || Math.Abs(hatch.PatternDefinitions[0].LineBasePoint.Y - firstPoint.Y) > 20000)
                                    {
                                        requiresShift = true;
                                        distanceX = hatch.PatternDefinitions[0].LineBasePoint.X - firstPoint.X;
                                        distanceY = hatch.PatternDefinitions[0].LineBasePoint.Y - firstPoint.Y;
                                    }

                                    if (requiresShift)
                                    {
                                        foreach (CadHatchPatternData d in hatch.PatternDefinitions)
                                        {
                                            d.LineBasePoint.X -= distanceX;
                                            d.LineBasePoint.Y -= distanceY;
                                        }
                                    }
                                }
                            }
}

Do you use the .NET SDK with the version 21.3?

@cuipz_coalinfo_net_cn

You only need to have .NET Framework installed.