how to use CopyToOtherImageTool
Moderators: SDS, support, admin
-
- Posts: 2
- Joined: 23 May 2024, 22:21
how to use CopyToOtherImageTool
i'm trying to evaluate this api for purchase as soon as i can prove it works. i'm having a lot of trouble understanding how to do anything other than what's in some examples on how to save files to different file types. i asked someone in sales and they told me i could use CopyToOtherImageTool and they also told me to make inserts out of the original files which helps paste them to a specific position. i havent found that code yet(creating inserts) but i did try the copy tool and this is my code. is this right? at the end the CADtoDwg.SaveAsDWG is failing and only tells me 'Object reference not set to an instance of an object.' but doesnt help me any more. from what i can tell i have a cadimage and a proper dwg file path selected as i am just opening a drawing and saving over it to the same name.
using CADImport;
using CADImport.Export;
using PRO = CADImport.Professional;
private void AddEntitiesToDrawing(string dxfDrawing, string drawingName, Point3D origin)
{
// copy entities and blocks from a dxf to the dwg
CADImage sourceCadImage = CADImage.CreateImageByExtension(dxfDrawing);
CADEntityCollection cadEntities = sourceCadImage.Converter.Entities;
CADEntityCollection cadBlocks = sourceCadImage.Converter.Blocks;
CADImage drawing = CADImage.CreateImageByExtension(_outputFile);
PRO.CopyToOtherImageTool copyTool = new PRO.CopyToOtherImageTool(drawing);
copyTool.CopyEntities(cadEntities);
copyTool.CopyEntities(cadBlocks);
copyTool.ActivateTool();
// add layout using drawingName later
// save the dwg
CADtoDWG.SaveAsDWG(drawing, _outputFile);
}
using CADImport;
using CADImport.Export;
using PRO = CADImport.Professional;
private void AddEntitiesToDrawing(string dxfDrawing, string drawingName, Point3D origin)
{
// copy entities and blocks from a dxf to the dwg
CADImage sourceCadImage = CADImage.CreateImageByExtension(dxfDrawing);
CADEntityCollection cadEntities = sourceCadImage.Converter.Entities;
CADEntityCollection cadBlocks = sourceCadImage.Converter.Blocks;
CADImage drawing = CADImage.CreateImageByExtension(_outputFile);
PRO.CopyToOtherImageTool copyTool = new PRO.CopyToOtherImageTool(drawing);
copyTool.CopyEntities(cadEntities);
copyTool.CopyEntities(cadBlocks);
copyTool.ActivateTool();
// add layout using drawingName later
// save the dwg
CADtoDWG.SaveAsDWG(drawing, _outputFile);
}
Re: how to use CopyToOtherImageTool
The CopyEntities method returns the list of copied elements, which needs placing to the necessary position. Here is an example:
Code: Select all
private void AddEntitiesToDrawing(string dxfDrawing, string drawingName, Point3D origin)
{
string _outputFile = @"D://New.dxf";
// copy entities and blocks from a dxf to the dwg
CADImage sourceCadImage = CADImage.CreateImageByExtension(dxfDrawing);
sourceCadImage.LoadFromFile(dxfDrawing);
CADEntityCollection cadEntities = sourceCadImage.Converter.Entities;
CADEntityCollection cadBlocks = sourceCadImage.Converter.Blocks;
CADImage drawing = CADImage.CreateImageByExtension(_outputFile);
drawing.LoadFromFile(_outputFile);
CopyToOtherImageTool copyTool = new CopyToOtherImageTool(drawing);
copyTool.ActivateTool();
var copideEnts = copyTool.CopyEntities(cadEntities);
var copiedBlocks = copyTool.CopyEntities(cadBlocks); // copy only if you need all the blocks even if they are not on the layout
foreach (CADEntity entity in copideEnts)
{
drawing.Converter.GetSection(ConvSection.Entities).AddEntity(entity);
}
foreach (CADEntity entity in copiedBlocks)
{
drawing.Converter.GetSection(ConvSection.Blocks).AddEntity(entity);
}
// add layout using drawingName later
// save the dwg
CADtoDWG.SaveAsDWG(drawing, _outputFile);
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 2
- Joined: 23 May 2024, 22:21
Re: how to use CopyToOtherImageTool
this doesnt output anything. all i get with this is a cadfile with your watermark in it just as i got with my code once i got it working without the foreach statements. i went further and even tried drawing.converter.loads(entity) and that didnt have any result either. i've attached the dwg file and a picture.