How can I implement the PNGOUT command in AutoCAD.Net? Is there a standard or existant solution?
(All objects are selected)
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 -
The screenshot methods introduced in
and
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
Hi,
then plot-api might be a way to go.
- alfred -
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 ?
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); } }