How to export image between two points in Model Space

How to export image between two points in Model Space

amirmoaz26
Observer Observer
227 Views
4 Replies
Message 1 of 5

How to export image between two points in Model Space

amirmoaz26
Observer
Observer

Hi everyone,

I want to export a portion of the Model Space as an image file (PNG/JPEG). Specifically, I’d like to define two corner points (like a window) and then generate an image that covers only that area of the drawing.

I’ve already managed to do this using a BMP export, but the resolution is very low and the output quality isn’t acceptable. What I need is a higher-quality image (PNG/JPEG, with better DPI or scaling).

 

  • Is there a way to capture a “window area” in Model Space and save it as a high-resolution image?
  • Should I use the plotting API for this, or is there another recommended method?

Any sample code or guidance would be greatly appreciated.

Thanks!

0 Likes
Accepted solutions (1)
228 Views
4 Replies
Replies (4)
Message 2 of 5

fieldguy
Advisor
Advisor
Accepted solution

Have you seen this article?  https://www.keanw.com/2007/10/plotting-a-wind.html 

Message 3 of 5

ActivistInvestor
Mentor
Mentor

Getting a reasonable resolution requires plotting the desired area (using the Plot/Window option). 

 

You can automate that as well, as per the article referenced by @fieldguy.

Message 4 of 5

mdolanVQYAA
Enthusiast
Enthusiast

I had a bit of an issue getting this to work with anything other than the DWF (DWF6 ePlot.pc3) exporter Kean was using in the blog.  This is because you can easily change PlotDeviceName to something like PublishToWeb PNG.pc3, but the mediaName was a bit harder to figure out. This is because the display name in the plot dialog is not the same as the media name. Below is a little code to list out the mediaNames available to use in the file for the PlotDeviceName.

 

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            PlotSettings ps = new PlotSettings(true);
            PlotSettingsValidator psv = PlotSettingsValidator.Current;

            // Set the device first
            psv.SetPlotConfigurationName(ps, "PublishToWeb PNG.pc3", null);
            psv.RefreshLists(ps);

            // Get the list of valid media names
            StringCollection mediaNames = psv.GetCanonicalMediaNameList(ps);

            foreach (string name in mediaNames)
            {
                ed.WriteMessage($"\nAvailable media: {name}");
            }

 

0 Likes
Message 5 of 5

norman.yuan
Mentor
Mentor

The media names you see in the Plot dialog is "LocaleMediaName".

 

You can call PlotSettingsValidator.GetLocaleMediaName(PlotSettings settings, string canonicalMediaName):

 

            // Get the list of valid media names
            StringCollection mediaNames = psv.GetCanonicalMediaNameList(ps);
            string targetParper=null;
            string targetCononicalName =null;
            foreach (string name in mediaNames)
            {
                ed.WriteMessage($"\nAvailable media: {name}");
                targetPaper = psv.GetLocaleMediaName(ps, name);
                if (targetPaper.Equals("MyTargetPaperName")
                {
                   targetCononicalName = name;
                   break;
                }
            }
            // Now you found the cononical media name for later code, based 
            // on the expected user-friendly paper name
            ... ...

 

HTH

Norman Yuan

Drive CAD With Code

EESignature