Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Accessing Layout Previews

It is possible to store in .dwg file not only the preview of the whole drawing, but also individual previews for each layout.

Layouts' previews are stored in .png format, therefore Raster Services module supporting .png format is required. To load Raster Service module, use the following code:


OdRxRasterServicesPtr pRasSvcs = ::odrxDynamicLinker()->loadApp(RX_RASTER_SERVICES_APPNAME);

Getting preview image

To get a raster image with the layout preview, use getPreviewImage() method.

For an example, to get a preview image for a layout specified with its name, use the following code:


OdGiRasterImagePtr pImg;
OdDbObjectId id = m_pDb->findLayoutNamed(OdString(m_sNewLayoutName));
OdDbLayoutPtr layout = id.safeOpenObject(OdDb::kForWrite);
if ( !layout.isNull() )
{
  pImg = layout->getPreviewImage();
}
m_Preview.SetImage(pImg);

In the code above it is assumed that m_pDb is a valid pointer referencing to an opened database. To get layout's ID, findLayoutNamed() method is used.

If layout is successfully opened, getPreviewImage() method is called to get preview image. pImg is set as an image for the GUI component m_Preview.

Setting preview image

To set a raster image as a new preview of the layout, call setPreviewImage() method.

For an example, to set a previously created .png file as a preview image for a layout specified with its name, use the following code:


OdGiRasterImagePtr pImg;

...

OdDbObjectId id = m_pDb->findLayoutNamed(OdString(m_sNewLayoutName));
OdDbLayoutPtr layout = id.safeOpenObject(OdDb::kForWrite);
if ( !layout.isNull() )
{
  layout->setPreviewImage(pImg);
}

Example application

Sample code for working with layout previews can be found in the sample MFC application (OdaMfcApp). Source code of the OdaMfcApp is located in Drawing\Examples\win\OdaMfcApp.

See Also

Working with Layouts

Making a Layout Active

Example of Working with the Layout Object

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.