• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

creare screenshot di autocad con autocad stesso in c#

PlannerRoad

Guest
su through the interface c# code is available for the compilation of a utility that allows you to simultaneously create two screeshots via autocad: one of its window and the other of its work area.

the code, reported qui, is the following:
PHP:
   using acapp = autodesk.autocad.applicationservices;
    using autodesk.autocad.runtime;
    using system.drawing.imaging;
    using system.drawing;
     
    namespace screenshottest
    {
      public class commands
      {
        [CommandMethod("CSS")]
        static public void capturescreenshot()
        {
          screenshottofile(
            acapp.application.mainwindow,
            "c:\\main-window.png",
            0, 0, 0, 0
          );
          screenshottofile(
            acapp.application.documentmanager.mdiactivedocument.window,
            "c:\\doc-window.png",
            30, 26, 10, 10
          );
        }
     
        private static void screenshottofile(
          autodesk.autocad.windows.window wd,
          string filename,
          int top, int bottom, int left, int right
        )
        {
          point pt = wd.location;
          size sz = wd.size;
     
          pt.x += left;
          pt.y += top;
          sz.height -= top + bottom;
          sz.width -= left + right;
     
          // set the bitmap object to the size of the screen
     
          bitmap bmp =
            new bitmap(
              sz.width,
              sz.height,
              pixelformat.format32bppargb
            );
          using (bmp)
          {
            // create a graphics object from the bitmap
     
            using (graphics gfx = graphics.fromimage(bmp))
            {
              // take a screenshot of our window
     
              gfx.copyfromscreen(
                pt.x, pt.y, 0,0, sz,
                copypixeloperation.sourcecopy
              );
     
              // save the screenshot to the specified location
     
              bmp.save(filename, imageformat.png);
            }
          }
        }
      }
    }
in the code in red are the command of the utility that is css and the location and format of the image used as a screenshot save directory, i.e.c:\\main-window.png e c:\\doc-window.pngthe first related to the autocad window, the second related to its work area.
These 3 parameters (command and routes) can be changed at will.
how to fill out the code: in this debate visual c#: fill out the code for autocad I explained the procedure and indicated the software for compiling c#.

in this case, beyond ai due file acdbmgd.dll eacmgd.dll already mentioned in the discussion indicated, for this utility other references must be added.how and which other references add: always in the menu "project" -> option "Add reference" -> tab ".net" this time, add as reference system.drawing and in the case of autocad 2010 probably also presentation.core.
even if not mentioned in the article, for the operation of the code I had to add also the reference system.windows.forms, without which the utility during the compilation indicated an error.

for the rest of the compilation and loading of the utility in autocad continue to follow the procedure reported in the other discussion.

After uploading the compiled utility with the netload command giving the css command (or other command you edited) you will have the automatic creation of the two screenshots in the indicated directory.
 
Last edited:
I attach the file, which I generated from that code above.
 

Attachments

Last edited:
screenshotthe code of utility css, reported above, was completely modified by the author (kean walmsley of through the interface) and a new utility for creating autocad screenshots, much more complete, which became part of the monthly autodesk labs utilities.
the new utility, from the name screenshot, now allows many more options, such as the ability to directly send the screenshot to the printer, or to have all the objects, even if colored, black or gray tone.
find the articles of kean walmsley, with the various updates that happened, here:
http://through-the-interface.typepa...screenshot-novembers-plugin-of-the-month.html
http://through-the-interface.typepa...screenshot-novembers-plugin-of-the-month.html
http://through-the-interface.typepa...novembers-plugin-of-the-month-screenshot.html
http://through-the-interface.typepa...ated-version-of-screenshot-now-available.htmlthe utility being as the previous in c#, it loads with the command netload, after ché autocad the "will register".
the command of the utility is screenshot, while the command of its removal is removess.
read the readme file contained in the compressed file, where the sources are also contained.

you can download here:
http://labs.autodesk.com/utilities/screenshot/
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top