Creating bitmap using selected CADEntities
Moderators: SDS, support, admin
Creating bitmap using selected CADEntities
Hello,
I want to create a bitmap using only the selected CADEntities (in CADEditorControl). I think easy way to do is to set visible property to false for all non selected CADEntities and save it as bitmap, but I don't want to iterate through all CADEntities so tried
creating a new cad image and
used cadImage.CopyEntities and cadImage.PasteEntities to copy the selected entities into new CADImage
code seems to be working fine for most cases but not for CADCurvePolygons.
It is working fine after using cadEntity.AssignEntity for all copied entities,
Not sure why I have to copy the entities again????
but these new CADEntities(CADCurvePolygons) are getting reset(CADCurvePolygon.Boundaries return 0) if I use cadImage.SetNewPosEntity.
What is the best way to create a new CADImage using the selected CADEntities(in CADEditorControl)?
Thanks
Ravi
I want to create a bitmap using only the selected CADEntities (in CADEditorControl). I think easy way to do is to set visible property to false for all non selected CADEntities and save it as bitmap, but I don't want to iterate through all CADEntities so tried
creating a new cad image and
used cadImage.CopyEntities and cadImage.PasteEntities to copy the selected entities into new CADImage
Code: Select all
CADImage cadImage = CADImage.CreateImageByExtension(this.m_strSelectedCADFilePath);
cadImage.Converter.HeadStruct = (HeadVarStruct)cadImage.Converter.HeadStruct.Clone();
cadImage.CopyEntities(m_cadEditorControl.Image.SelectedEntities);
cadImage.PasteEntities();
It is working fine after using cadEntity.AssignEntity for all copied entities,
Not sure why I have to copy the entities again????
Code: Select all
int nCount = 0
foreach(CADEntity cadEntity in cadImage.Converter.Entities)
{
cadEntity.AssignEntity(m_cadEditorControl.Image.SelectedEntities[nCount]);
nCount++
}
Code: Select all
foreach(CADEntity cadEntity in cadImage.Converter.Entities)
{
cadImage.SetNewPosEntity(100, 100, 0, cadEntity);
}
Thanks
Ravi
Re: Creating bitmap using selected CADEntities
Hello Ravi,
You may try the another way: create a new temporary layout for the existing CADImage, copy the selected entities onto this layout, set the layout as current, then save it as bitmap using a CADImage.SaveToFile method. For example:
Mikhail
You may try the another way: create a new temporary layout for the existing CADImage, copy the selected entities onto this layout, set the layout as current, then save it as bitmap using a CADImage.SaveToFile method. For example:
Code: Select all
using CADImport;
...
SaveFileDialog saveDialog;
public Form1()
{
InitializeComponent();
saveDialog = new SaveFileDialog();
saveDialog.Filter = "Bitmap(*.bmp)|*.bmp";
}
...
if (cadEditorControl1.Image == null || saveDialog.ShowDialog() != DialogResult.OK) return;
CADImage img;
CADLayout newlay = new CADLayout();
newlay.Name = "Layout1";
img = cadEditorControl1.Image;
CADLayout prevLayout = img.CurrentLayout;
img.Converter.AddLayout(newlay);
foreach (CADEntity ent in img.SelectedEntities)
{
newlay.AddEntity(ent);
}
img.GetExtents();
img.CurrentLayout = newlay;
img.ClearSelection();
img.ClearMarkers();
DRect imgRect = new DRect(0, 0, img.PureExtents.Width, img.PureExtents.Height);
img.SaveToFile(saveDialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp, imgRect);
img.CurrentLayout = prevLayout;
img.Layouts.Entities.Remove(newlay);
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support