Export selection as png using javascript

Hi,

I am trying to export selection to PNG file using simple javascript in CorelDraw 2019:

var opt = host.StructExportOptions;
opt.AntiAliasingType = host.cdrNormalAntiAliasing//getting error: Cannot set property 'AntiAliasingType' of undefined
opt.ImageType = host.cdrRGBColorImage;
opt.Overwrite = true;
opt.ResolutionX =300;
opt.ResolutionY = 300;
exportFileName = "d:\\test.png";
host.ActiveDocument.Export(exportFileName,host.cdrPNGhost.cdrSelectionoptundefined);
on the second line, I get error: Cannot set property 'AntiAliasingType' of undefined. Lines below it starting with opt will produce a similar error.
Please help in refining the code. Thanks in advance.
  • try change opt.AntiAliasingType = host.cdrNormalAntiAliasing; to opt.AntiAliasingType = 1

    • Thanks. But I get the same error with opt.AntiAliasingType = 1.

      BTW, I just need javascript that would export the ActiveSelection to PNG file.

      • try export your document by using ActiveDocument.ExportBitmap. In this case, you will not need to use StructExportOptions

        • So I tried:

          1. filter= host.ActiveDocument.ExportBitmap("d:\\test.png"host.cdrPNGhost.cdrSelectionhost.cdrRGBColorImage0, 0300300host.cdrNormalAntiAliasingfalsetruetruefalsehost.cdrCompressionNone,undefined,undefined);
          2. filter.finish();
          but still got same error at line 2: TypeError: cannot read property 'finish' of the undefined
          • use ExportBitmap as sub (without "filter="), not as function. And just remove 2nd line

            • I am scripting in javascript to use on mac.

              "sub" don't work in javascript.

              • i mean instead filter= host.ActiveDocument.ExportBitmap("d:\\test.png", host.cdrPNG, ...

                try use host.ActiveDocument.ExportBitmap("d:\\test.png", host.cdrPNG, ...