.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Implement the PNGOUT command in AutoCAD.Net

5 REPLIES 5
Reply
Message 1 of 6
F32
Explorer
1961 Views, 5 Replies

Implement the PNGOUT command in AutoCAD.Net

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

(All objects are selected)

5 REPLIES 5
Message 2 of 6
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 6
F32
Explorer
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

Message 4 of 6
Alfred.NESWADBA
in reply to: F32

Hi,

 

then plot-api might be a way to go.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 6
F32
Explorer
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 ?
Message 6 of 6
FRFR1426
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); } }

 

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost