Hello,
Is it possible to convert dxf file to dwg file using aspose lib?
Hello,
Is it possible to convert dxf file to dwg file using aspose lib?
@msdos41,
Hi.
Here is the basic example:
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileName))
{
cadImage.Save("result.dwg", new DwgOptions());
}
Here is my current code:
using (var cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(dxfPath))
{
var dwgPath = Path.Combine(saveFolder, $"{Path.GetFileNameWithoutExtension(filePath)}_{DateTime.Now:yyyyMMddHHmmssffff}.dwg");
var options = new Aspose.CAD.ImageOptions.DwgOptions();
var format = options.TargetFormat;
cadImage.Save(dwgPath, options);
}
Here is 2 problems:
I have another quesion. I am using aspose.cad to load dxf file. Is it possible to parse the elements in the dxf file and remove some of them? Like the graphic in the attachment above, I want to delete the rectangle boundaries in the dxf file.
@msdos41,
Hi.
Removing entities from DXF is possible, the main question seems to be - how to identify the required entities. Here is the basic example how to remove border for the file above (the border is polyline and is identified by quantity of vertices in it):
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileName))
{
List<CadEntityBase> entitiesToRemove = new List<CadEntityBase>();
foreach (CadEntityBase ceb in cadImage.Entities)
{
System.Console.WriteLine(ceb.TypeName);
if (ceb.TypeName == CadEntityTypeName.POLYLINE)
{
CadPolyline polyline = (CadPolyline)ceb;
if (polyline.ChildObjects.Count == 6)
{
entitiesToRemove.Add(ceb);
}
}
}
List<CadEntityBase> entities = new List<CadEntityBase>(cadImage.Entities);
foreach (CadEntityBase ceb in entitiesToRemove)
{
cadImage.TryRemoveEntity(ceb);
entities.Remove(ceb);
}
cadImage.Entities = entities;
cadImage.UpdateSize();
cadImage.Save(outPath);
}
@oleksii.gorokhovatskyi
Hi, I tried directly save as dwg without DwgOptions. But it occurred an error. Check out the attachment.
using (var cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(dxfPath))
{
var dwgPath = Path.Combine(saveFolder, $"{Path.GetFileNameWithoutExtension(filePath)}_{DateTime.Now:yyyyMMddHHmmssffff}.dwg");
cadImage.Save(dwgPath);
}
error.PNG (8.3 KB)
@msdos41,
Hi.
The common idea of using cadImage.Save() without any options is the preserving of the initial format, but it works a bit differently for DXF/DWG now. For this case the initial DXF has R12 format and writing it to DWG of the same format is not possible, so message with error occurs. The recommended way to do DXF to DWG is using DWG options, e.g., cadImage.Save(outPath, new DwgOptions()).
Hi, I am using Aspose.Imaging lib to convert svg to dxf, then use that dxf convert to dwg.
You meant the dxf format is R12. So which format could be converted to dwg without options? How to do it?
My svg to dxf codes:
using (var image = Aspose.Imaging.Image.Load(filePath))
{
// Create an instance of DxfOptions
var exportOptions = new Aspose.Imaging.ImageOptions.DxfOptions() { TextAsLines = false, ConvertTextBeziers = true };
Aspose.Imaging.ImageOptions.VectorRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions();
rasterizationOptions.PageWidth = image.Width;
rasterizationOptions.PageHeight = image.Height;
rasterizationOptions.FullFrame = false;
exportOptions.VectorRasterizationOptions = rasterizationOptions;
// Save svg to dxf
var dxfPath = Path.Combine(saveFolder, $"{Path.GetFileNameWithoutExtension(filePath)}_{DateTime.Now:yyyyMMddHHmmssffff}.dxf");
image.Save(dxfPath, exportOptions, Aspose.Imaging.Rectangle.Empty);
}
@msdos41,
Hi.
During the conversion between different formats the expected and correct way is to use options. So, now you can convert DXF R12 and other DXF formats to DWG 2018 with new DwgOptions(). Conversion from DXF to DWG without options causing errors at the moment, we have created CADNET-9670 to cover them, but this is not preferrable way to do this conversion. Unfortuntely we don’t have yet the support to convert DXF R12 to more recent DXF (e.g., 2018) that could be helpful here with the goal to use saving to DWG without options. Aspose.Imaging has support for DXF R12 only too.