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)