hi i am using .Net library and want to merge 2 CAD files over each on start position.
I have tried understanding your requirements and request you to please provide the source files along with desired merged CAD file that you want to generate on your end. We will investigate the requirements on our end to help you further.
Is there no sample method to do so or your library doesn’t provide any such feature. I wan to add a DXF file as background layout for another DXF file.
I have observed your requirements and regret to share that at present the requested support is unavailable in API. A ticket with ID CADNET-822 has been created as in our issue tracking system as a new feature request. Our development team will look into the possibility of implementation of the requested feature. This thread has been associated with this new feature request, so that you can be automatically notified as soon as this issue is resolved.
Has there been any progress on this topic or ticket CADNET-822? We have a similar application where we look to merge multiple *.dwg files and then export the result to a raster image file.
@brockshew,
Hello.
CADNET-822 was resolved, but it was about DXF files and merging one of them as background. Could you please share the sample DWG files and describe (or provide) the expected result of merging in more details?
MERGE-SAMPLE.zip (827.5 KB)
I have attached a zipped folder with a sample of the desired process. The component files listed below are merged together to form the full geometry described in COMPLETE.dwg. Then the result of the merge operation is exported to a bitmap image. Is the Aspose.CAD software capable of performing the necessary operations?
Component Files
- CORD.dwg
- MODSCH.dwg
- MODULARDISCONNECT.dwg
- PRIMSCH1.dwg
@brockshew,
This seems to be feasible but with some notes. The content of the entire DWG file could be inserted into another (this is shown in example below), or we can also think about to iterate over entities in all files and copy them. But the crucial question here is the position where the content of the embedded files shoud be placed. In the example below we found position in AutoCAD, probably, they could be calculated from the content of the drawings (e.g., searching for some known entities to evaluate coordinates for each part or matching entities between files).
Here is the idea how to embed two test files inside another one and export result to PNG:
string fileNameBackground = "PRIMSCH1.dwg";
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(fileNameBackground))
{
AddDwg(cadImage, "MODSCH.dwg", new Cad3DPoint(0, 6.1696));
AddDwg(cadImage, "CORD.dwg", new Cad3DPoint(11.08, 3.72));
cadImage.UpdateSize();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.PageHeight = 2000;
cadRasterizationOptions.PageWidth = 2000;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
PngOptions pngOptions = new PngOptions();
pngOptions.VectorRasterizationOptions = cadRasterizationOptions;
cadImage.Save(fileNameBackground + ".png", pngOptions);
}
private static void AddDwg(CadImage cadImage, string fileName, Cad3DPoint insertionPoint)
{
CadInsertObject newInsert = new CadInsertObject();
newInsert.Name = fileName;
newInsert.LayerName = "0";
newInsert.InsertionPoint = insertionPoint;
CadBlockDictionary allBlocks = cadImage.BlockEntities;
CadBlockEntity newBlock = new CadBlockEntity();
newBlock.XRefPathName = fileName;
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 = blockEntities.ToArray();
}