.NET

Reply
F32
Member
F32
Posts: 4
Registered: ‎10-10-2013
Message 1 of 6 (560 Views)

Implement the PNGOUT command in AutoCAD.Net

560 Views, 5 Replies
12-12-2013 01:22 AM

How can I implement the PNGOUT command in AutoCAD.Net? Is there a standard or existant solution?

(All objects are selected)

*Expert Elite*
Alfred.NESWADBA
Posts: 9,403
Registered: ‎06-29-2007
Message 2 of 6 (548 Views)

Re: Implement the PNGOUT command in AutoCAD.Net

12-12-2013 03:46 AM in reply to: F32

Hi,

 

it's nothing more than a screenshot, isn't it?

 

To get it in a higher quality, with some more options you can also use the plot-api and define a PC3 that is designed for PNG-creation.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
F32
Member
F32
Posts: 4
Registered: ‎10-10-2013
Message 3 of 6 (534 Views)

Re: Implement the PNGOUT command in AutoCAD.Net

12-12-2013 06:20 AM in reply to: Alfred.NESWADBA

The screenshot methods introduced in

 

http://through-the-interface.typepad.com/through_the_interface/2009/09/taking-screenshots-of-autocad...

 

and

 

http://through-the-interface.typepad.com/through_the_interface/2009/09/taking-a-screenshot-of-a-user...

 

does not work for me, as I don't want the axes to be painted.

 

I also tried the offscreen rendering method introduced in

 

http://through-the-interface.typepad.com/through_the_interface/2007/04/taking_a_snapsh.html

 

however, the images created have white background, and I'm quite sure what the corrent VisualStyleType should be if I just want exactly the same images in 2D model view

*Expert Elite*
Alfred.NESWADBA
Posts: 9,403
Registered: ‎06-29-2007
Message 4 of 6 (521 Views)

Re: Implement the PNGOUT command in AutoCAD.Net

12-12-2013 09:26 AM in reply to: F32

Hi,

 

then plot-api might be a way to go.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
F32
Member
F32
Posts: 4
Registered: ‎10-10-2013
Message 5 of 6 (496 Views)

Re: Implement the PNGOUT command in AutoCAD.Net

12-12-2013 10:43 PM in reply to: F32

Thanks for your reply. Finally I've almost got it work correctly, and here's the code:

 

// Hide axes
Application.SetSystemVariable("UCSICON", 0);

// Get viewport number
int vpn = Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

// Get view (create if none)
View view = doc.GraphicsManager.GetGsView(vpn, true);

// Take a snapshot and save image
Bitmap bmp = view.GetSnapshot(view.Viewport);
bmp.Save("C:\\a.png");

However there are still questions:

 

  • Why is there no existant view and I have to pass true for the second parameter in GetGsView() ?
  • After executing the code above, the original white X-Y axes becomes colorful X-Y-Z axes, what's happened ?
Valued Contributor
FRFR1426
Posts: 92
Registered: ‎04-05-2012
Message 6 of 6 (485 Views)

Re: Implement the PNGOUT command in AutoCAD.Net

12-13-2013 01:47 AM in reply to: F32
  • Why is there no existant view and I have to pass true for the second parameter in GetGsView() ?
  • After executing the code above, the original white X-Y axes becomes colorful X-Y-Z axes, what's happened ?

It is because GraphicsManager works with AGS (AutoCAD Graphic System, wireframe 3D), not with WHIP (Wireframe 2D).

 

You are in wireframe 2D, so there is no AGS View and AutoCAD must create one. If you switch in wireframe 3D or another visual style, AutoCAD will use the existing AGS view.

 

If you want full control on your screenshot, you have to create a view and then use an off screen device to draw on it:

 

var cvport = (short)Application.GetSystemVariable("CVPORT");
Image img;
using (var view = new View())
{
    doc.GraphicsManager.SetViewFromViewport(view, cvport);
    view.SetView(view.Position, view.Target, view.UpVector, width, height);

    using (Device dev = doc.GraphicsManager.CreateAutoCADOffScreenDevice())
    {
        dev.OnSize(new Size(width, height);

        // Set the render type and the background color
        dev.DeviceRenderType = RendererType.Default;
        dev.BackgroundColor = Color.White;

        // Add the view to the device and update it
        dev.Add(view);
        dev.Update();
        
        using (Model model = doc.GraphicsManager.CreateAutoCADModel())
        {
            // Create entities here, you can clone your existing entities
// Set an explicit ColorIndex
var line = new Line(..);
line.ColorIndex = 7; view.Add(line, model); } view.ZoomExtents(..,..) img = view.GetSnapshot(new Rectangle(0, 0, width, height); } }

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!