8 Replies Latest reply on Jan 31, 2012 9:25 AM by Head1

    How to place the cursor to a specific location - with Automation?

    Head1

      Hello everybody,

       

        I am looking for a line of code that places the cursor to a specified x,y.

        I couldn't find anything about this sbject in  automation manuals. ( or searched in wrong places..)

       

        Thanks for any help.

       

         head1

      ---------------------------------------------------------------------------

       

        • 1. Re: How to place the cursor to a specific location - with Automation?
          peter.kurlak

          I doubt this is possible with Mentor's API, but it's definitely possible with the Windows API.  But, before I go into unneeded detail, what are you trying to accomplish?  If you just want to zoom to a certain point within a document, you can use something like:

           


          '  (minX, minY)

          '        +-----------------+

          '        |                 |

          '        |      (x, y)     |

          '        |                 |

          '        +-----------------+

          '                     (maxX, maxY)

          '

          set pcbDoc = Application.ActiveDocument


          ''' Validate pcbDoc '''


          pcbDoc.ActiveView.SetExtents(x - minX, y - minY, x + maxX, y + maxY, epcbUnitCurrent)

           


          • 2. Re: How to place the cursor to a specific location - with Automation?
            Head1

            Hello Peter,

             

              This is the point. I DO NOT want to zoom.

            What I want is to point to pins, connected together in a single net.

            Zooming, in this case, is a disadvantage.

             

            Best is whenever I click on a pin name , which is dispalyed somewhere  on the

            form of the program ( in Vb6), the cursor should move to that pin. 

             

            So, moving the cursor in a good idea.

             

            There is a nother idea: to move a graphic symbol (like a cross), in a user defined layer.

            But this in  more complicated.

             

                                 Thanks,

                                  Head1.

            • 3. Re: How to place the cursor to a specific location - with Automation?
              peter.kurlak

              Why not make the pin or pins selected and zoom to selected?  If you want to provide additional visual cues, you could look at "Using Motion Graphics".  You can draw whatever you want on a document in real-time without user defined layers.

              • 4. Re: How to place the cursor to a specific location - with Automation?
                Head1

                Hello Peter,

                   Selecting the pin can be a good idea, especially in shadow mode, but zoom - not.

                  Becase, for every zoom I have to make zoom out.

                  What I want, is to show the user the location for every pin in net, without zooming in and out.

                 

                  If I will not find how to move the cursor, then selecting the pin will be good too.

                 

                   Thanks,

                 

                     Head1.

                ---------------------------------------------------------------------------------------------------

                 

                • 5. Re: How to place the cursor to a specific location - with Automation?
                  peter.kurlak

                  I'm not entirely clear on your requirements, but if you select multiple pins, the zoom function will only zoom in to the point where all selected objects can be seen (so it might not zoom much at all).

                  • 6. Re: How to place the cursor to a specific location - with Automation?
                    Head1

                    Hello Peter,

                     

                      I plan to select only one pin.

                      A listbox will contain all pins connection in a single pin.

                      Whenever the user clicks a pin name (Like U24-8), this pin will be selected, without zoom.

                      Or, the original plan: the cursor will move to that pin.

                     

                      I hope I am clear now.

                     

                       Many thanks,

                     

                        Head1.

                    ----------------------------------------------------------------------------------------

                    • 7. Re: How to place the cursor to a specific location - with Automation?
                      Patrick.Cashman

                      You don't need to move the cursor, but you can if you really want to.  I'd start with something like this:

                       

                              comp = doc.FindComponent

                              pins = comp.Pins

                              For Each pin In pins

                                  If pin.Name = "??" Then

                                      pin.Selected = True

                                      pin.Highlighted = true

                                  End If

                              Next

                       

                      You'd have to parse the J24-8 for the refdes and the pin number to get the right component and the pin number.  I don't remember at the moment if pin.name is the correct item to use, but it's pin.[something].  You'll have to experiment to see.

                       

                      If you want to move the cursor, it's much more complicated.  First you need to access the mouse_event functionality in user32.dll.  Then you do something like this:

                       

                      1. Put the cursor somewhere on the screen. (don't touch the mouse here or you're lost)

                      2. Gt the Expedition cursor position, and Windows mouse position.

                      3. Move to some other location programatically.  (guess an amount to move)

                      4. Get the Exp. and Windows cursor/mouse positions again.

                      5. Compute the ratio of Exp. distance to Windows window coordinate distance.

                      6. Using the FindComponent / get pins method above, find the pin and get it's location in the Expedition window

                      7. Based on where you are in the Windows window, compute how far and where to move, then do it.

                       

                      The commands are:

                       

                      Dim view As MGCPCB.View

                      SetCursorPos(100, 100) 'this is the windows command to move the mouse

                      '(x and y are first found by getting the location of something, like a pin in your case)

                       

                      x1 = int(view.MousePositionX) 'this is the Expedition command to get the position of the cursor in the expedition coordinate system     

                      y1 = int(view.MousePositionY)     

                      SetCursorPos(300, 300) 'move the mouse to some other place     

                      x2 = int(view.MousePositionX) 'get a new set of Exp coordinates     

                      y2 = int(view.MousePositionY)    

                      xr = 200/(x2 - x1) 'compute the ratio of windows position to Expedition position  (200 = 300 - 100, from the two SetCursor commands - it's how far you moved the mouse in the windows environment)

                      yr = 200/(y2 - y1)

                      SetCursorPos(100 + (x - x1)*xr, 100 - (y - y1)*xr) 'move to the desired location, basically the difference of where you are compared to where you want to be, times the ratio of the two coordinate systems.

                       

                      You'll also need this whole pile of goo to get the mouse_event stuff to work and get the cursor position: (it will all go at the top of your class, right after the class declaration. )

                       

                       

                          Public Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, _

                              ByVal cButtons As Int32, ByVal dwExtraInfo As Int32)

                       

                          Public Declare Function SetCursorPos Lib "user32.dll" ( ByVal X As Int32, ByVal Y As Int32) As Boolean

                          Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long

                       

                           'the following is for emulating mouse actions

                          Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, _

                              ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

                          Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down

                          Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up

                          Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down

                          Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up

                          Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down

                          Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up

                       

                      You see it's very complicated.  There is a whole layer of stuff going on between your mouse cursor and whatever is happening in the software you are using the mouse with.  This method uses brute force to acquire the data for where the mouse is (from both environments) and then tries to move it accordingly.  It's clumsy.  Perhaps there's a better way using the Mentor tools, but I haven't stumbled across it yet.

                       

                      Much easier to just highlight/select the pin as I indicated above.

                      • 8. Re: How to place the cursor to a specific location - with Automation?
                        Head1

                        Hello Patrick,

                           Thanks for your answer.

                           How to highlight a pin I already know.

                           About separating ref_des from pin number ( like U16  -  9 ) - you are right.

                          I believe you are right about the procedure you have described to move the cursor.

                          It is to complicated and not so important.

                          So I give up with it.  Highlighting a pin is good enough.

                         

                          Anyway, thanks for you answer.

                         

                                                   Head1.

                        ------------------------------------------------------------