10 Replies Latest reply on Feb 2, 2018 2:53 PM by Patrick.Cashman

    How to take a snapshot for current screen in PCB Layout by automation?

    xinyou.liu

      How to take a snapshot for current screen in PCB Layout by automation?

      In PCB layout, I want to take a snapshot for current screen (only the workspace, excluding toolbar and file menu), just like below picture.

      Do anyone know how to do it ? Thanks.

       

      kendall_hiles Do you have any ideas? Thanks.

       

      Xici

        • 1. Re: How to take a snapshot for current screen in PCB Layout by automation?
          bbpcbdesign

          Hi Xici,

          follow this link,

          https://communities.mentor.com/docs/DOC-2934

          It is an old Mentor script. It was developed for EE7.9.x version. I think it does more than what you need, but could be useful.

          Bortolo

          • 2. Re: How to take a snapshot for current screen in PCB Layout by automation?
            xinyou.liu

            Hi Bortolo,

             

            Thanks for your reply. But that is not I want.

            I want to save a picture printing what we see.

             

            Xici

            • 3. Re: How to take a snapshot for current screen in PCB Layout by automation?
              jeff@viavi

              Do you want it to automatically save to a file or just to the clipboard?  If it is just to the clipboard, do an Alt-EB (Edit>Copy Bitmap to Clipboard) and then draw a box around what you want to include.  I'm not sure if that function is opened up to automation or not

              • 4. Re: How to take a snapshot for current screen in PCB Layout by automation?
                peter_festesen

                Since what you are after, is more of a Windows (assuming this is for Windows, not Linux), I suggest running a search like

                "take screenshot windows by vbs script" in you preferred search engine. With Chrome, one of the hits is this one (Application is Word, but perhaps it can be modified for xPCB?)

                 

                Print Screen - How to perform a Print Screen and save it in one file in silent mode?

                • 5. Re: How to take a snapshot for current screen in PCB Layout by automation?
                  bbpcbdesign

                  Hi Xici,

                  With automation you could recover coordinates of desired area and pass them to a screen capture tool.
                  Try with some freeware tools using commanline parameters.
                  Two example:

                       Irfanview

                  IrfanView.png

                       Boxcutter

                  Boxcutter.png

                  Many other examples from web.
                  Irfanview is my favorite image viewer.

                  Bortolo

                  • 6. Re: How to take a snapshot for current screen in PCB Layout by automation?
                    kendall_hiles

                    I did this for the original version of HyperLynxDRC, I called my routine snappy.

                     

                    This example is in AATK>HyperLynxDRC\Working\Violations

                     

                    Function snappy(Row, Path)
                        ' Create the required objects
                        Set objSnagit = CreateObject("SNAGIT.ImageCapture.1")
                        Set wshShell = CreateObject("WScript.Shell")

                        ' Set input options
                        objSnagit.Input = siiDesktop
                        objSnagit.IncludeCursor = True

                        ' Set output options
                        objSnagit.Output = sioFile
                        objSnagit.OutputImageFile.FileType = siftPNG
                        objSnagit.OutputImageFile.ColorDepth = sicd32Bit
                        objSnagit.OutputImageFile.FileNamingMethod = sofnmFixed
                        objSnagit.OutputImageFile.FileName = Row '"snagtest"
                        objSnagit.OutputImageFile.Directory = Path '"C:\"

                        ' Capture
                        objSnagit.Capture
                        Call add_pic(Row, Path)

                        ' Launch the captured image in the default viewer
                        'wshShell.Run "C:\snagtest.png", 0, False

                        ' Release the objects
                        Set objSnagit = Nothing
                        Set wshShell = Nothing
                    End Function

                     

                    -kendall

                    • 7. Re: How to take a snapshot for current screen in PCB Layout by automation?
                      bbpcbdesign

                      Hi Kendal,

                      AATK is always a great resource.

                      Your solution is great but I don't know if all users have Snagit  ( shareware tool ).

                      I have it and I use it daily, but I never thought of using it this way.

                      However, for me is the best screen capture tool.

                       

                      Bortolo

                      • 8. Re: How to take a snapshot for current screen in PCB Layout by automation?
                        Patrick.Cashman

                        This can be done with Windows API calls. It's a bit of a complicated process, but it can be done. Here's what you would do, in simple terms:

                         

                        1. Use the AutomationElement functions to find the window of interest, by name. Start with the desktop, then find the Xpedition window, then the sub-windows within the Xpedition window.

                         

                        2. Get the handle of the object of interest, in this case a sub-window inside the Xpedition window.

                         

                        3. Use the handle and the Graphics tools in vb.net to get a bitmap image of the window you want.

                         

                        Here is an example of using AutomationElements to find a particular field (the Grow/Shrink text box) in the Properties dialog in Fablink:

                         

                        (note you need the

                        Imports system.Windows.Automation

                        statement at the top of whatever class or module you put this in)

                         

                        Public Sub set_panel_border_line_thickness_b()

                        Dim dt, exp, props, gs_box As AutomationElement

                        dim chln as AutomationElementCollection

                        dim ctrl_type as ControlType

                        Dim name As String

                        Dim n As Integer

                        Dim gui As MGCPCB.Gui

                        Dim pb As MGCPCB.PanelBorder

                         

                        pb = fabdoc.PanelBorder

                         

                        While pb.Selected = False

                        pb.Selected = True

                        End While

                         

                         

                        gui = fabapp.Gui

                        gui.ActiveMode = 2

                         

                        'get the automation reference to the windows desktop

                        dt = AutomationElement.RootElement

                         

                        'find the Expedition PCB window

                        ctrl_type = ControlType.Window

                        chln = dt.FindAll(treescope.Children, New PropertyCondition(AutomationElement.ControlTypeProperty, ctrl_type ))

                         

                        For Each exp In chln

                        name = exp.Current.Name.ToString

                        If instr(name, "FabLink") > 0 Then

                        debug.Print("found the Fablink window")

                        exit for

                        End If

                        Next

                         

                        If exp Is Nothing Then

                        Debug.Print("Fablink window lost. Exiting.")

                        exit sub

                        End If

                         

                        exp.SetFocus

                        n = 0

                        try_to_find_props:

                        gui.ProcessCommand("Edit->Properties")

                        debug.Print("trying to find the properties window")

                        props = exp.FindFirst(treescope.Children, new PropertyCondition(AutomationElement.NameProperty, "Properties"))

                         

                        'you may want to put a check here to make sure you actually found the Properties window, such as

                        'if props is nothing then . . .

                         

                        props.SetFocus

                         

                         

                        While pb.Selected = False

                        pb.Selected = True

                        End While

                         

                         

                                'find the Line Width Combo Box

                                ctrl_type = ControlType.Edit

                         

                         

                                chln = props.FindAll(treescope.Children, New PropertyCondition(AutomationElement.ControlTypeProperty, ctrl_type ))

                         

                        For Each gs_box In chln

                        name = gs_box.Current.Name.ToString

                        Debug.Print("name is " & name.ToString)

                                    If InStr(name, "Shrink") > 0 Then

                                        Debug.Print("and now we have found the Grow/Shrink box")

                                        Exit For

                                    End If

                                Next

                         

                        Debug.Print("Final gs_box name is " & gs_box.Current.Name.ToString)

                         

                        If gs_box Is Nothing Then

                        debug.Print("We are unable to locate the Grow/Shrink box in the Properties window")

                        exit sub

                        End If

                        gs_box.SetFocus

                         

                        . . .

                         

                        End Sub

                         

                        You can change this up a bit so that first you display the names of each of the child objects in every object you find, so that you can by process of elimination find the name of the window you want.  You can also get the Visual UI Automation Verify tool from the Windows SDK to be able to see the names of every windows object.  This can help you narrow down your search.

                         

                        Of course you will need to change this to find the window you want.  But all the pieces are in there.  You will just change the names and the ctrl_type as needed to find a window, panel, or other object you want.

                         

                        Once you have the window object, you get its handle. See in formation on how to do this here.

                        Then you get the bitmap using the graphics.fromHwnd method, as shown here. Then you can save it as a file, put it on the Windows clipboard, or paste it  into some other program's window, a document, or whatever.

                         

                        Yes, it's a long way around.  Yes, it's complicated.  It will take some time to get it right.  The good thing is that it works.  And if you learn these methods well, there is a lot you can do with the WindowsAutomation functions.  Basically you can do anything with any object in any window. Think about that as the return on the time investment you will make for this window image capture exercise. Adding AutomationElements and the .net Graphics functionality to your toolbox is powerful.

                         

                        Best of luck with it.

                        • 9. Re: How to take a snapshot for current screen in PCB Layout by automation?
                          bbpcbdesign

                          Hi Patrick,

                          very interesting, but if I understand well, with this method you will capture a full window, or any other element inside it.

                          But the request was...

                               I want to take a snapshot for current screen (only the workspace, excluding toolbar and file menu)

                          He is asking a window region. How do you manage this?

                          -Bortolo

                          • 10. Re: How to take a snapshot for current screen in PCB Layout by automation?
                            Patrick.Cashman

                            The workspace is actually a window all its own.  It's a child object of the application window, just like all the panels, buttons, text boxes, dialog boxes (other windows )  and so on that make up the main application window. Each of these items can be found by name and then queried or manipulated as if a user were operating them, all by way of the automationelements functionality.