First,
I usually use two CAD images (one is a template, the other is loaded from a source file to edit).
when I clone a entity from a template CAD image, the handle is the same as the one cloned in the template CAD image.
And then, I add the cloned entity to a source CAD image.
I think... if the handle value is already contained in a source CAD image, it will conflict with each other when opening output.dwg file converted from the source CAD image.
Can I manage the handles of entities cloned? Reordering or Editing?
Second,
I cloned Color and CADHatch and add them to an empty CAD image successfully.
CADDimension, however, doesn't work. All Code is working clearly, but the output.dwg is not opened.
The error message 'Drawing file is not valid' is poped up on CADViewer (Autodesk DWG TrueView 2018).
The code is below.
Code: Select all
string dwgFile = "dimention.dwg"; // <-- Template dwg file
CADImage cadImage = null;
cadImage = CADImage.CreateImageByExtension(dwgFile);
cadImage.LoadFromFile(dwgFile);
CADImage cadImage2 = new CADImage();
cadImage2.InitialNewImage();
//CADLayer vlayer = cadImage2.Converter.LayerByName("tempLayer");
CADDimension dimensionL = new CADDimension();
foreach (var entity in cadImage.Converter.Entities)
{
if (entity.GetType() == typeof(CADDimension))
{
dimensionL.Clone(entity);
break;
}
}
//dimensionL.LinDefPoint1 = new DPoint(100, 100, 0);
//dimensionL.LinDefPoint2 = new DPoint(100, 1000, 0);
//dimensionL.DefPoint = new DPoint(100, 500, 0);
//dimensionL.TextPosVert = DimTextPosVert.Center;
//dimensionL.TextAlign = 0;
////dimensionL.Style = vDimStyle;
//dimensionL.Layer = vlayer;
//dimensionL.Color = System.Drawing.Color.White;
cadImage2.Converter.Loads(dimensionL);
cadImage2.Layouts[0].AddEntity(dimensionL);
//cadImage2.GetExtents();
CADImport.Export.CADtoDWG.SaveAsDWG(cadImage2, "output.dwg");
if (cadImage != null)
{
cadImage.ClearBuffer();
cadImage.Dispose();
cadImage = null;
}
if (cadImage2 != null)
{
cadImage2.ClearBuffer();
cadImage2.Dispose();
cadImage2 = null;
}
GC.Collect();