Block and drawing quality decreasing

Hi,

I am trying to use differents blocks from differents sources from my computer and use them in a single drawing. The issue is that when I copy a block in my current drawing, the block quality decreases and the block is not a block anymore, but just lines, as well as the text becoming lines. The quality of the rest of my current drawing also decreases the same way. Here is my code:

string dwgPath = Path.Combine(Environment.CurrentDirectory, “DWG”, “CAD_TO_EDIT.dwg”);
string outPath = Path.Combine(Environment.CurrentDirectory, “EDITED_CAD.DXF”);
string sourceBlockPath = Path.Combine(Environment.CurrentDirectory, “DWG”, “Blocs”, “BLOCK_1.dwg”); // That directly the block, not a drawing with the block inside

using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(dwgPath))
{
CadInsertObject newInsert = new CadInsertObject();
newInsert.Name = “BLOCK_1”;
newInsert.ObjectHandle = “O6”; // I’m not sure what I’m suppose to write here
newInsert.LayerName = “Model”;
newInsert.InsertionPoint.X = 0;
newInsert.InsertionPoint.Y = 0;

CadBlockDictionary allBlocks = cadImage.BlockEntities;
CadBlockEntity newBlock = new CadBlockEntity();
newBlock.XRefPathName = sourceBlockPath;
allBlocks.Add(newInsert.Name, newBlock);
cadImage.BlockEntities = allBlocks;

List<CadEntityBase> entities = new List<CadEntityBase>(cadImage.Entities);
entities.Add(newInsert);
cadImage.Entities = entities.ToArray();

CadBlockTableObject blockTableObjectReference = null;
CadBlockEntity cadBlockEntity = null;

foreach (CadBlockTableObject tableObject in cadImage.BlocksTables)
{
    if (string.Equals(tableObject.HardPointerToLayout, cadImage.Layouts["Model"].ObjectHandle))
    {
        blockTableObjectReference = tableObject;
        break;
    }
}
if (blockTableObjectReference != null && cadImage.BlockEntities.ContainsKey(blockTableObjectReference.BlockName))
{
    cadBlockEntity = cadImage.BlockEntities[blockTableObjectReference.BlockName];
}

List<CadEntityBase> blockEntities = new List<CadEntityBase>(cadBlockEntity.Entities);
blockEntities.Add(newInsert);
cadBlockEntity.Entities = entities.ToArray();

cadImage.UpdateSize();
cadImage.Save(outPath, new DxfOptions());

}

Here is my files:

Aspose_question.zip (195,8 Ko)

@SamCroteau,
Hello.
The result as polylines is expected during saving image with DxfOptions(). Saving without them:

cadImage.Save(outPath);

should preserve entities. But unfortunately this export doesn’t work now for this case. We have created CADNET-9852 to investigate the reasons and fix it.

Basically, the library can’t write dwg? What is it CADNET-9852? And where can I find it?

Thank you!

@SamCroteau,
we can write DWG (but 2018 only) in the same way like DXF, as polylines or not. But errors may occur sometimes anyway, so don’t hesitate contacting us about them, we will investigate and fix.
CADNET-9852 is the ID of the task in our bugtracking system you can refer to. You can see the status of the task at the bottom of the current page with this thread.

Okay thank you, so about my issue, why the quality is decreasing? Block are becoming lines and don’t stay blocks, texts are also becoming lines and the lines are becoming bigger like the overall drawing quality seems to decreases when I use DxfOptions. If I don’t use any options (so Dwg), I can’t open the file because the file is corrupt.

Can you try my code and try to fix it or give an example of adding a block from an other dwg in a drawing?

Also, Just to be sure, what .NET framework should I use for the best results?

Thank you!!

@SamCroteau,
The quality is decreasing because it is implemented now is Aspose.CAD in such a way that everything is exploded into lines with DxfOptions. We have already tried your example, of course, thank you, it is easily reproducible with your code. We saw that the file is corrupted after export without options, that’s why we have created separate task to resolve it. You code seems to be fine for now, probably, we will modify it when have more details about sources of the issue. Results of export should be the same for all .NET versions.